From c168a1f30d39eddec8cdcdfbe9700e83a8b67746 Mon Sep 17 00:00:00 2001 From: Emina Ahmetovic Date: Fri, 5 Feb 2021 14:32:37 +0100 Subject: fix placeholder overwritting issue --- .../impl/signing/pdfbox2/PADESPDFBOXSigner.java | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas') 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 eec9b6c1..0a32d7a5 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 @@ -108,6 +108,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { PDFAsVisualSignatureProperties properties = null; List placeholders; + List availablePlaceholders; + SignaturePlaceholderData signaturePlaceholderData = null; + String placeholder_id = ""; if(PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID) != null && !PlaceholderWebConfiguration.getValue(PLACEHOLDER_WEB_ID).equalsIgnoreCase("")){ @@ -157,6 +160,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { SignaturePlaceholderData signaturePlaceholderDataInit = PlaceholderFilter.checkPlaceholderSignatureLocation(pdfObject.getStatus(), pdfObject.getStatus().getSettings(), placeholder_id); placeholders = SignaturePlaceholderExtractor.getPlaceholders(); + availablePlaceholders = listAvailablePlaceholders(placeholders, existingSignatureLocations(doc)); + if(placeholder_id.equalsIgnoreCase("")){ if(checkAvailablePlaceholders(placeholders,existingSignatureLocations(doc))!=null) @@ -165,8 +170,13 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { }; } - SignaturePlaceholderData signaturePlaceholderData = PlaceholderFilter - .checkPlaceholderSignatureLocation(pdfObject.getStatus(), pdfObject.getStatus().getSettings(),placeholder_id); + if(availablePlaceholders!=null) { + signaturePlaceholderData = PlaceholderFilter + .checkPlaceholderSignatureLocation(pdfObject.getStatus(), pdfObject.getStatus().getSettings(),placeholder_id); + } + + + TablePos tablePos = null; @@ -643,6 +653,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { if (doc != null) { try { doc.close(); + SignaturePlaceholderExtractor.getPlaceholders().clear(); } catch (IOException e) { logger.debug("Failed to close COS Doc!", e); // Ignore @@ -921,4 +932,20 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } return result; } + + + //find first placeholder_id + public List listAvailablePlaceholders(List placeholders, List existingPlaceholders) { + List result = null; + + if(placeholders!=null) { + for(int i = 0; i < placeholders.size(); ++i) { + //take smallest id + if(!existingPlaceholders.contains(placeholders.get(i).getPlaceholderName())) { + result.add(placeholders.get(i)); + } + } + } + return result; + } } \ No newline at end of file -- cgit v1.2.3