我做到了’:)
这是用于使用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();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)