我無法在不使數字簽名失效的情況下蓋印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