Package eu.europa.esig.dss.pdf.pdfbox
Class PdfBoxDocumentReader
java.lang.Object
eu.europa.esig.dss.pdf.pdfbox.PdfBoxDocumentReader
- All Implemented Interfaces:
PdfDocumentReader,Closeable,AutoCloseable
The PDFBox implementation of
PdfDocumentReader-
Constructor Summary
ConstructorsConstructorDescriptionPdfBoxDocumentReader(byte[] binaries, String passwordProtection) The PDFBox implementation of the ReaderPdfBoxDocumentReader(DSSDocument dssDocument) Default constructor of the PDFBox implementation of the ReaderPdfBoxDocumentReader(DSSDocument dssDocument, String passwordProtection) The PDFBox implementation of the ReaderPdfBoxDocumentReader(org.apache.pdfbox.pdmodel.PDDocument pdDocument) The constructor to directly instantiate thePdfBoxDocumentReader -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis method verifies whether creation of new signature fields is allowed by the PDF permissions dictionarybooleanThis method verifies whether fill-in of existing signature fields is allowed by PDF document permissions dictionaryvoidclose()Creates an emptyPdfArrayCreates an emptyPdfDictExtracts PdfSignatureDictionaries present in the signaturelonggenerateDocumentId(PAdESCommonParameters parameters) Computes a DocumentId in a deterministic way based on the givenparametersand the documentgenerateImageScreenshot(int page) Generates the image screenshot for the given page of the PDFgenerateImageScreenshotWithoutAnnotations(int page, List<PdfAnnotation> annotations) Generates the image screenshot by hiding the given list ofannotationBoxesReturns a document catalog as a dictionaryReturns value of /DocMDP dictionary defining the permitted modification in a PDF, when presentLoads the last DSS dictionary from the document if exists NOTE: can return null if DSS dictionary is not presentintReturns an amount of pages found in the documentgetPageBox(int page) Returns a page box dimensionsintgetPageRotation(int page) This method returns a corresponding page's rotation within the documentorg.apache.pdfbox.pdmodel.PDDocumentReturns the current instance ofPDDocumentgetPdfAnnotations(int page) Retrieves all annotations found in the documentfloatReturns version of the PDF document defined in the document's header.org.apache.pdfbox.pdmodel.PDPagegetPDPage(int page) Returns aPDPagefloatReturns version of the PDF document.booleanThis method checks whether the document is encryptedbooleanThis method verifies if the document has been opened with a full owner access (all modifications are permitted)booleanisSignatureCoversWholeDocument(PdfSignatureDictionary signatureDictionary) Checks if a signature for the given PDF Signature Dictionary covers the whole documentbooleanThis method verifies whether a PDF contains a usage rights signaturevoidsetVersion(float version) Sets PDF version number, by upgrading /Catalog dictionary /Version parameter
-
Constructor Details
-
PdfBoxDocumentReader
Default constructor of the PDFBox implementation of the Reader- Parameters:
dssDocument-DSSDocumentto read- Throws:
IOException- if an exception occursInvalidPasswordException- if the password is not provided or invalid for a protected document
-
PdfBoxDocumentReader
public PdfBoxDocumentReader(DSSDocument dssDocument, String passwordProtection) throws IOException, InvalidPasswordException The PDFBox implementation of the Reader- Parameters:
dssDocument-DSSDocumentto readpasswordProtection-Stringa password to open a protected document- Throws:
IOException- if an exception occursInvalidPasswordException- if the password is not provided or invalid for a protected document
-
PdfBoxDocumentReader
public PdfBoxDocumentReader(byte[] binaries, String passwordProtection) throws IOException, InvalidPasswordException The PDFBox implementation of the Reader- Parameters:
binaries- a byte array of a PDF to readpasswordProtection-Stringa password to open a protected document- Throws:
IOException- if an exception occursInvalidPasswordException- if the password is not provided or invalid for a protected document
-
PdfBoxDocumentReader
public PdfBoxDocumentReader(org.apache.pdfbox.pdmodel.PDDocument pdDocument) The constructor to directly instantiate thePdfBoxDocumentReader- Parameters:
pdDocument-PDDocument
-
-
Method Details
-
getPDDocument
public org.apache.pdfbox.pdmodel.PDDocument getPDDocument()Returns the current instance ofPDDocument- Returns:
PDDocument
-
getDSSDictionary
Description copied from interface:PdfDocumentReaderLoads the last DSS dictionary from the document if exists NOTE: can return null if DSS dictionary is not present- Specified by:
getDSSDictionaryin interfacePdfDocumentReader- Returns:
PdfDssDict
-
extractSigDictionaries
public Map<PdfSignatureDictionary,List<PdfSignatureField>> extractSigDictionaries() throws IOExceptionDescription copied from interface:PdfDocumentReaderExtracts PdfSignatureDictionaries present in the signature- Specified by:
extractSigDictionariesin interfacePdfDocumentReader- Returns:
- a map between
PdfSignatureDictionaryand relatedPdfSignatureFields - Throws:
IOException- if an exception occurs
-
isSignatureCoversWholeDocument
Description copied from interface:PdfDocumentReaderChecks if a signature for the given PDF Signature Dictionary covers the whole document- Specified by:
isSignatureCoversWholeDocumentin interfacePdfDocumentReader- Parameters:
signatureDictionary-PdfSignatureDictionaryto check the result for- Returns:
- TRUE if the signature covers the whole document, false otherwise
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getNumberOfPages
public int getNumberOfPages()Description copied from interface:PdfDocumentReaderReturns an amount of pages found in the document- Specified by:
getNumberOfPagesin interfacePdfDocumentReader- Returns:
- number of pages
-
getPageBox
Description copied from interface:PdfDocumentReaderReturns a page box dimensions- Specified by:
getPageBoxin interfacePdfDocumentReader- Parameters:
page- number of a page to get annotation box of- Returns:
AnnotationBoxrepresenting page dimensions
-
getPageRotation
public int getPageRotation(int page) Description copied from interface:PdfDocumentReaderThis method returns a corresponding page's rotation within the document- Specified by:
getPageRotationin interfacePdfDocumentReader- Parameters:
page- number of a page to get rotation of- Returns:
- rotation degrees
-
getPdfAnnotations
Description copied from interface:PdfDocumentReaderRetrieves all annotations found in the document- Specified by:
getPdfAnnotationsin interfacePdfDocumentReader- Parameters:
page- number- Returns:
- a list of
PdfAnnotations associated with the given page - Throws:
IOException- if an exception occurs
-
getPDPage
public org.apache.pdfbox.pdmodel.PDPage getPDPage(int page) Returns aPDPage- Parameters:
page- number- Returns:
PDPage
-
generateImageScreenshot
Description copied from interface:PdfDocumentReaderGenerates the image screenshot for the given page of the PDF- Specified by:
generateImageScreenshotin interfacePdfDocumentReader- Parameters:
page- number to be generated- Returns:
BufferedImagescreenshot for the given page- Throws:
IOException- if an exception occurs
-
generateImageScreenshotWithoutAnnotations
public BufferedImage generateImageScreenshotWithoutAnnotations(int page, List<PdfAnnotation> annotations) throws IOException Description copied from interface:PdfDocumentReaderGenerates the image screenshot by hiding the given list ofannotationBoxes- Specified by:
generateImageScreenshotWithoutAnnotationsin interfacePdfDocumentReader- Parameters:
page- number to be generatedannotations- a list ofPdfAnnotations to be hidden- Returns:
BufferedImagescreenshot for the given page- Throws:
IOException- if an exception occurs
-
isEncrypted
public boolean isEncrypted()Description copied from interface:PdfDocumentReaderThis method checks whether the document is encrypted- Specified by:
isEncryptedin interfacePdfDocumentReader- Returns:
- TRUE if the document is encrypted, FALSE otherwise
-
isOpenWithOwnerAccess
public boolean isOpenWithOwnerAccess()Description copied from interface:PdfDocumentReaderThis method verifies if the document has been opened with a full owner access (all modifications are permitted)- Specified by:
isOpenWithOwnerAccessin interfacePdfDocumentReader- Returns:
- TRUE if the document has been open with a full access, FALSE otherwise
-
canFillSignatureForm
public boolean canFillSignatureForm()Description copied from interface:PdfDocumentReaderThis method verifies whether fill-in of existing signature fields is allowed by PDF document permissions dictionary- Specified by:
canFillSignatureFormin interfacePdfDocumentReader- Returns:
- TRUE if fill-in signature forms is permitted, FALSE otherwise
-
canCreateSignatureField
public boolean canCreateSignatureField()Description copied from interface:PdfDocumentReaderThis method verifies whether creation of new signature fields is allowed by the PDF permissions dictionary- Specified by:
canCreateSignatureFieldin interfacePdfDocumentReader- Returns:
- TRUE if the new signature field creation is permitted, FALSE otherwise
-
getCertificationPermission
Description copied from interface:PdfDocumentReaderReturns value of /DocMDP dictionary defining the permitted modification in a PDF, when present- Specified by:
getCertificationPermissionin interfacePdfDocumentReader- Returns:
CertificationPermission
-
isUsageRightsSignaturePresent
public boolean isUsageRightsSignaturePresent()Description copied from interface:PdfDocumentReaderThis method verifies whether a PDF contains a usage rights signature- Specified by:
isUsageRightsSignaturePresentin interfacePdfDocumentReader- Returns:
- TRUE of a PDF contains a usage rights signature, FALSE otherwise
-
getCatalogDictionary
Description copied from interface:PdfDocumentReaderReturns a document catalog as a dictionary- Specified by:
getCatalogDictionaryin interfacePdfDocumentReader- Returns:
PdfDict
-
generateDocumentId
Computes a DocumentId in a deterministic way based on the givenparametersand the document- Parameters:
parameters-PAdESCommonParameters- Returns:
- deterministic identifier
-
getPdfHeaderVersion
public float getPdfHeaderVersion()Description copied from interface:PdfDocumentReaderReturns version of the PDF document defined in the document's header.- Specified by:
getPdfHeaderVersionin interfacePdfDocumentReader- Returns:
- document version from file's header
-
getVersion
public float getVersion()Description copied from interface:PdfDocumentReaderReturns version of the PDF document. Returns version defined in the file header, or catalog's /Version, when latest is present.- Specified by:
getVersionin interfacePdfDocumentReader- Returns:
- document version
-
setVersion
public void setVersion(float version) Description copied from interface:PdfDocumentReaderSets PDF version number, by upgrading /Catalog dictionary /Version parameter- Specified by:
setVersionin interfacePdfDocumentReader- Parameters:
version- value (e.g. 1.7)
-
createPdfDict
Description copied from interface:PdfDocumentReaderCreates an emptyPdfDict- Specified by:
createPdfDictin interfacePdfDocumentReader- Returns:
PdfDict
-
createPdfArray
Description copied from interface:PdfDocumentReaderCreates an emptyPdfArray- Specified by:
createPdfArrayin interfacePdfDocumentReader- Returns:
PdfArray
-