Tag: itext

下载-ItextSharp时生成空白pdf

我正在尝试生成一个简单的PDF文档,可以从asp.net网页下载。 此pdf文档具有带标题文本的段落,其余内容已通过预填充的DataTable实例填充。 我试图在这里打印的所有列都是文本,除了一列是图像(缩略图)。 我可以毫无例外地执行附加的代码,生成pdf文档并将其下载到客户端浏览器。 问题: 用户可以在浏览器中查看下载的pdf(仅通过IE和Chrome测试),并可以查看pdf中的所有内容,包括缩略图。 但是,当将生成的pdf保存到本地驱动器并打开它时,所有pdf页面都是空白的。 一直在打破我的头,任何提示都会非常有帮助。 在服务器端事件上生成PDF的代码 private void Download() { var document = new Document(); try { var dataTable = GetDataTable(parameters); //this line create and fill a DataTable with some values Response.ContentType = “application/pdf”; Response.AddHeader(“content-disposition”,”attachment;filename=sample.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);//get a pdf writer instance document.Open(); //Create table var pdfTable = DocumentManager.CreateTable(dataTable.Columns.Count, […]

使用ITextsharp将Html导出为PDF

我试过下面的代码,我也遇到了错误。 我正在使用最新的DLL。 String strSelectUserListBuilder = @” My First Heading My first paragraph. “; String htmlText = strSelectUserListBuilder.ToString(); List htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null); 我收到了这个错误: 给定的密​​钥不在字典中。

使用iText阅读PDF注释

我试图将PDF注释的内容变为字符串,以便将该信息存储在数据库中以供搜索。 有谁知道如何使用iText / iTextSharp完成此操作?

iTextSharp表格宽度为页面的100%

我正在尝试使用iTextSharp为文档添加表格。 这是一个例子: Document document = new Document(PageSize.LETTER,72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(“C:\\test.pdf”, FileMode.Create)); document.Open(); Table table = new Table ( 2, 1 ); table.Width = document.RightMargin – document.LeftMargin; // Cell placeholder Cell cell = new Cell ( new Paragraph ( “Some Text” ) ); table.AddCell ( cell ); cell = new […]

如何在PDF中查找所有特定文本并在上面插入分页符?

我对PDF有一个棘手的要求 我需要在pdf中搜索特定的字符串 – 属性编号: 每次找到这个,我都需要在上面添加一个分页符 我可以访问IText和Spire.PDF,我首先看IText 我已经从其他post建立了我需要使用PDF压模 下面的逻辑添加了一个可行的新页面 但是,就我而言,我只需要分页而不是空白页 var newFile = @”c:\temp\full.pdf”; var dest = @”c:\temp\dest.pdf”; var reader = new PdfReader(newFile); if (File.Exists(dest)) { File.Delete(dest); } var stamper = new PdfStamper(reader, new FileStream(dest, FileMode.CreateNew)); var total = reader.NumberOfPages + 1; for (var pageNumber = total; pageNumber > 0; pageNumber–) { var pageContent = reader.GetPageContent(pageNumber); […]

如何使用iTextSharp在PDF中显示✔?

我正在尝试使用iTextSharp在PDF中显示“✔”字符。 但是,角色不会显示在创建的PDF上。 请帮帮我。

itextsharp:如何找到矩形的填充颜色

我按照ItextSharp示例获取图形结构,使用代码获取矩形坐标: class VectorGraphicsListener : IExtRenderListener { public void ModifyPath(PathConstructionRenderInfo renderInfo) { if (renderInfo.Operation == PathConstructionRenderInfo.RECT) { float x = renderInfo.SegmentData[0]; float y = renderInfo.SegmentData[1]; float w = renderInfo.SegmentData[2]; float h = renderInfo.SegmentData[3]; … 我尝试了renderInfo.GetFillColor(); 但是没有这样的方法。 我想获得额外的矩形属性: 像矩形填充颜色,(一些类似于DIV样式=“背景:蓝色;边框:黑色;”标签在HTML中)我是如何得到它的?

使用c#中的iTextSharp的pdf阿拉伯语

我想在C#中创建一个包含阿拉伯文本内容的PDF文件。 我正在使用iTextSharp来创建它。 我按照http://geekswithblogs.net/JaydPage/archive/2011/11/02/using-itextsharp-to-correctly-display-hebrew–arabic-text-right.aspx中的说明进行操作。 我想在pdf中插入以下阿拉伯语句子。 تمإبرامهذاالعقدفيههااليوم[●]مالموافق[●]منقبلوبين。 [●]需要用动态英语单词代替。 我尝试使用ARIALUNI.TTF实现这一点[本教程链接建议]。 代码如下。 public void WriteDocument() { //Declare a itextSharp document Document document = new Document(PageSize.A4); //Create our file stream and bind the writer to the document and the stream PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@”D:\Test.Pdf”, FileMode.Create)); //Open the document for writing document.Open(); //Add a new page document.NewPage(); //Reference a […]

如何将表添加为标题?

我正在使用iTextSharp尝试为我生成的PDF添加页眉和页脚,但是,如果我尝试添加宽度为页面100%的页眉,我会遇到一些问题。 所以我做了以下事情: 1)我创建了一个名为PdfHeaderFooter的类,它扩展了iTextSharp PdfPageEventHelper类 2)进入PdfHeaderFooter我已经实现了生成标头的OnStartPage()方法: // write on start of each page public override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); PdfPTable tabHead = new PdfPTable(new float[] { 1F }); PdfPCell cell; //tabHead.TotalWidth = 300F; tabHead.WidthPercentage = 100; cell = new PdfPCell(new Phrase(“Header”)); tabHead.AddCell(cell); tabHead.WriteSelectedRows(0, -1, 150, document.Top, writer.DirectContent); } 如果我使用像tabHead.TotalWidth = 300F那样的东西; insted […]

Document.NewPage()不添加新页面

我正在尝试向pdf文档添加新页面,但由于某种原因,这种情况不会发生。 也许我的另一个问题https://stackoverflow.com/questions/11428878/itextsharp-splitlate-not-working与此有关,因为此问题中的表不会中断并且不会创建新页面。 这是我添加新页面的代码: Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate(),20,20,20,40); string rep1Name; // variable to hold the file name of the first part of the report rep1Name = Guid.NewGuid().ToString() + “.pdf”; FileStream output = new FileStream(System.Web.HttpContext.Current.Server.MapPath(“~/ReportGeneratedFiles/reports/” + rep1Name), FileMode.Create); PdfWriter pdfWriter = PdfWriter.GetInstance(doc, output); doc.Open(); doc.NewPage(); doc.NewPage(); doc.Close();