Tag: itext

如何防止替换注释更改位置和文本大小?

我正在使用iTextSharp将Typewriter注释替换为具有相同内容和位置的文本框,但是一些结果文本框最终处于不同文本大小的不同位置,尽管看似在hashMap具有完全相同的数据。 问题是,当我在此示例PDF上创建这些新注释,然后在Adobe Acrobat XI中查看PDF时,新文本框会出现以下问题: 它们已经从原始位置(与箭头相邻)移动到页面下方 文字的大小已经改变 右键单击新文本框时,没有可用的属性 我怀疑所有3个问题都是由于我正在创建新文本框的一个潜在问题。 当我在hashMap中检查annot的/Rect键时,它具有与原始freeTextAnnot相同顺序的相同矩形坐标,所以我不明白为什么某些注释最终会被取代。 这是我使用现有Typewriter注释数据创建新文本框的代码。 请注意,您需要将inputPath和outputPath设置为PDF的实际位置及其目标路径: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using iTextSharp; using iTextSharp.text.pdf; using System.IO; namespace PDFConverterTester { public class PdfModifierTester { public void testWithPaths() { //set to location of test PDF string inputPath = @”C:\InputPath\Before Conversion Dummy.pdf”; //set to destination of new […]

如何绕过iTextSharp桌边的角?

我想在itextsharp中制作一个圆角矩形。 这是我现在没有舍入的输出: 这是我处理输出的代码: pdftbl = new PdfPTable(3); pdftbl.WidthPercentage = 100; width = new float[3]; width[0] = 0.6F; width[1] = 0.2F; width[2] = 0.6F; pdftbl.SetWidths(width); pdfcel = new PdfPCell(new Phrase(Insuredaddress, docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); pdfcel = new PdfPCell(new Phrase(“”, docWhiteFont9)); pdfcel.Border = 0; pdftbl.AddCell(pdfcel); pdfcel = new PdfPCell(new Phrase(BkrAddrss, docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); objDocument.Add(pdftbl); […]

itext读取pdf 1s作为向上箭头ERROR

出于某种原因,itextsharp现在正在读取pdf,其中包含诸如4123之类的数字为4 * 23,其中*实际上是指向上方的箭头。 不知道为什么会这样。 请帮忙。 谢谢。 示例文件位于: https : //dl.dropboxusercontent.com/u/116833/SAMPLE%20PDF.pdf

在IIS上托管的C#中使用USB令牌打开X509证书选择

我正在制定一项要求,要求在ASP.Net C#中对PDF文件进行数字签名,并开发了一个在我的本地机器上使用USB令牌获取客户端证书的应用程序。 但是,在IIS服务器上托管此应用程序时收到错误“当前会话不是交互式” 。 任何人都有任何想法,我们如何从ASP.Net C#中的客户端机器获取X509Certificates,并且此应用程序托管在IIS服务器而不是控制台应用程序上。 我的代码供参考: private void getSign() { X509Store store = new X509Store(StoreLocation.CurrentUser); store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly); X509Certificate2 cert = null; //manually chose the certificate in the store X509Certificate2Collection sel = X509Certificate2UI.SelectFromCollection(store.Certificates, null, null, X509SelectionFlag.SingleSelection); if (sel.Count > 0) cert = sel[0]; else { //MessageBox.Show(“Certificate not found”); return; } SignWithThisCert(cert); }

iTextSharp如何旋转/切换页面从横向到纵向

我正在使用iTextSharp将多个PDF文件合并为一个Pdf。 我在网上找到了一些关于如何完成此任务的代码示例 。 它们都可以工作,没有明显的问题,因为我能够将多个PDF文件合并为一个PDF。 我所拥有的问题是我希望所有页面都在PORTRAIT中,因为一些PDF文件在LANDSCAPE中有页面,我希望它们可以旋转到PORTRAIT。 我不介意他们要么颠倒,要么侧身,但他们都必须是肖像。 查看列出的示例中的代码部分: page = writer.GetImportedPage(reader, i); rotation = reader.GetPageRotation(i); 始终将页面旋转值返回为0(零),因此代码部分 if (rotation == 90 rotation == 270) { cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height); } 永远不会被执行(如果这是应该做的,旋转页面)。 所以,根据第一个代码示例page = writer.GetImportedPage(reader, i)的链接中的代码page = writer.GetImportedPage(reader, i)在将其添加到新的合并之前,我将如何将页面的页面布局从Landscape更改为Portrait使用cb.AddTemplate… PDF文档cb.AddTemplate… ? PS。 确定页面是横向还是纵向我使用从SO获得的以下代码 (适用于上面的代码示例): float pageXYRatio = page.Width / page.Height; if (XYRatio > 1f) { […]

itext ColumnText忽略对齐

我试图在左侧获得一些文本行,在右侧获取一些文本。 出于某种原因,iText似乎完全忽略了对齐。 例: // create 200×100 column ct = new ColumnText(writer.DirectContent); ct.SetSimpleColumn(0, 0, 200, 100); ct.AddElement(new Paragraph(“entry1”)); ct.AddElement(new Paragraph(“entry2”)); ct.AddElement(new Paragraph(“entry3”)); ret = ct.Go(); ct.SetSimpleColumn(0, 0, 200, 100); ct.Alignment = Element.ALIGN_RIGHT; ct.AddElement(new Paragraph(“entry4”)); ct.AddElement(new Paragraph(“entry5”)); ct.AddElement(new Paragraph(“entry6”)); ret = ct.Go(); 我已将第二列的对齐方式设置为Element.ALIGN_RIGHT,但文本显示在第一列的顶部,从而呈现不可读的文本。 对齐仍然设置为左。 有任何想法吗?

让PdfStamper使用MemoryStreams(c#,itextsharp)

我找到了将PDF文件签名为新文件的旧代码,它将签署由Web服务发送的MemoryStreams(字节数组)。 简单吧? 好吧,那是昨天。 今天我无法让它发挥作用。 这是旧代码,它使用FileStreams并且它可以工作: public static string OldPdfSigner(PdfReader pdfReader, string destination, string password, string reason, string location, string pathToPfx) { using (FileStream pfxFile = new FileStream(pathToPfx, FileMode.Open, FileAccess.Read)) { … using (PdfStamper st = PdfStamper.CreateSignature(pdfReader, new FileStream(destination, FileMode.Create, FileAccess.Write), ‘\0’)) { PdfSignatureAppearance sap = st.SignatureAppearance; sap.SetCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.Reason = reason; sap.Location = […]

PDF使用C#读取高亮度文本(突出显示注释)

我使用iTextSharp编写了一个提取工具,可以从PDF文档中提取注释信息。 对于高亮注释,我只得到页面上突出显示的区域的矩形。 我的目标是提取已突出显示的文本。 为此,我使用`PdfTextExtractor’。 Rectangle rect = new Rectangle( pdfArray.GetAsNumber(0).FloatValue, pdfArray.GetAsNumber(1).FloatValue, pdfArray.GetAsNumber(2).FloatValue, pdfArray.GetAsNumber(3).FloatValue); RenderFilter[] filter = { new RegionTextRenderFilter(rect) }; ITextExtractionStrategy strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter); string textInsideRect = PdfTextExtractor.GetTextFromPage(pdfReader, pageNo, strategy); return textInsideRect; PdfTextExtractor返回的结果并不完全正确。 例如,它返回“即将消除纸张追逐”,即使只突出显示“消除” 。 有趣的是,包含突出显示的“消除”的TJ的整个文本是“将要消除纸张追逐” (TJ是将文本写入页面的PDF指令)。 我很想听到有关此问题的任何意见 – 也包括不涉及iTextSharp的解决方案。

iText或iTextSharp基本文本编辑

我可以通过多种方式从PDF中的页面中提取文本: String pageText = PdfTextExtractor.GetTextFromPage(reader, i); 这可用于获取页面上的任何文本。 或者: byte[] contentBytes = iTextSharp.text.pdf.parser.ContentByteUtils.GetContentBytesForPage(reader, i); 可能性是无穷无尽的。 现在我想删除/编辑某个单词,例如显式单词,敏感信息(将黑盒放在它们上面显然是一个坏主意:)或者PDF中的任何单词(简单和仅文本)。 我可以使用上面的方法找到这个词。 我可以算一下它的出现等等…… 我不关心布局,或者PDF并不是真正意图以这种方式操纵的事实。 我只想知道是否有一种机制可以让我以这种方式操纵我的PDF的原始内容。 你可以说我正在寻找“SetContentBytesForPage()”……

ItextSharp尝试解析html进行pdf转换时出错

我使用ItextSharp模块将下面列出的html转换为pdf页面。 mmammar Click to View Pricing FCI: 78211-014 78211-009 78211-006 78211-007 78211-003 78211-005 78211-008 78211-004 78211-012 78211-007LF 78211-015LF 78211-003LF 78211-009LF 78211-005LF 78211-010LF 78211-006LF 78211-014LF 78211-004LF 78211-012LF 78211-008LF 78211-011LF 78211-013LF 78211-010 78211-015 Souriau: 24JR124-3 C#代码生成上面的html: var html = new StringBuilder(@”Authorized Distributor Click to View Pricing, Inventory, Delivery & Lifecycle Information:”); List mfrBrands = MfrBrandView.Load(fileId); var uniquesuppliers […]