From a3bef06e6b3f2e465703aa8b64ab36f6e3d76de7 Mon Sep 17 00:00:00 2001 From: Emina Ahmetovic Date: Mon, 18 Jan 2021 16:07:28 +0100 Subject: update placeholder search --- .../placeholder/SignaturePlaceholderExtractor.java | 11 +++++++---- .../pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java | 15 +++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'pdf-as-pdfbox-2/src') diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java index 9043aae7..0998a2eb 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java @@ -106,8 +106,6 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl private static List placeholders = new ArrayList<>(); private int currentPage = 0; private PDDocument doc; - - private SignaturePlaceholderExtractor(String placeholderId, int placeholderMatchMode, PDDocument doc) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { @@ -128,13 +126,18 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl this.doc = doc; } - public static List listPlaceholders() { + public static List getPlaceholders() { return placeholders; } - public static void clearPlaceholders(){ + public void setPlaceholders(List placeholders) { + this.placeholders = placeholders; + } + + public static void clearPlaceholders() { placeholders.clear(); } + /** * Search the document for placeholder images and possibly included * additional info.
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 82c48d96..cff5fc7f 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 @@ -107,6 +107,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { PDFASSignatureInterface genericSigner) throws PdfAsException { PDFAsVisualSignatureProperties properties = null; + List placeholders; String placeholder_id = ""; if(PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID) != null && !PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID).equalsIgnoreCase("")){ @@ -155,11 +156,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { signature.setSubFilter(COSName.getPDFName(signer.getPDFSubFilter())); SignaturePlaceholderData signaturePlaceholderDataInit = PlaceholderFilter.checkPlaceholderSignatureLocation(pdfObject.getStatus(), pdfObject.getStatus().getSettings(), placeholder_id); - //gives a list of all placeholders - List placeholders = SignaturePlaceholderExtractor.listPlaceholders(); - if(placeholders!=null){ - SignaturePlaceholderExtractor.clearPlaceholders(); - } + placeholders = SignaturePlaceholderExtractor.getPlaceholders(); + + if(placeholder_id.equalsIgnoreCase("")){ if(checkAvailablePlaceholders(placeholders,existingSignatureLocations(doc))!=null) { @@ -177,7 +176,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { if (signaturePlaceholderData != null) { // Placeholder found! - logger.info("Placeholder data found."); + placeholders.clear(); + logger.info("Placeholder data found."); if (signaturePlaceholderData.getProfile() != null) { logger.debug("Placeholder Profile set to: " + signaturePlaceholderData.getProfile()); requestedSignature.setSignatureProfileID(signaturePlaceholderData.getProfile()); @@ -900,12 +900,15 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { //find first available placeholder public SignaturePlaceholderData checkAvailablePlaceholders(List placeholders, List existingPlaceholders) { SignaturePlaceholderData result = null; + + if(placeholders!=null){ for(int i = 0; i < placeholders.size(); ++i) { if(!existingPlaceholders.contains(placeholders.get(i).getPlaceholderName())) { result = placeholders.get(i); break; } } + } return result; } } \ No newline at end of file -- cgit v1.2.3