我已經使用iReport生成了一個包含3個頁面的報告。現在簽名只出現在一個頁面中。但我需要使用iText爲每個頁面簽名。使用iText在每個頁面中進行數字簽名
PdfReader reader = new PdfReader(fullFilePath);
String outputPath = reportPath + randomUUID + fileExtension;
FileOutputStream fout = new FileOutputStream(outputPath);
stp = PdfStamper.createSignature(reader, fout, '\0', null, true);
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null,PdfSignatureAppearance.SELF_SIGNED);
sap.setReason("test");
sap.setLocation("test");
String imagePath = servletContextPath + "/resources/img/signature.png";
File file = new File(imagePath);
byte[] imageByte = new byte[(int) file.length()];
try (FileInputStream fileInputStream = new FileInputStream(file)) {
fileInputStream.read(imageByte);
Image image = Image.getInstance(imageByte);
sap.setImage(image);
}
// comment next line to have an invisible signature
for (int page = 1; page <= reader.getNumberOfPages(); page++){
sap.setVisibleSignature(signatureRectangle, page, null);
}
你想每個頁面有一個簽名還是一個全局簽名? – mkl 2013-03-28 07:35:41
每個頁面上帶有可視化的一個全局簽名。 – ziha 2013-03-28 07:46:15
參考我的回答是,iText是不可能的(雖然可以適當擴展iText)。此外,具有多種可視化形式的此類簽名的法律價值也是有問題的,因此,PDF閱讀器可能會在將來開始拒絕此類簽名。 – mkl 2013-03-28 08:17:48