public void testChangeAppearancesWithName() throws IOException {
try (InputStream resource = new FileInputStream("C:\\Users\\Prajwal\\Documents\\digisigndesk\\src\\org\\apache\\pdfbox\\examples\\doc\\5ab8cf12ddeb9f1fb4f33ae5.pdf");
PdfReader pdfReader = new PdfReader(resource);
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "signed-app-name.pdf"));
PdfWriter pdfWriter = new PdfWriter(result);
PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter, new StampingProperties().useAppendMode())) {
SignatureUtil signatureUtil = new SignatureUtil(pdfDocument);
PdfAcroForm acroForm = PdfAcroForm.getAcroForm(pdfDocument, false);
for (String name : signatureUtil.getSignatureNames()) {
PdfPKCS7 pkcs7 = signatureUtil.verifySignature(name);
X509Certificate signerCert = (X509Certificate) pkcs7.getSigningCertificate();
String signerName = CertificateInfo.getSubjectFields(signerCert).getField("CN");
PdfFormField field = acroForm.getField(name);
field.setModified();
for (PdfWidgetAnnotation pdfWidgetAnnotation : field.getWidgets()) {
pdfWidgetAnnotation.setRectangle(new PdfArray(new int[]{100, 100, 200, 200}));
PdfFormXObject form = new PdfFormXObject(new Rectangle(100, 100));
Canvas canvas = new Canvas(form, pdfDocument);
canvas.add(new Paragraph().setItalic().add("Signed by:"));
canvas.add(new Paragraph().setBold().add(signerName));
pdfWidgetAnnotation.setNormalAppearance(form.getPdfObject());
}
}
}
}
您好我正在使用上面的代码更改签名外观但是在adobe将签名显示为无效之后...我请求@mkl共享电子邮件以便我可以共享示例签名的pdf或建议任何合适的方式...我正在使用itext7