diff options
author | emusic <emina.music@egiz.gv.at> | 2019-12-16 16:30:47 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2019-12-16 16:30:47 +0100 |
commit | a2756cccaea16bd2f5b99eedc5b07699552a7537 (patch) | |
tree | b62a055bcbf1c19e3767fa01f6a0552c57e2b6d4 /pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2 | |
parent | ba0bfe16e391c13d67a34ea216e9b40ea0751c04 (diff) | |
download | pdf-as-4-a2756cccaea16bd2f5b99eedc5b07699552a7537.tar.gz pdf-as-4-a2756cccaea16bd2f5b99eedc5b07699552a7537.tar.bz2 pdf-as-4-a2756cccaea16bd2f5b99eedc5b07699552a7537.zip |
remove add new page functionality when signature already exists
Diffstat (limited to 'pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2')
-rw-r--r-- | pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java index c37002c4..c99bb608 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java @@ -132,6 +132,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { try { doc = pdfObject.getDocument(); + //if signature already exists dont create new page + List<PDSignatureField> pdSignatureFieldList = doc.getSignatureFields(); + SignaturePlaceholderData signaturePlaceholderData = PlaceholderFilter .checkPlaceholderSignature(pdfObject.getStatus(), pdfObject.getStatus().getSettings()); @@ -172,14 +175,12 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { String sigFieldName = pdfObject.getStatus().getSettings().getValue(SIGNATURE_FIELD_NAME); signature = findExistingSignature(doc, sigFieldName); //signature = findExistingSignature(doc, "ownerSignature"); - if (signature == null) - { + if (signature == null) { // create signature dictionary signature = new PDSignature(); } - else - { + else { isAdobeSigForm = true; } @@ -304,8 +305,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { logger.debug("Positioning: {}", positioningInstruction.toString()); - if(!isAdobeSigForm){ + if(!isAdobeSigForm) { if (positioningInstruction.isMakeNewPage()) { + int last = doc.getNumberOfPages() - 1; PDDocumentCatalog root = doc.getDocumentCatalog(); PDPage lastPage = root.getPages().get(last); @@ -318,12 +320,13 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // handle rotated page int targetPageNumber = positioningInstruction.getPage(); + logger.debug("Target Page: " + targetPageNumber); PDPage targetPage = doc.getPages().get(targetPageNumber - 1); int rot = targetPage.getRotation(); logger.debug("Page rotation: " + rot); // positioningInstruction.setRotation(positioningInstruction.getRotation() - // + rot); + // // + rot); logger.debug("resulting Sign rotation: " + positioningInstruction.getRotation()); SignaturePositionImpl position = new SignaturePositionImpl(); @@ -349,14 +352,10 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { */ if (signaturePlaceholderData != null) { - // Placeholder found! - // replace placeholder - InputStream fis = PADESPDFBOXSigner.class.getResourceAsStream("/placeholder/empty.jpg"); PDImageXObject img = JPEGFactory.createFromStream(doc, fis); - img.getCOSObject().setNeedToBeUpdated(true); // PDDocumentCatalog root = doc.getDocumentCatalog(); // PDPageNode rootPages = root.getPages(); @@ -414,12 +413,11 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { doc.addSignature(signature, signer, options); - //String sigFieldName = "ownerSignature"; - if (sigFieldName == null) { sigFieldName = "PDF-AS Signatur"; } + int count = PdfBoxUtils.countSignatures(doc, sigFieldName); sigFieldName = sigFieldName + count; @@ -434,7 +432,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // pdstRoot); //this is not used for Adobe signature fields - if(!isAdobeSigForm){ + if(!isAdobeSigForm) { PDSignatureField signatureField = null; if (acroFormm != null) { @SuppressWarnings("unchecked") @@ -474,7 +472,6 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } } - PDSignatureField signatureField = null; PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(); if (acroForm != null) { @@ -646,7 +643,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } catch (IOException e) { logger.warn(MessageResolver.resolveMessage("error.pdf.sig.01"), e); throw new PdfAsException("error.pdf.sig.01", e); - } finally { + } finally { if (doc != null) { try { doc.close(); @@ -708,7 +705,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { throw new PdfAsException("Failed validating PDF Document RuntimeException."); } finally { if (document != null) { - IOUtils.closeQuietly((Closeable) document); + IOUtils.closeQuietly(document); } } } @@ -752,11 +749,10 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert, int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError { try { - PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); + PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); PDDocument origDoc = new PDDocument(); - origDoc.addPage(new PDPage(PDRectangle.A4)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); origDoc.save(baos); @@ -779,7 +775,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID()); String signaturePosString = signatureProfileConfiguration.getDefaultPositioning(); - PositioningInstruction positioningInstruction = null; + PositioningInstruction positioningInstruction; if (signaturePosString != null) { positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", origDoc, visualObject, pdfObject.getStatus().getSettings()); @@ -886,9 +882,6 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { if (signature == null) { signature = new PDSignature(); - // after solving PDFBOX-3524 - // signatureField.setValue(signature) - // until then: signatureField.getCOSObject().setItem(COSName.V, signature); } else |