Search code examples
javapdfitextdigital-signature

Verify if a PDF is digitally signed with iText


As the title says I want to know if a given PDF file is already digitally signed.

I used iText to sign it but I'm not able to know if it is already signed to eventually resign it or perform other actions.

Is there a way to do it simply (possibly using iText)?


Solution

  • Using iText:

    PdfReader reader = new PdfReader(...);
    AcroFields acroFields = reader.getAcroFields();
    List<String> signatureNames = acroFields.getSignatureNames();
    

    Now signatureNames contains the names of all reachable signature fields containing signatures, cf. the JavaDoc:

    /**
     * Gets the field names that have signatures and are signed.
     *
     * @return the field names that have signatures and are signed
     */
    public ArrayList<String> getSignatureNames()