Tag: itextsharp

如何从左下角到左上角更改pdf页面中文本的坐标

我正在使用PDFBOX和itextsharp dll并处理pdf。 这样我就可以得到一个矩形内文本的文本坐标。 使用itextsharp.dll提取矩形坐标。 基本上我从itextsharp.dll获取矩形坐标,其中itextsharp使用坐标系统作为左下角。 我从PDFBOX获取pdf页面文本,其中PDFBOX使用坐标系统作为左上角。 我需要帮助将坐标从左下角转换为左上角 提前致谢 更新我的问题 请原谅我,如果你理解我的问题,如果没有提供完整的信息.. 好吧,让我试着从一开始就提供更多细节。 我正在开发一个工具,我在其中获得一个PDF,其中使用评论部分中的一些绘图标记绘制一个矩形。 现在我正在使用iTextsharp读取矩形坐标 PdfDictionary pageDict = pdReader.GetPageN(page_no); PdfArray annotArray = pageDict.GetAsArray(PdfName.ANNOTS); 其中pdReader是PdfReader。 并使用PDFBOX提取页面文本及其坐标。 在哪里我有一个类创建pdfBoxTextExtraction在这我处理文本和坐标,使它返回文本和llx,lly,urx,ury “逐行”请逐行注意而不是句子明智。 所以我想提取位于Rectangle坐标内的文本。 当从itextsharp返回矩形的坐标时,我陷入困境,即llx,lly,urx,矩形的ury在左下角有一个原点,因为从PDFBOX返回的文本坐标在左上角有一个原点。然后我意识到我需要调整y轴,使原点从左下角移动到左上角。 因为我得到了页面的高度和庄稼的高度 iTextSharp.text.Rectangle mediabox = reader.GetPageSize(page_no); iTextSharp.text.Rectangle cropbox = reader.GetCropBox(page_no); 做了一些基本调整 lly = mediabox.Top – lly ury = mediabox.Top – ury 在某些情况下,调整工作,而在一些PDF需要调整cropbox lly = cropbox .Top – lly ury […]

itextSharp – 合并pdf文件会禁用扩展的读者权限

我正在使用Itextsharp v5.1并创建了启用的阅读器pdf文件。 我写了一个填充表格的ac#class,并保留每个pdf文件的扩展阅读器。 但是,当我在这里使用这个MergeFiles函数时,它会创建一个新的Merged文件而不是扩展阅读器,我需要你的帮助,请将它转为扩展阅读器…… 我的MergeFiles函数是: public static void MergeFiles(string destinationFile, string[] sourceFiles) { try { //1: Create the MemoryStream for the destination document. using (MemoryStream ms = new MemoryStream()) { //2: Create the PdfCopyFields object. PdfCopyFields copy = new PdfCopyFields(ms); // – Set the security and other settings for the destination file. //copy.Writer.SetEncryption(PdfWriter.STRENGTH128BITS, null, “1234”, […]

在合并之间合并字体pdfs itextsharp C#

我需要将多个pdf合并在一起。 我正在使用itextsharp来创建所有的pdf。 我需要将pdf的大小减小到尽可能小的大小。 我知道每个pdf的字体都是重复的。 在合并的pdf中是否只使用一组字体? 例如,pdf1是2.8mb,pdf2是2.8mb我将它们合并在一起,大约5.7mb。 我知道这两个pdf都使用相同的字体,但字体的数据正在被删除,即使它在相同的pdf中。 我尝试使用压缩属性设置为最佳压缩并设置完全压缩,并且几乎不会减小尺寸。 虽然当我通过Acrobat X pro运行pdf并优化其减少近90%+从160 mb到5 mb。 使用情况审计表明,在优化之前,其90%的pdf是字体。 现在有没有办法合并pdfs合并之间的字体?

使用itextsharp将多个图像转换为多个页面PDF

我需要使用模板 将图像转换为PDF 。 我可以使用itextsharp创建一个页面PDF。 假设1图像为1页PDF 。 当我有多个图像时会出现问题。 如何使用预定义模板创建多个页面PDF。 以下是我的代码: public static string CreatePDFDocument(string docname, string imagePath, string mediaField) { PdfReader pdfReader = null; string pdfPortrait = ConfigurationManager.AppSettings[“PdfPortraitTemplate”]; string pdfLandscape = ConfigurationManager.AppSettings[“PdfLandscapeTemplate”]; iTextSharp.text.Image instanceImg = iTextSharp.text.Image.GetInstance(imagePath); string filename = ConfigurationManager.AppSettings[“LocalFolder”] + docname + “.pdf”; FileStream pdfOutputFile = new FileStream(filename, FileMode.Create); if (instanceImg.ScaledHeight >= instanceImg.ScaledWidth) { pdfReader […]

将所有PDF字段设置为ReadOnly

在iTextSharp中有一种方法可以将表单上的所有字段设置为只读吗? 目前我正在单独设置每一个,这是一个痛苦的… formFields.SetFieldProperty( “Applicant.Phone”, “setfflags”, PdfFormField.FF_READ_ONLY, null ); formFields.SetFieldProperty( “Applicant.SSN”, “setfflags”, PdfFormField.FF_READ_ONLY, null ); 等等

获取堆栈溢出exception生成PDF

作为我之前问题的延续,我一直在试用PDF的页眉和页脚function。 经过一番讨论后,我在PdfPageEventHelper类上更改了很多代码。 以下是我所拥有的: public class ReportHeaderFooter : PdfPageEventHelper { public string HeaderTitle { get; set; } public IReportsAccessor ReportsAccessor { get; set; } private Image footerImg; private Image headerImg; private BaseColor headerColor; private PdfPTable tblHeader; public ReportHeaderFooter(IReportsAccessor reportsAccessor) { this.ReportsAccessor = reportsAccessor; var rootPath = ConfigurationManager.AppSettings[“SaveFileRootPath”]; headerColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml(“#ffffff”)); // Not really but I […]

ItextSharp中的Pdf合并问题(合并Pdfs后不保留其值)

我们正在尝试使用ITextSharp合并三个PDF。 问题是合并后我们只能从第一个PDF获取数据,而其他两个PDF不保留其值。 所有这些PDF都具有相同的结构(即它们使用相同的模板和不同的数据),因此我的假设是它们具有相同的字段(AcroFields),这可能会在合并时产生此问题。 这是合并代码: public void MergeFiles(string destinationFile, string[] sourceFiles) { try { int f = 0; string outFile = destinationFile; Document document = null; PdfCopy writer = null; while (f < sourceFiles.Length) { // Create a reader for a certain document PdfReader reader = new PdfReader(sourceFiles[f]); // Retrieve the total number of pages int […]

在iTextSharp中为pdf单元格添加页眉,页脚和背景颜色

我正在使用iTextSharp for PDF Doc creater。 我想添加标题,它是一个文本和它下面的一行,然后是要出现的表格。 页脚应包含右下角的页码。 我能够创建表,但页眉和页脚似乎是一个问题。 有人可以给出一个示例代码来解决这个问题。 我也希望为表格中的标题列着色,即仅第一行的标题列具有背景颜色。 我是新来的,所以请帮帮我。 提前致谢。

使用iTextSharp 4.1.6为特定页面添加书签

我想添加一个指向文档中特定页面的书签。 从其他PDF文件中添加书签我正在使用与下面类似的代码合并,但是当我复制它以将自定义书签添加到未加书签的项目时,它会失败: var bookmarks = new ArrayList(); var writer = new PdfCopy(document, memorystream); // … var uni = new Hashtable(); uni.Add(“Action”, “GoTo”); uni.Add(“Title”, “Awesome Unicorn pic”); uni.Add(“Page”, “8 XYZ 0 0 0”); bookmarks.Add(uni); // … writer.Outlines = bookmarks; 但显然(“Page”, “8 XYZ 0 0 0”)并未引用第 8 节 ,而是第 8 节或类似的内容。 是否有可用于指向任意页面的替代操作? 还是其他一些方法?

iTextSharp Textfield将字​​体设置为Bold

对于textfield对象,我想将样式更改为粗体。 我已经创建了arial字体,因为它不是BaseFont对象的默认字体。 显然,TextField对象仅将BaseFont作为有效字体。 我想知道如何将我分配给文本字段的字体样式更改为粗体。 有没有办法做到这一点? 这是我到目前为止的代码 TextField txtNewField = new TextField(stamp.Writer, new Rectangle(1, 1, 75, 25), “TxtField”); BaseFont arial = BaseFont.CreateFont(@”c:\windows\fonts\arial.ttf”, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); txtNewField.FontSize = 8; txtNewField.Font = arial; 先感谢您!