Class ITextDocumentReader

java.lang.Object
eu.europa.esig.dss.pdf.openpdf.ITextDocumentReader
All Implemented Interfaces:
PdfDocumentReader, Closeable, AutoCloseable

public class ITextDocumentReader extends Object implements PdfDocumentReader
The IText (OpenPdf) implementation of PdfDocumentReader
  • Constructor Details

    • ITextDocumentReader

      public ITextDocumentReader(DSSDocument dssDocument) throws IOException, InvalidPasswordException
      Default constructor of the OpenPDF implementation of the Reader
      Parameters:
      dssDocument - DSSDocument to read
      Throws:
      IOException - if an exception occurs
      InvalidPasswordException - if the password is not provided or invalid for a protected document
    • ITextDocumentReader

      public ITextDocumentReader(DSSDocument dssDocument, byte[] passwordProtection) throws IOException, InvalidPasswordException
      The OpenPDF implementation of the Reader to read a password-protected document
      Parameters:
      dssDocument - DSSDocument to read
      passwordProtection - binaries of a password to open a protected document
      Throws:
      IOException - if an exception occurs
      InvalidPasswordException - if the password is not provided or invalid for a protected document
    • ITextDocumentReader

      public ITextDocumentReader(DSSDocument dssDocument, byte[] passwordProtection, PdfMemoryUsageSetting pdfMemoryUsageSetting) throws IOException, InvalidPasswordException
      The OpenPDF implementation of the Reader
      Parameters:
      dssDocument - DSSDocument to read
      passwordProtection - binaries of a password to open a protected document
      pdfMemoryUsageSetting - PdfMemoryUsageSetting
      Throws:
      IOException - if an exception occurs
      InvalidPasswordException - if the password is not provided or invalid for a protected document
    • ITextDocumentReader

      public ITextDocumentReader(byte[] binaries, byte[] passwordProtection) throws IOException, InvalidPasswordException
      The OpenPDF implementation of the Reader
      Parameters:
      binaries - a byte array of a PDF to read
      passwordProtection - binaries of a password to open a protected document
      Throws:
      IOException - if an exception occurs
      InvalidPasswordException - if the password is not provided or invalid for a protected document
    • ITextDocumentReader

      public ITextDocumentReader(com.lowagie.text.pdf.PdfReader pdfReader)
      The constructor to directly instantiate the ITextDocumentReader
      Parameters:
      pdfReader - PdfReader
  • Method Details

    • getPdfReader

      public com.lowagie.text.pdf.PdfReader getPdfReader()
      Returns the current instance of PdfReader
      Returns:
      PdfReader
    • getDSSDictionary

      public PdfDssDict getDSSDictionary()
      Description copied from interface: PdfDocumentReader
      Loads the last DSS dictionary from the document if exists NOTE: can return null if DSS dictionary is not present
      Specified by:
      getDSSDictionary in interface PdfDocumentReader
      Returns:
      PdfDssDict
    • extractSigDictionaries

      public Map<PdfSignatureDictionary,List<PdfSignatureField>> extractSigDictionaries()
      Description copied from interface: PdfDocumentReader
      Extracts PdfSignatureDictionaries present in the signature
      Specified by:
      extractSigDictionaries in interface PdfDocumentReader
      Returns:
      a map between PdfSignatureDictionary and related PdfSignatureFields
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isSignatureCoversWholeDocument

      public boolean isSignatureCoversWholeDocument(PdfSignatureDictionary signatureDictionary)
      Description copied from interface: PdfDocumentReader
      Checks if a signature for the given PDF Signature Dictionary covers the whole document
      Specified by:
      isSignatureCoversWholeDocument in interface PdfDocumentReader
      Parameters:
      signatureDictionary - PdfSignatureDictionary to check the result for
      Returns:
      TRUE if the signature covers the whole document, false otherwise
    • getNumberOfPages

      public int getNumberOfPages()
      Description copied from interface: PdfDocumentReader
      Returns an amount of pages found in the document
      Specified by:
      getNumberOfPages in interface PdfDocumentReader
      Returns:
      number of pages
    • getPageBox

      public AnnotationBox getPageBox(int page)
      Description copied from interface: PdfDocumentReader
      Returns a page box dimensions
      Specified by:
      getPageBox in interface PdfDocumentReader
      Parameters:
      page - number of a page to get annotation box of
      Returns:
      AnnotationBox representing page dimensions
    • getPageRotation

      public int getPageRotation(int page)
      Description copied from interface: PdfDocumentReader
      This method returns a corresponding page's rotation within the document
      Specified by:
      getPageRotation in interface PdfDocumentReader
      Parameters:
      page - number of a page to get rotation of
      Returns:
      rotation degrees
    • getPdfAnnotations

      public List<PdfAnnotation> getPdfAnnotations(int page)
      Description copied from interface: PdfDocumentReader
      Retrieves all annotations found in the document
      Specified by:
      getPdfAnnotations in interface PdfDocumentReader
      Parameters:
      page - number
      Returns:
      a list of PdfAnnotations associated with the given page
    • getObjectByKey

      public com.lowagie.text.pdf.PdfObject getObjectByKey(PdfObjectKey objectKey)
      Gets PdfObject from the PDF by the given objectKey
      Parameters:
      objectKey - PdfObjectKey to get object for
      Returns:
      PdfObject when the object corresponding to the defined key found, NULL otherwise
    • createPdfStream

      public com.lowagie.text.pdf.PdfStream createPdfStream(byte[] binaries)
      Creates a PdfStream with given binaries
      Parameters:
      binaries - binary array to be included to the stream
      Returns:
      PdfStream
    • generateImageScreenshot

      public BufferedImage generateImageScreenshot(int page)
      Description copied from interface: PdfDocumentReader
      Generates the image screenshot for the given page of the PDF
      Specified by:
      generateImageScreenshot in interface PdfDocumentReader
      Parameters:
      page - number to be generated
      Returns:
      BufferedImage screenshot for the given page
    • generateImageScreenshotWithoutAnnotations

      public BufferedImage generateImageScreenshotWithoutAnnotations(int page, List<PdfAnnotation> annotations)
      Description copied from interface: PdfDocumentReader
      Generates the image screenshot by hiding the given list of annotationBoxes
      Specified by:
      generateImageScreenshotWithoutAnnotations in interface PdfDocumentReader
      Parameters:
      page - number to be generated
      annotations - a list of PdfAnnotations to be hidden
      Returns:
      BufferedImage screenshot for the given page
    • isEncrypted

      public boolean isEncrypted()
      Description copied from interface: PdfDocumentReader
      This method checks whether the document is encrypted
      Specified by:
      isEncrypted in interface PdfDocumentReader
      Returns:
      TRUE if the document is encrypted, FALSE otherwise
    • isOpenWithOwnerAccess

      public boolean isOpenWithOwnerAccess()
      Description copied from interface: PdfDocumentReader
      This method verifies if the document has been opened with a full owner access (all modifications are permitted)
      Specified by:
      isOpenWithOwnerAccess in interface PdfDocumentReader
      Returns:
      TRUE if the document has been open with a full access, FALSE otherwise
    • canFillSignatureForm

      public boolean canFillSignatureForm()
      Description copied from interface: PdfDocumentReader
      This method verifies whether fill-in of existing signature fields is allowed by PDF document permissions dictionary
      Specified by:
      canFillSignatureForm in interface PdfDocumentReader
      Returns:
      TRUE if fill-in signature forms is permitted, FALSE otherwise
    • canCreateSignatureField

      public boolean canCreateSignatureField()
      Description copied from interface: PdfDocumentReader
      This method verifies whether creation of new signature fields is allowed by the PDF permissions dictionary
      Specified by:
      canCreateSignatureField in interface PdfDocumentReader
      Returns:
      TRUE if the new signature field creation is permitted, FALSE otherwise
    • getCertificationPermission

      public CertificationPermission getCertificationPermission()
      Description copied from interface: PdfDocumentReader
      Returns value of /DocMDP dictionary defining the permitted modification in a PDF, when present
      Specified by:
      getCertificationPermission in interface PdfDocumentReader
      Returns:
      CertificationPermission
    • isUsageRightsSignaturePresent

      public boolean isUsageRightsSignaturePresent()
      Description copied from interface: PdfDocumentReader
      This method verifies whether a PDF contains a usage rights signature
      Specified by:
      isUsageRightsSignaturePresent in interface PdfDocumentReader
      Returns:
      TRUE of a PDF contains a usage rights signature, FALSE otherwise
    • getCatalogDictionary

      public PdfDict getCatalogDictionary()
      Description copied from interface: PdfDocumentReader
      Returns a document catalog as a dictionary
      Specified by:
      getCatalogDictionary in interface PdfDocumentReader
      Returns:
      PdfDict
    • generateDocumentId

      public com.lowagie.text.pdf.PdfObject generateDocumentId(PAdESCommonParameters parameters)
      Computes a DocumentId in a deterministic way based on the given parameters and the document
      Parameters:
      parameters - PAdESCommonParameters
      Returns:
      PdfObject representing an /ID entry containing a deterministic identifier
    • getPdfHeaderVersion

      public float getPdfHeaderVersion()
      Description copied from interface: PdfDocumentReader
      Returns version of the PDF document defined in the document's header.
      Specified by:
      getPdfHeaderVersion in interface PdfDocumentReader
      Returns:
      document version from file's header
    • getVersion

      public float getVersion()
      Description copied from interface: PdfDocumentReader
      Returns version of the PDF document. Returns version defined in the file header, or catalog's /Version, when latest is present.
      Specified by:
      getVersion in interface PdfDocumentReader
      Returns:
      document version
    • setVersion

      public void setVersion(float version)
      Description copied from interface: PdfDocumentReader
      Sets PDF version number, by upgrading /Catalog dictionary /Version parameter
      Specified by:
      setVersion in interface PdfDocumentReader
      Parameters:
      version - value (e.g. 1.7)
    • createPdfDict

      public PdfDict createPdfDict()
      Description copied from interface: PdfDocumentReader
      Creates an empty PdfDict
      Specified by:
      createPdfDict in interface PdfDocumentReader
      Returns:
      PdfDict
    • createPdfArray

      public PdfArray createPdfArray()
      Description copied from interface: PdfDocumentReader
      Creates an empty PdfArray
      Specified by:
      createPdfArray in interface PdfDocumentReader
      Returns:
      PdfArray