iText Stamping-Java

iText Stamping-Java,第1张

iText Stamping-Java

我做到了’:)

这是用于使用iText将自定义文本添加到文档而不使数字签名无效代码

//Read the source PDFPdfReader reader = new PdfReader(inputstream);//Create PdfStamp objectstamp = new PdfStamper(reader, new FileOutputStream(file), '', true);//Create the proper annotationPdfAnnotation annot = PdfAnnotation.createFreeText(stamp.getWriter(),  new Rectangle(150, 150, 200, 200), "Annotation 1", pcb);annot.setFlags(PdfAnnotation.FLAGS_PRINT);//Insert the annotation         stamp.addAnnotation(annot, 1);//Close the stampstamp.close();  

编辑:

为了在不使数字签名无效的情况下将图像图章插入文档,我使用了以下代码:

//Read the pdf PdfReader reader = new PdfReader(inputstream);//Use PdfStamper in append modestamp = new PdfStamper(reader, new FileOutputStream(file), '', true); //Read the imageImage img = Image.getInstance(ImageIO.read(imgStream), null);float w = img.getScaledWidth();float h = img.getScaledHeight();Rectangle location = new Rectangle(70, 770 - h, 70 + w, 770);//Create stamp annotationPdfAnnotation stampAnnot = PdfAnnotation.createStamp(stamp.getWriter(), location, null, "ITEXT");img.setAbsolutePosition(0, 0);//Create new PdfContentByte from the stamp writer//If you use cd = stamp.getOverContent(1) - you'll invalidate the signaturesPdfContentByte cb = new PdfContentByte(stamp.getWriter());PdfAppearance app = cb.createAppearance(w, h);app.addImage(img);stampAnnot.setAppearance(PdfName.N, app);stampAnnot.setFlags(PdfAnnotation.FLAGS_PRINT);stamp.addAnnotation(stampAnnot, 1);reader.close();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5461945.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存