Tag: itextsharp

iTextSharp v5 GetTextFromPage()抛出IndexOutOfRangeException

尝试使用以下代码提取pdf的文本内容: PdfReader reader = new PdfReader(path); string strText = string.Empty; for (int page = 1; page <= reader.NumberOfPages; page++) { string s = PdfTextExtractor.GetTextFromPage(reader, page); strText += " " + s; } reader.Close(); NumberOfPages返回257,但在第227页,GetTextFromPage()抛出IndexOutOfRangeException。 任何帮助表示赞赏。 hofnarwillie

使用iTextSharp从pdf中读取javascript

我有一个脚本,在加载pdf文件后运行,并填充pdf中的一些表单字段。 我假设它是在场景后面运行的某种javascript。 在javascript代码中存储了一些我需要检索的值。 我使用iTextSharp来处理pdf文件。 是否可以读取javascript代码或值,以便我可以用我的c#代码以某种方式使用它们?

将Pdf文件保存在特定文件夹中而不是下载

我正在做html到pdf文件。 它立即下载。 我不想立即下载。 我希望转换后将文件保存在我的项目文件夹中。 我的C#代码 string html =”some contents”; Response.ContentType = “application/pdf”; Response.AddHeader(“content-disposition”, “attachment;filename=WelcomeLetter.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); StringReader sr = new StringReader(table); Document ResultPDF = new Document(iTextSharp.text.PageSize.A4, 25, 10, 20, 30); PdfPTable Headtable = new PdfPTable(7); Headtable.TotalWidth = 525f; Headtable.LockedWidth = true; Headtable.HeaderRows = 5; Headtable.FooterRows = […]

如何添加粘滞便笺,在光标处插入文本,..使用带有C#的iTextSharp在现有PDF文件中添加注释?

我想使用带有C#的iTextSharp在现有PDF文件中添加注释注释。 请提供示例代码以在现有PDF文件中添加注释。 这里是我的注释的PS脚本: [/Contents (My Text contents) /Rect [100 600 150 550] /SrcPg 1 /Title (My Title text) /Color [0 0 1] /Subtype /Caret /ANN pdfmark

在*当前位置*绘制一个矩形,然后获取其位置坐标

所以,我正在使用iTextSharp将一些文本写入PDF文件。 在PDF文档中添加了几个段落和短语之后,我想: 在具有填充颜色的矩形(例如红色)上绘制下一段文本。 我可以根据我要在其上面写的文本的文本度量来计算矩形必须具有的所需宽度和高度。 但是,我如何告诉Rectangle API顶部和左侧坐标是什么,如何必须绘制?

从资源加载basefont

我正在尝试使用ITextSharp并加载插入项目中的字体文件作为资源。 我尝试了不同的解决方案,但它们似乎都不起作用,这里是我所做的一个示例: 这个无法加载资源 private static BaseFont _bfArial; public static BaseFont BfArial { get { if (_bfArial == null) _bfArial = BaseFont.CreateFont(@”Resources\Images\arialuni.ttf”, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); return _bfArial; } } 这个给了我一个错误:“’Identity-H’不是受支持的编码名称。” private static BaseFont _bfCourier; public static BaseFont BfCourier { get { if (_bfCourier == null) _bfCourier = BaseFont.CreateFont(“Courier”, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, FontsResources.cour, null); return _bfCourier; } } […]

如何将表添加为标题?

我正在使用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 […]

在Itext中更改背景图像以水印或改变不透明度c#ASP.net

我想让iText中的背景图像透明化 这是我的图像代码: string root = Server.MapPath(“~”); string parent = Path.GetDirectoryName(root); string grandParent = Path.GetDirectoryName(parent); string imageFilePath = parent + “/Images/logo.png”; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath); jpg.ScaleToFit(1700, 800); jpg.Alignment = iTextSharp.text.Image.UNDERLYING; jpg.SetAbsolutePosition(100, 250); jpg.ScaleAbsoluteHeight(500); jpg.ScaleAbsoluteWidth(500); 任何的想法?

使用itextsharp在PDF中保持相似的图像大小

我正在使用itextsharp将我的图片带到pdf文件。 我用chunk。 然而,当我使用chunk new line时,尽管我使用了相同的scaletofit,但我的图像会改变它的大小。 protected void btnPDF_Click(object sender, EventArgs e) { var doc1 = new Document(); var filename = “MyTestPDF” + DateTime.Now.ToString(“yyyyMMddHHmmssfff”) + “.pdf”; var output = new FileStream(Path.Combine(“C:\\Users\\apr13mpsip\\Downloads”, filename), FileMode.Create); iTextSharp.text.pdf.PdfWriter.GetInstance(doc1, output); doc1.Open(); PdfPTable table = new PdfPTable(1); table.TotalWidth = 585f; table.LockedWidth = true; PdfPTable table2 = new PdfPTable(1); table2.TotalWidth = 585f; table2.LockedWidth […]

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();