Tag: itextsharp

“文档未打开”仅在使用iTextSharp的生产中出错

我在iTextSharp中收到“文档未打开”错误,但仅限于生产中。 代码在我的开发机器和分段上运行良好。 我在舞台服务器上的Temp文件夹中设置了相同的权限。 public static byte[] ConvertHtmlToPdf(string html) { html = HtmlPostProcessor.Process(html); byte[] fileData = null; string tempPath = ConfigurationManager.AppSettings[“TempDirectory”]; string tempPDFFile = Path.Combine(tempPath, Guid.NewGuid() + “.pdf”); int num = FontFactory.RegisterDirectory(@”C:\Windows\Fonts”); using (FileStream fs = new FileStream(tempPDFFile, FileMode.Create)) { using (Document document = new Document(PageSize.LETTER, 50, 50, 50, 50)) { document.Open(); PdfWriter.GetInstance(document, fs); using (StringReader […]

如何将iTextSharp.text.Image大小调整为我的代码?

我是iText和iTextSharp ( iText的C#版本)的新手,我有以下问题。 我在我的PDF中插入了一些jpg图表。 这些图表由一些像这样的jpg呈现: 我以这种方式将其插入到PDF的表格中: iTextSharp.text.Image img = null; …………………………………… …………………………………… …………………………………… if (currentVuln.UrgencyRating > 0) { img = ChartHelper.GetPdfChartV2((int)currentVuln.UrgencyRating * 10, _folderImages); vulnerabilityDetailsTable.AddCell(new PdfPCell(img) { Border = PdfPCell.RIGHT_BORDER, BorderColor = new BaseColor(79, 129, 189), BorderWidth = 1, Padding = 5, MinimumHeight = 30, PaddingTop = 10 }); } 这是GetPdfChartV2()方法的一部分,我在其中加载图表immage: public static iTextSharp.text.Image GetPdfChartV2(int […]

itextsharp:拆分页面大小等于文件大小

这是我如何拆分大pdf(144 MB) public int SplitAndSave(string inputPath, string outputPath) { FileInfo file = new FileInfo(inputPath); string name = file.Name.Substring(0, file.Name.LastIndexOf(“.”)); using (PdfReader reader = new PdfReader(inputPath)) { for (int pagenumber = 1; pagenumber <= reader.NumberOfPages; pagenumber++) { string filename = pagenumber.ToString() + ".pdf"; Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileStream(outputPath + […]

如何使用iTextSharp将表格插入PDF文档?

我想在现有的PDF文档中插入一个表格。 我正在关注一个关于将图像插入PDF的post,但是在尝试添加表时我得到一个空引用exception错误。 这是我目前的代码 public static byte[] InsertTable(byte[] pdf, DataTable dt, int pageNum, int x, int y, int columns, int rows, int[] columnWidths, float rowHeight) { using (var inputPDF = new MemoryStream(pdf)) using (var outputPDF = new MemoryStream()) { var reader = new PdfReader(inputPDF); var stamper = new PdfStamper(reader, outputPDF); var pdfContentByte = stamper.GetOverContent(pageNum); Table t […]

更改PDF – 文本重新定位

有没有办法将现有pdf页面内的文本移动/移动 到其他位置 ? 就像在区域x = 100处有一些文本,y = 100,w = 100,h = 100并且我想将其移动到x = 50,y = 200,w = 100,h = 100。 我做了很多研究,似乎iTextSharp无法做到这一点。 PDFSharp声称它可以完成,但我找不到任何例子。 一种方法是制作我想要移动的文本的特定区域的位图,在该区域上绘制白色矩形并在新位置插入位图。 我不想使用这个解决方案,因为我使用超过1K页面的大型pdf文件,其中每个页面都必须被更改。 我发现的是,我需要找到一种方法来改变文本定位操作符(文本矩阵和文本状态参数),这并不是那么简单。 有人有什么想法吗?

用unicode字符填写pdf表单

我试图用c#插入一些unicode charaters(arabic)到PDF格式我使用了iTextSharp库但是当我插入字符并在PDF文件中保存字符时,unicode字符才会显示,直到我双击字符的位置应该出现。 string pdfTemplate = @”c:\po.pdf”; string newFile = @”g:\test\completed_fw4.pdf”; PdfReader pdfReader = new PdfReader(pdfTemplate); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create)); AcroFields pdfFormFields = pdfStamper.AcroFields; pdfFormFields.SetField(“position”, TextBox1.Text); pdfStamper.FormFlattening = false; // close the pdf pdfStamper.Close();

使用iTextSharp创建图像水印时,将图像水印添加到Pdf

不知道这是否可能。 在创建pdf并将其保存在磁盘后,在添加水印时看到很多post。 但在创建文档时如何添加图像水印。 我知道如何将图像添加到文档中。 但是我如何定位它以使其出现在页面末尾。

PdfPCell中的水平文本对齐

我正在使用此代码水平对齐。 cell = New PdfPCell(); p = New Phrase(“value”); cell.AddElement(p); cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; //Tried with Element.Align_Center Also. Tried Adding this line before adding element also. table.AddCell(cell); 它不起作用。 我正在创建一个包含5列的表,并在运行时使用上面的代码在for循环中动态添加单元格。 我希望所有单元格内容都居中。

如何在itextsharp pdf创建中设置单元格宽度

如何使用c#在itextsharp pdf cell ceration中设置单元格宽度和高度。 我只是用 cell.width = 200f; 但它应该显示错误消息。 宽度无法设定。 我该怎么办?..

iTextSharp – 裁剪PDF文件(C#)

我想使用iTextSharp和矩形(0,1000,600,155)裁剪PDF文件。 一切都很好,当你打开创建的* .pdf文件时,你只能看到那个裁剪的内容,但是! 如果您解析该pdf,仍然有来自文档不可见部分的信息和文本,我不能接受。 如何完整地删除该数据? 这是我的代码示例: static void cropiTxtSharp(){ string file =”C:\\testpdf.pdf”; string oldchar = “testpdf.pdf”; string repChar = “test.pdf”; PdfReader reader = new PdfReader(file); PdfDictionary pageDict; PdfRectangle rect = new PdfRectangle(0, 1000, 600, 115); pageDict = reader.GetPageN(1); pageDict.Put(PdfName.CROPBOX, rect); PdfStamper stamper = new PdfStamper(reader, new FileStream(file.Replace(oldchar, repChar), FileMode.Create, FileAccess.Write)); stamper.Close(); reader.Close(); } 编辑:这是有效的代码,我花了几个小时,但最后我做到了:P 首先,在项目中添加以下内容: […]