Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3848

Get the exact original PDF that was signed(without signature fields)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.0.6
    • None
    • AcroForm, Signing
    • None

    Description

      I am trying to get the original pdf from the signed pdf.

      I am able to remove the signature using doc.getSignatureDictionaries().get(0).getSignedContent(signedPDF);

      However, the signature field stays.

      However, when I try to remove the signature fields using the following code:

      PDDocument pdDoc = PDDocument.load(origPDF);
      PDDocumentCatalog catalog = pdDoc.getDocumentCatalog();
      PDAcroForm form = catalog.getAcroForm();
      List<PDField> acroFormFields = form.getFields();
      for (PDField field: acroFormFields) {
      if (field.getFieldType().equalsIgnoreCase("Sig"))

      { System.out.println("START removing Sign Flags"); field.setReadOnly(true); field.setRequired(false); field.setNoExport(true); System.out.println("END removing Sign Flags"); System.out.println("START flattenning field"); field.getAcroForm().flatten(); field.getAcroForm().refreshAppearances(); System.out.println("END flattenning field"); //field.getAcroForm().refreshAppearances(); }

      The signature field is removed, but the image that was used for visible signature, somehow, magically appear. (The document that I load here is the one that has signature removed using origPDF = doc.getSignatureDictionaries().get(0).getSignedContent(signedPDF);

      See the attached files:
      Example.pdf (Original file)
      Example_Signed.pdf (Signed File)
      Example_Signed_orig.pdf (after removing the signature)
      Example_Signed_final.pdf (after flattening the Example_Signed_orig.pdf)

      See the stackoverflow post for more details:

      https://stackoverflow.com/questions/44843095/verifying-pdf-signature-in-java-using-bouncy-castle-and-pdfbox

      Attachments

        1. Example_Signed.pdf
          36 kB
          Nikola Radosevic
        2. Example_signed_final.pdf
          20 kB
          Nikola Radosevic
        3. Example_signed_orig.pdf
          21 kB
          Nikola Radosevic
        4. Example.pdf
          11 kB
          Nikola Radosevic

        Activity

          People

            Unassigned Unassigned
            nikola.radosevic Nikola Radosevic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: