Class PdfSigner

java.lang.Object
org.jpedal.tools.PdfSigner

public final class PdfSigner extends Object
Digitally signs PDF documents

Example usage:


 PdfSigner.signPdf(
      "/input.pdf",
      "/output.pdf",
      "1234",
      "/keystore.p12",
      "John Doe",
      "London",
      "Accepting Agreement"
 );
 

Note: Your keystore must meet the following conditions to be suitable for signing:

  • The keystore must be a PKCS#12 file containing your private key and X.509 certificate
  • The certificate must be valid
  • The certificate signature algorithm must be SHA256 RSA
  • The private key usage must be digitalSignature
  • Field Details

    • DEFAULT_SIGNATURE_SIZE

      public static final int DEFAULT_SIGNATURE_SIZE
      The default signature size if none is specified.
      See Also:
  • Method Details

    • signPdf

      public static void signPdf(String input, String output, String password, String keystore, String name, String location, String reason) throws IOException
      Signs the PDF file and writes the result to disk
      Parameters:
      input - The file location of the document to be signed
      output - The file location of the document which is to be produced
      password - The password for your key store
      keystore - The file location of your key store
      name - The name of the person/business signing the document
      location - The real-world location of where the document is said to be signed
      reason - The reason for signing the document
      Throws:
      IOException - IOException
    • signPdf

      public static void signPdf(String input, String output, String password, String keystore, String name, String location, String reason, PdfSigner.ACCESS_PERMISSION permissions) throws IOException
      Signs the PDF file and writes the result to disk
      Parameters:
      input - The file location of the document to be signed
      output - The file location of the document which is to be produced
      password - The password for your key store
      keystore - The file location of your key store
      name - The name of the person/business signing the document
      location - The real-world location of where the document is said to be signed
      reason - The reason for signing the document
      permissions - The Document Access Permissions level (see PdfSigner.ACCESS_PERMISSION
      Throws:
      IOException - IOException
    • signPdf

      public static void signPdf(String input, String output, String password, String keystore, String name, String location, String reason, int signatureSize) throws IOException
      Signs the PDF file and writes the result to disk
      Parameters:
      input - The file location of the document to be signed
      output - The file location of the document which is to be produced
      password - The password for your key store
      keystore - The file location of your key store
      name - The name of the person/business signing the document
      location - The real-world location of where the document is said to be signed
      reason - The reason for signing the document
      signatureSize - The size of the /Contents value in the signature dictionary
      Throws:
      IOException - IOException
    • signPdf

      public static void signPdf(String input, String output, String password, String keystore, String name, String location, String reason, PdfSigner.ACCESS_PERMISSION permissions, int signatureSize) throws IOException
      Signs the PDF file and writes the result to disk
      Parameters:
      input - The file location of the document to be signed
      output - The file location of the document which is to be produced
      password - The password for your key store
      keystore - The file location of your key store
      name - The name of the person/business signing the document
      location - The real-world location of where the document is said to be signed
      reason - The reason for signing the document
      permissions - The Document Access Permissions level (see PdfSigner.ACCESS_PERMISSION
      signatureSize - The size of the /Contents value in the signature dictionary
      Throws:
      IOException - IOException