Tag: itext

使用itextSharp 5.3.3对数字签名和validationPdf文档

我正在尝试使用iTextSharp 5.3.3对服务器(c#)上的pdf文档进行数字签名和validation。 我使用DigiSign(在线工具)生成.Pfx文件,然后使用Windows生成证书(.cer)文件 /// /// Signs a PDF document using iTextSharp library /// /// The path of the source pdf document which is to be signed /// The path at which the signed pdf document should be generated /// A Stream containing the private/public key in .pfx format which would be used to sign the […]

iTextSharp:如何在表格中找到第一行和第二行的高度?

我想获得第一和第二列高度,以了解我是否需要调用document.NewPage() 。 但是,如果不将表添加到文档中,我找不到这样做的方法。 例: PdfPRow firstRow = new PdfPRow(cells1.ToArray()); table.Rows.Add(firstRow); PdfPRow secondRow = new PdfPRow(cells2.ToArray()); table.Rows.Add(secondRow); float h1 = table.GetRowHeight(0), h2 = table.GetRowHeight(1); if (currentY – h1 – h2 < 30) document.NewPage(); document.Add(table);

来自HTML的iText 7可访问的PDF:当使用display:table时,如何避免表标记;

我正在开发一个ASP.NET MVC项目,它将视图转换为PDF。 以前使用Rotavia,但新的客户要求是PDF可访问/ 508兼容。 出于布局目的,以前的开发人员有一个完整的标题部分(徽标,标题,免责声明等)作为没有元素的表(只是td)。 我需要将它们转换为div,但看起来保持不变。 所以,我所做的是使它们成为div,然后使用CSS属性,display:table,display:table-row-group,display:table-row,display:table-cell。 它看起来几乎完全相同。 问题是,即使它们现在是div,也使用iText DefaultTagWorkerFactory,如下所示: ConverterProperties props = new ConverterProperties(); FontProvider fp = new FontProvider(); fp.AddStandardPdfFonts(); props.SetFontProvider(fp); var tagWorkerFactory = new DefaultTagWorkerFactory(); props.SetTagWorkerFactory(tagWorkerFactory); HtmlConverter.ConvertToPdf(html, pdfDoc, props); 它仍然将Div标签转换为table,tr和td标签。 显然,在div上使用display:table的整个目的是避免使用表但获得相同的布局效果。 为什么iText会实现这种行为,有什么方法吗? 如果没有,任何人都可以提供任何精确的CSS等效显示:table,display:table-row-group,display:table-row,display:table-cell,因为看起来iText只看到属性,“display:table”并使用table-tag。 我在自定义标记工作器工厂中尝试了以下操作,该工厂通过向我的div添加一个类“make-div”来inheritanceDefaultTagWorkerFactory,如下所示: public class AccessibilityTagWorkerFactory : DefaultTagWorkerFactory { public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context) { var attributes = tag.GetAttributes(); var […]

iTextSharp中的Pades LTVvalidation会引发公钥,而不是根CA证书的证书签名

我收到一个带有错误消息的Org.BouncyCastle.Security.InvalidKeyException当使用LtvVerifiervalidationpdf时, 公钥不会出现在证书签名中 。 在绕过CRL LDAP URI的问题之后出现此问题。 用于执行validation的代码与上一篇文章相同: public static bool Validate(byte[] pdfIn, X509Certificate2 cert) { using (var reader = new PdfReader(pdfIn)) { var fields = reader.AcroFields; var signames = fields.GetSignatureNames(); if (!signames.Any(n => fields.SignatureCoversWholeDocument(n))) throw new Exception(“None signature covers all document”); var verifications = signames.Select(n => fields.VerifySignature(n)); var invalidSignature = verifications.Where(v => !v.Verify()); var invalidTimeStamp […]

在iTextSharp中设置表格的高度

我创建了一个包含2列的表。 在第一行的第二个单元格中,我想插入另一个只有一个单元格的表格。 问题是我无法设置第二个表的高度。 它的内容高度超过了内容。 它的高度与添加它的单元高度相等。

iTextSharp table.SpacingBefore not not working

我有一张桌子,我试图从pdf文档的上边缘向下约20/30个浮点(f)。 我想稍微向下空间的原因是因为我的pdf文档边缘有一个矩形边框。 PdfPTable table = new PdfPTable(1); table.SpacingBefore = 20f; table.SpacingAfter = 20f; table.TotalWidth = 700f; table.LockedWidth = true; table.SpacingAfter工作得很好但是table.SpacingBefore不会,我的桌子只是坐在上边缘,根本不会空间/填充。

ItextSharp(Itext) – 为段落设置自定义字体

我试图将自定义字体设置为Paragraph,但我无法使其工作。 我尝试设置.Font =,但它只能在大小方面工作,但它忽略了字体。 你能帮忙吗? Paragraph T = new Paragraph(newTempLine); iTextSharp.text.Font contentFont = iTextSharp.text.FontFactory.GetFont(“Webdings”, 12, iTextSharp.text.Font.NORMAL); T.Font = contentFont; myDocument.Add(T);

从文档大纲(书签)中获取页码

我正在使用itext7库来操作一些现有的PDF。 出于某种原因,我无法从大纲中获取页码。 我想我应该以某种方式从PdfDestination中获取它,但在其任何子类中都找不到任何匹配的方法。 PdfDocument pdfDoc = new PdfDocument(new PdfReader(“example.pdf”)); var root = pdfDoc.GetOutlines(false); foreach (PdfOutline ol in root.GetAllChildren()) { Console.WriteLine(ol.GetTitle()); PdfDestination d = ol.GetDestination(); // how to get the page number from the destination object } 在iText5中,我使用了SimpleBookmark.GetBookmark(reader) ,它返回了包含“Page”条目的词典列表 – 但这个function似乎已在iText7中删除了。 编辑:我看了一下Github上的PdfExplicitDestination.getDestinationPage()的Net实现(对于java来说是一样的。我不明白这个方法的参数的用途。如果我传入null,它似乎只适用于pdf使用ToString()在大纲层次结构中使用一个级别。通过工作我的意思是它将零索引页码作为字符串返回。对于PDF代码,它找不到页码(对于第一级别)。 PdfDocument pdfDoc = new PdfDocument(new PdfReader(“example.pdf”)); var root = pdfDoc.GetOutlines(); foreach (PdfOutline ol in […]

PDF Itextsharp打印在打印输出的页面右下角添加边距

我有一个PDF导出函数(ality),当在页面/视图上呈现结果时,我有以下输出 如您所见,表格的内容在页面中心对齐,一切看起来都很完美。 但是在打印时,内容(表格)会略微收缩,输出会略微向左轻微推动,这意味着页面右侧和底部会有额外的空间。 这种扭曲的输出在纸张打印机和文档刻录机打印输出上都显示如下。 我无法确定导致这种情况的原因,因为代码中的一切似乎都很好。 相同的代码用于创建和输出PDF文件,所有内容都显示为完美居中。 从网页打印(第一张图片)是问题所在。 这是一个CSS问题还是XMLworker问题? 我的导出方法如下(不相关的代码修剪) public ActionResult ExportFileToPrint() { var printList = conStrings.GetReport(search); string webgridstyle = style.GetCss(); //Pdf css /*Grid with records data (rows)*/ string gridHtml = style.GetGrid(printList); string exportData = String.Format (“” + “{0}” + “” + “” + “{1}” + “”, “” + webgridstyle + “”, gridHtml); var bytes […]

在pdf中的每个图像的正下方或上方添加文本

private static void InsertTextToPdf(string sourceFileName, string newFileName) { using (Stream pdfStream = new FileStream(sourceFileName, FileMode.Open)) using (Stream newpdfStream = new FileStream(newFileName, FileMode.Create, FileAccess.ReadWrite)) { PdfReader pdfReader = new PdfReader(pdfStream); PdfStamper pdfStamper = new PdfStamper(pdfReader, newpdfStream); PdfContentByte pdfContentByte = pdfStamper.GetOverContent(1); BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); pdfContentByte.SetColorFill(BaseColor.BLUE); pdfContentByte.SetFontAndSize(baseFont, 8); pdfContentByte.BeginText(); pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER, “Kevin Cheng – A Hong […]