0
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());
            }
        }
    }
}

Hi I am using the above code for changing signature appearance but after that adobe is showing the signature as invalid...I request @mkl to share email so that I can share sample signed pdf or suggest any suitable ways... I am using itext7

Prajwal M
  • 1
  • 4
  • what library are you using? Please add the appropriate label and mention the version in your question. The directory name has "pdfbox" but this isn't pdfbox. – Tilman Hausherr Mar 28 '18 at 09:02
  • Can you share a sample pdf before and after your manipulation? – mkl Apr 06 '18 at 12:35
  • Hi I am using the above code for changing signature appearance but after that adobe is showing the signature as invalid...I request @mkl to share email so that I can share sample signed pdf or suggest any suitable ways... I am using itext7 – Prajwal M Apr 09 '18 at 04:58
  • The usual way to share binary data related to a question is to create a public share (Dropbox, Google drive, ... - nothing with ads or worse, please) and post the url of that share here. That way others can help, too. – mkl Apr 09 '18 at 05:29
  • Related answer: The code this question is about has been written for [this answer](https://stackoverflow.com/a/37070234/1729265). As written there, *this obviously is not allowed if your documents has been certified with no changes allowed.* This could be the reason for the OP's problems. – mkl Apr 09 '18 at 14:22

0 Answers0