Class PdfBoxSignatureService

java.lang.Object
eu.europa.esig.dss.pdf.AbstractPDFSignatureService
eu.europa.esig.dss.pdf.pdfbox.PdfBoxSignatureService
All Implemented Interfaces:
PDFSignatureService

public class PdfBoxSignatureService
extends AbstractPDFSignatureService
Implementation of PDFSignatureService using PDFBox
  • Constructor Details

    • PdfBoxSignatureService

      public PdfBoxSignatureService​(PDFServiceMode serviceMode, PdfBoxSignatureDrawerFactory signatureDrawerFactory)
      Constructor for the PdfBoxSignatureService
      Parameters:
      serviceMode - current instance is used to generate DocumentTypestamp or Signature signature layer
      signatureDrawerFactory - drawer factory implementation to be used
  • Method Details

    • setSecureRandomProvider

      public void setSecureRandomProvider​(SecureRandomProvider secureRandomProvider)
      Set the SecureRandomProvider. Allows to modify a custom behavior for signing of encrypted documents.
      Parameters:
      secureRandomProvider - SecureRandomProvider
    • checkDocumentPermissions

      protected void checkDocumentPermissions​(DSSDocument document, String pwd)
      Description copied from class: AbstractPDFSignatureService
      This method checks if the document is not encrypted or with limited edition rights
      Specified by:
      checkDocumentPermissions in class AbstractPDFSignatureService
      Parameters:
      document - DSSDocument the document which will be modified
      pwd - String password protection phrase used to encrypt the document
    • digest

      public byte[] digest​(DSSDocument toSignDocument, PAdESCommonParameters parameters)
      Description copied from interface: PDFSignatureService
      Returns the digest value of a PDF document
      Parameters:
      toSignDocument - the document to be signed
      parameters - the signature/timestamp parameters
      Returns:
      the digest value
    • sign

      public DSSDocument sign​(DSSDocument toSignDocument, byte[] signatureValue, PAdESCommonParameters parameters)
      Description copied from interface: PDFSignatureService
      Signs a PDF document
      Parameters:
      toSignDocument - the pdf document
      signatureValue - the signature value
      parameters - the signature/timestamp parameters
      Returns:
      DSSDocument
    • createSignatureDictionary

      protected org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature createSignatureDictionary​(org.apache.pdfbox.pdmodel.PDDocument pdDocument, PAdESCommonParameters parameters)
      Creates a new signature dictionary Note for developers: keep protected! See https://github.com/esig/dss/pull/138
      Parameters:
      pdDocument - PDDocument
      parameters - PAdESCommonParameters
      Returns:
      PDSignature
    • setMDPPermission

      public void setMDPPermission​(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature signature, int accessPermissions)
      Set the access permissions granted for this document in the DocMDP transform parameters dictionary. Details are described in the table "Entries in the DocMDP transform parameters dictionary" in the PDF specification.
      Parameters:
      doc - The document.
      signature - The signature object.
      accessPermissions - The permission value (1, 2 or 3).
    • checkEncryptedAndSaveIncrementally

      public void checkEncryptedAndSaveIncrementally​(org.apache.pdfbox.pdmodel.PDDocument pdDocument, OutputStream outputStream, PAdESCommonParameters parameters)
      Checks if the document is encrypted and saves incrementally to outputStream
      Parameters:
      pdDocument - PDDocument to check and save
      outputStream - OutputStream to save the content to
      parameters - PAdESCommonParameters
    • saveDocumentIncrementally

      public void saveDocumentIncrementally​(org.apache.pdfbox.pdmodel.PDDocument pdDocument, OutputStream outputStream)
      Saves the document incrementally
      Parameters:
      pdDocument - PDDocument to save
      outputStream - OutputStream to save incremental update to
    • addDssDictionary

      public DSSDocument addDssDictionary​(DSSDocument document, List<DSSDictionaryCallback> callbacks, String pwd)
      Description copied from interface: PDFSignatureService
      This method adds the DSS dictionary (Baseline-LT)
      Parameters:
      document - the document to be extended
      callbacks - the callbacks to retrieve the revocation data,...
      pwd - the password protection used to create the encrypted document
      Returns:
      the pdf document with the added dss dictionary
    • getAvailableSignatureFields

      public List<String> getAvailableSignatureFields​(DSSDocument document, String pwd)
      Description copied from interface: PDFSignatureService
      Returns not-signed signature fields from an encrypted document
      Parameters:
      document - the pdf document
      pwd - the password protection phrase used to encrypt the document
      Returns:
      the list of not signed signature field names
    • addNewSignatureField

      public DSSDocument addNewSignatureField​(DSSDocument document, SignatureFieldParameters parameters, String pwd)
      Description copied from interface: PDFSignatureService
      This method allows to add a new signature field to an existing encrypted pdf document
      Parameters:
      document - the pdf document
      parameters - the parameters with the coordinates,... of the signature field
      pwd - the password protection used to create the encrypted document
      Returns:
      the pdf document with the new added signature field
    • loadPdfDocumentReader

      protected PdfDocumentReader loadPdfDocumentReader​(DSSDocument dssDocument, String passwordProtection) throws IOException, InvalidPasswordException
      Description copied from class: AbstractPDFSignatureService
      Loads PdfDocumentReader instance
      Specified by:
      loadPdfDocumentReader in class AbstractPDFSignatureService
      Parameters:
      dssDocument - DSSDocument to read
      passwordProtection - String the password used to protect the document
      Returns:
      PdfDocumentReader
      Throws:
      IOException - in case of loading error
      InvalidPasswordException - if the password is not provided or invalid for a protected document
    • loadPdfDocumentReader

      protected PdfDocumentReader loadPdfDocumentReader​(byte[] binaries, String passwordProtection) throws IOException, InvalidPasswordException
      Description copied from class: AbstractPDFSignatureService
      Loads PdfDocumentReader instance
      Specified by:
      loadPdfDocumentReader in class AbstractPDFSignatureService
      Parameters:
      binaries - a byte array
      passwordProtection - String the password used to protect the document
      Returns:
      PdfDocumentReader
      Throws:
      IOException - in case of loading error
      InvalidPasswordException - if the password is not provided or invalid for a protected document