Package eu.europa.esig.dss.pdf.pdfbox
Class PdfBoxSignatureService
java.lang.Object
eu.europa.esig.dss.pdf.AbstractPDFSignatureService
eu.europa.esig.dss.pdf.pdfbox.PdfBoxSignatureService
- All Implemented Interfaces:
PDFSignatureService
Implementation of PDFSignatureService using PDFBox
-
Field Summary
Fields inherited from class eu.europa.esig.dss.pdf.AbstractPDFSignatureService
pdfDifferencesFinder, pdfObjectModificationsFinder, resourcesHandlerBuilder -
Constructor Summary
ConstructorsConstructorDescriptionPdfBoxSignatureService(PDFServiceMode serviceMode, PdfBoxSignatureDrawerFactory signatureDrawerFactory) Constructor for the PdfBoxSignatureService -
Method Summary
Modifier and TypeMethodDescriptionaddDssDictionary(DSSDocument document, PdfValidationDataContainer validationDataForInclusion, String pwd) This method adds the DSS dictionary (Baseline-LT) to a password-protected documentaddNewSignatureField(DSSDocument document, SignatureFieldParameters parameters, String pwd) This method allows to add a new signature field to an existing encrypted pdf documentvoidcheckEncryptedAndSaveIncrementally(org.apache.pdfbox.pdmodel.PDDocument pdDocument, OutputStream outputStream, PAdESCommonParameters parameters) Checks if the document is encrypted and saves incrementally tooutputStreamprotected byte[]computeDigest(DSSDocument toSignDocument, PAdESCommonParameters parameters) Computes digest on to be signed data computed on thetoSignDocumentrespectively to the givenparametersprotected org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignaturecreateSignatureDictionary(org.apache.pdfbox.pdmodel.PDDocument pdDocument, PAdESCommonParameters parameters) Creates a new signature dictionary Note for developers: keep protected! See PR #138getAvailableSignatureFields(DSSDocument document, String pwd) Returns not-signed signature fields from an encrypted documentprotected PdfDocumentReaderloadPdfDocumentReader(byte[] binaries, String passwordProtection) LoadsPdfDocumentReaderinstanceprotected PdfDocumentReaderloadPdfDocumentReader(DSSDocument dssDocument, String passwordProtection) LoadsPdfDocumentReaderinstancepreviewPageWithVisualSignature(DSSDocument toSignDocument, PAdESCommonParameters parameters) Returns a page preview with the visual signaturepreviewSignatureField(DSSDocument toSignDocument, PAdESCommonParameters parameters) Returns a preview of the signature fieldvoidsaveDocumentIncrementally(org.apache.pdfbox.pdmodel.PDDocument pdDocument, OutputStream outputStream) Saves the document incrementallyprotected voidsetMDPPermission(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.voidsetSecureRandomProvider(SecureRandomProvider secureRandomProvider) Set theSecureRandomProvider.protected DSSDocumentsignDocument(DSSDocument toSignDocument, byte[] cmsSignedData, PAdESCommonParameters parameters) This method creates a signed document from the originaltoSignDocument, incorporating a new revision, enveloping the providedcmsSignedDataMethods inherited from class eu.europa.esig.dss.pdf.AbstractPDFSignatureService
addDssDictionary, addNewSignatureField, analyzePdfModifications, buildSignatureFieldBox, checkDocumentPermissions, checkNewSignatureIsPermitted, checkSignatureFieldAgainstPageDimensions, checkSignatureFieldBoxOverlap, digest, extractBeforeSignatureValue, getAvailableSignatureFields, getRevisions, getSignatureValue, getType, getVisibleSignatureFieldBoxPosition, getVisibleSignatureFieldBoxPosition, getVisualDifferences, instantiateResourcesHandler, isContentValueEqualsByteRangeExtraction, isDocTimestamp, isDocumentTimestampLayer, isSignature, loadSignatureDrawer, setAlertOnForbiddenSignatureCreation, setAlertOnSignatureFieldOutsidePageDimensions, setAlertOnSignatureFieldOverlap, setMaximalPagesAmountForVisualComparison, setPdfDifferencesFinder, setPdfObjectModificationsFinder, setResourcesHandlerBuilder, sign, toPdfPageCoordinates
-
Constructor Details
-
PdfBoxSignatureService
public PdfBoxSignatureService(PDFServiceMode serviceMode, PdfBoxSignatureDrawerFactory signatureDrawerFactory) Constructor for the PdfBoxSignatureService- Parameters:
serviceMode- current instance is used to generate DocumentTimestamp or Signature signature layersignatureDrawerFactory- drawer factory implementation to be used
-
-
Method Details
-
setSecureRandomProvider
Set theSecureRandomProvider. Allows modifying a custom behavior for signing of encrypted documents.- Parameters:
secureRandomProvider-SecureRandomProvider
-
computeDigest
Description copied from class:AbstractPDFSignatureServiceComputes digest on to be signed data computed on thetoSignDocumentrespectively to the givenparameters- Specified by:
computeDigestin classAbstractPDFSignatureService- Parameters:
toSignDocument-DSSDocumentto be signedparameters-PAdESCommonParameters- Returns:
- byte array
-
signDocument
protected DSSDocument signDocument(DSSDocument toSignDocument, byte[] cmsSignedData, PAdESCommonParameters parameters) Description copied from class:AbstractPDFSignatureServiceThis method creates a signed document from the originaltoSignDocument, incorporating a new revision, enveloping the providedcmsSignedData- Specified by:
signDocumentin classAbstractPDFSignatureService- Parameters:
toSignDocument-DSSDocumentto be signedcmsSignedData- byte array representing the encoded CMS signed data's binariesparameters-PAdESCommonParameters- 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 PR #138- Parameters:
pdDocument-PDDocumentparameters-PAdESCommonParameters- Returns:
PDSignature
-
setMDPPermission
protected 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 tooutputStream- Parameters:
pdDocument-PDDocumentto check and saveoutputStream-OutputStreamto save the content toparameters-PAdESCommonParameters
-
saveDocumentIncrementally
public void saveDocumentIncrementally(org.apache.pdfbox.pdmodel.PDDocument pdDocument, OutputStream outputStream) Saves the document incrementally- Parameters:
pdDocument-PDDocumentto saveoutputStream-OutputStreamto save incremental update to
-
addDssDictionary
public DSSDocument addDssDictionary(DSSDocument document, PdfValidationDataContainer validationDataForInclusion, String pwd) Description copied from interface:PDFSignatureServiceThis method adds the DSS dictionary (Baseline-LT) to a password-protected document- Parameters:
document- the document to be extendedvalidationDataForInclusion-PdfValidationDataContainerpwd- the password protection used to create the encrypted document (optional)- Returns:
- the pdf document with the added dss dictionary
-
getAvailableSignatureFields
Description copied from interface:PDFSignatureServiceReturns not-signed signature fields from an encrypted document- Parameters:
document- the pdf documentpwd- 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:PDFSignatureServiceThis method allows to add a new signature field to an existing encrypted pdf document- Parameters:
document- the pdf documentparameters- the parameters with the coordinates,... of the signature fieldpwd- the password protection used to create the encrypted document (optional)- Returns:
- the pdf document with the new added signature field
-
previewPageWithVisualSignature
public DSSDocument previewPageWithVisualSignature(DSSDocument toSignDocument, PAdESCommonParameters parameters) Description copied from interface:PDFSignatureServiceReturns a page preview with the visual signature- Parameters:
toSignDocument- the document to be signedparameters- the signature/timestamp parameters- Returns:
- a DSSDocument with the PNG picture
-
previewSignatureField
public DSSDocument previewSignatureField(DSSDocument toSignDocument, PAdESCommonParameters parameters) Description copied from interface:PDFSignatureServiceReturns a preview of the signature field- Parameters:
toSignDocument- the document to be signedparameters- the signature/timestamp parameters- Returns:
- a DSSDocument with the PNG picture
-
loadPdfDocumentReader
protected PdfDocumentReader loadPdfDocumentReader(DSSDocument dssDocument, String passwordProtection) throws IOException, InvalidPasswordException Description copied from class:AbstractPDFSignatureServiceLoadsPdfDocumentReaderinstance- Specified by:
loadPdfDocumentReaderin classAbstractPDFSignatureService- Parameters:
dssDocument-DSSDocumentto readpasswordProtection-Stringthe password used to protect the document- Returns:
PdfDocumentReader- Throws:
IOException- in case of loading errorInvalidPasswordException- 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:AbstractPDFSignatureServiceLoadsPdfDocumentReaderinstance- Specified by:
loadPdfDocumentReaderin classAbstractPDFSignatureService- Parameters:
binaries- a byte arraypasswordProtection-Stringthe password used to protect the document- Returns:
PdfDocumentReader- Throws:
IOException- in case of loading errorInvalidPasswordException- if the password is not provided or invalid for a protected document
-