我使用 iReport 生成了一个包含 3 页的报告。现在签名只出现在一页中。但我需要使用 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);
}