Tag: itextsharp

将Panel保存为PDF不起作用也不会出错

我正在尝试使用ITextSharp将面板保存为pdf。 当我设置断点并进行调试时,代码会停止在这行代码上,但是它不会出现错误而只是停止。 if (IsPostBack) { Response.ContentType = “application/pdf”; Response.AddHeader(“content-disposition”, “attachment;filename=Quote.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); **Panel1.RenderControl(hw);** StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); } 在面板中我有文本框,标签和GridView。

PdfPTable作为iTextSharp中的标题

我需要一个包含大约12个单元格的表格作为标题显示。 以下代码无法执行此操作。 我知道table2没有12个单元格。 在第二页上,仅显示“测试”。 我错过了什么? 提前致谢! Document document = new Document(); try { PdfWriter.GetInstance(document, new FileStream(“TableTest.pdf”, FileMode.Create)); document.Open(); PdfPTable table = new PdfPTable(1); table.WidthPercentage = 100; PdfPTable table2 = new PdfPTable(2); //logo PdfPCell cell2 = new PdfPCell(Image.GetInstance(@”C:\path\to\file.gif”)); cell2.Colspan = 2; table2.AddCell(cell2); //title cell2 = new PdfPCell(new Phrase(“\nTITLE TEXT”, new Font(Font.HELVETICA, 16, Font.BOLD | Font.UNDERLINE))); cell2.HorizontalAlignment […]

需要帮助使用itextsharp从HTML创建PDF

我正在尝试从HTML页面中创建PDF。 我正在使用的CMS是EPiServer。 到目前为止这是我的代码: protected void Button1_Click(object sender, EventArgs e) { naaflib.pdfDocument(CurrentPage); } public static void pdfDocument(PageData pd) { //Extract data from Page (pd). string intro = pd[“MainIntro”].ToString(); // Attribute string mainBody = pd[“MainBody”].ToString(); // Attribute // makae ready HttpContext HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = “application/pdf”; // Create PDF document Document pdfDocument = new Document(PageSize.A4, 80, 50, 30, […]

iTextSharp重复使用Acrofield中嵌入的字体

“iText In Action”中有一些提示,包括设置字体,以及“FontFactory.RegisterDirectories”方法(正如书中所说的那样……一个昂贵的调用)。 但是,就我而言,我想用于新字段的字体已经嵌入到文档中(在现有的Acrofield中)。 不能保证在用户的机器上(或在Web服务器上)存在相同的字体….有没有办法可以注册已经嵌入的字体,以便我可以将它重新用于其他对象? 在下面的代码中,Acrofield“TheFieldIWantTheFontFrom”具有我想要为名为“my_new_field”的字段重用的字体。 任何帮助将不胜感激! using (MemoryStream output = new MemoryStream()) { // Use iTextSharp PDF Reader, to get the fields and send to the //Stamper to set the fields in the document PdfReader pdfReader = new PdfReader(@”C:\MadScience\MSE_030414.pdf”); // Initialize Stamper (ms is a MemoryStream object) PdfStamper pdfStamper = new PdfStamper(pdfReader, output); // […]

从pdf文件中读取超链接

我正在尝试阅读pdf文件并从此文件中获取所有超链接。 我正在使用iTextSharp用于C#.net。 PdfReader reader = new PdfReader(“test.pdf”); List list = reader.GetLinks(36); 这个方法“GetLinks”返回一个包含大量链接信息的列表,但是这个方法没有返回我想要的值,超链接字符串我确切知道第36页有超链接

iTextSharp替换现有PDF中的文本而不会失去形成

我一直在互联网上搜索2周,并为我的问题找到了一些有趣的解决方案,但似乎没有什么能给我答案。 我的目标是做下面的事情: 我想在静态PDF文件中找到一个文本,并将该文本替换为另一个文本。 我想保留内容的设计。 这真的很难吗? 我发现了一种方法,但我丢失了整个信息: using (PdfReader reader = new PdfReader(path)) { StringBuilder text = new StringBuilder(); for (int i = 1; i <= reader.NumberOfPages; i++) { text.Append(PdfTextExtractor.GetTextFromPage(reader, i)); text.Replace(txt_SuchenNach.Text, txt_ErsetzenMit.Text); } return text.ToString(); } 我的第二次尝试更好,但需要我可以更改内部文本的字段: string fileNameExisting =path; string fileNameNew = @”C:\TEST.pdf”; using (FileStream existingFileStream = new FileStream(fileNameExisting, FileMode.Open)) using (FileStream newFileStream = […]

合并内存流以在c#中创建http PDF响应

我试图将2个水晶报告合并为单个pdf文件,我正在使用Itextsharp v5.1.1。 但它说文件无法打开。 它可能已损坏。 没有构建错误。 但pdf格式不正确,无法打开。 这是我选择完成此任务的顺序。 以pdf格式将Crystal报表导出到MemoryStream1 将第二个报告导出到MemoryStream2中。 合并内存流 将Streams发送到Http输出响应为PDF。 以下是订单中每个步骤的代码。 /// Get the Dataset from Stored Procedure for the CSSource Report dsCS = CSData.GetUSSourceXML(ds_input); /// Create the Report of type CSsource rptCS = ReportFactory.GetReport(typeof(CSsource)); rptCS .SetDataSource(dsCS); /// Set the Parameters to the CS report rptCS .ParameterFields[“Parameterid”].CurrentValues.Clear(); rptCS .SetParameterValue(“Parameterid”, PID); //// Serialize the Object […]

iTextSharp – 是否可以为同一个单元格和行设置不同的字体颜色?

我使用iTextSharp.dll与以下代码: var Title = “This is title”; var Description = “This is description”; Innertable.AddCell(new PdfPCell(new Phrase(string.Format(“{0} {1}”, Title, Description.Trim()), listTextFont)) { BackgroundColor = new BaseColor(233, 244, 249), BorderWidth = 0, PaddingTop = 4, PaddingLeft = -240, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_LEFT }); 我们可以为标题和描述设置不同的字体颜色,但只使用单个单元格(即不创建新表格)? 任何有关此事的帮助将不胜感激。

iTextSharp正在生成一个损坏的PDF

下面的代码片段返回一个损坏的PDF文档,但是如果我返回mergedDocument,它总是返回一个有效的PDF。 mergedDocument基于我使用Word创建的PDF文件,而完成的文档完全以编程方式生成。 代码“有效”,因为它不会引发exception。 为什么iTextSharp会创建损坏的PDF? byte[] completedDocument = null; using (MemoryStream streamCompleted = new MemoryStream()) { using (Document document = new Document()) { PdfCopy copy = new PdfCopy(document, streamCompleted); document.Open(); copy.Open(); foreach (var item in eventItems) { byte[] mergedDocument = null; PdfReader reader = new PdfReader(pdfTemplates[item.DataTokens[NotifyTokenType.OrganisationID]]); using (MemoryStream streamTemplate = new MemoryStream()) { using (PdfStamper stamper […]

使用iTextSharp获取指定区域中包含的文本

是否有可能使用iTextSharp获取pdf文档指定区域中包含的所有文本? 谢谢。