我无法在不使数字签名失效的情况下盖印PDF文档。iText冲压 - Java
目前,我成功地加盖了PDF。但是,如果文档先前已签名,则签名不再有效。我明白为什么会发生这种情况,但如果我使用Acrobat添加文本或使用注释对其进行标记,则签名是有效的。
我尝试添加注释或注释,但它仍使签名无效。有没有方法可以使用iText将邮票添加到PDF中,而不会使数字签名失效?
下面是代码片段我使用的邮票:
PdfReader reader = new PdfReader(inputstream);
stamp = new PdfStamper(reader, new FileOutputStream(file));
PdfContentByte pcb;
BaseFont bf = BaseFont.createFont("Courier", BaseFont.CP1250,BaseFont.EMBEDDED);
Rectangle r = reader.getPageSizeWithRotation(1);
pcb = stamp.getOverContent(1);
// set the font and size
float size = 12;
pcb.setFontAndSize(bf, size);
float width = 90;
float centerX = 0, startY = 0;
centerX = r.getWidth() - (width/2) - 20;
startY = r.getHeight() - (15 * 2) - 145;
pcb.beginText();
pcb.showTextAligned(PdfContentByte.ALIGN_CENTER, stampText, centerX, startY, 0);
pcb.setFontAndSize(bf, 10);
pcb.showTextAligned(PdfContentByte.ALIGN_CENTER, date, centerX-9, startY-8, 0);
pcb.endText();
stamp.close();
任何帮助将非常感激,感谢
正如在回答解释[如何添加空白页在数字签名pdf使用Java?](http://stackoverflow.com/questions/16710439/how-to-add-blank-page-in-digitally-signed-pdf-using-java)你不能添加内容到一个按照您的方式签署PDF。你声称你可以用Acrobat做到这一点,但事实并非如此。您可能会在注释中混淆文本,并将文本添加到内容流中。如果签名允许添加注释,则应该在* append mode *中使用'PdfStamper'添加文本注释。 –
我只能通过注释中的文本通过Acrobat添加内容,我很抱歉误会。我成功添加了评论而不会使签名无效。但是我无法获得freeTextAnnotation的挂起,它仍然使签名无效。 我使用 'stamp = new PdfStamper(reader,new FileOutputStream(file),'\ 0',true); PdfContentByte pcb = new PdfContentByte(stamp.getWriter()); float size = 12; pcb.setFontAndSize(bf,size); PdfAnnotation annot2 = PdfAnnotation.createFreeText(stamp.getWriter(),new Rectangle(x,y,x1,y1),“A1”,pcb); stamp.addAnnotation(annot2,1)' –
@请在问题中加上这样的代码说明。 – mkl