From aa99f5b7512a5019b71616f9589a7a5bbfc403da Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Mon, 15 Feb 2016 13:55:12 +0100 Subject: placeholder sorted mode --- .../placeholder/SignaturePlaceholderExtractor.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'pdf-as-pdfbox/src/main/java/at/gv/egiz') diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java index db16d212..54922864 100644 --- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java @@ -192,6 +192,38 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl if (placeholders.size() == 0) return null; + if (matchMode == PLACEHOLDER_MATCH_MODE_SORTED) { + // sort all placeholders by the id string if all ids are null do nothing + SignaturePlaceholderData currentFirstSpd = null; + for (int i = 0; i < placeholders.size(); i++) { + SignaturePlaceholderData spd = placeholders.get(i); + if (spd.getId() != null) { + if(currentFirstSpd == null) { + currentFirstSpd = spd; + logger.debug("Setting new current ID: {}", + currentFirstSpd.getId()); + } else { + String currentID = currentFirstSpd.getId(); + String testID = spd.getId(); + logger.debug("Testing placeholder current: {} compare to {}", + currentID, testID); + if(testID.compareToIgnoreCase(currentID) < 0) { + currentFirstSpd = spd; + logger.debug("Setting new current ID: {}", + testID); + } + } + } + } + + if(currentFirstSpd != null) { + logger.info("Running Placeholder sorted mode: using id: {}", currentFirstSpd.getId()); + return currentFirstSpd; + } else { + logger.info("Running Placeholder sorted mode: no placeholder with id found, fallback to first placeholder"); + } + } + for (int i = 0; i < placeholders.size(); i++) { SignaturePlaceholderData spd = placeholders.get(i); if (spd.getId() == null) @@ -207,6 +239,10 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl private static SignaturePlaceholderData matchPlaceholderPage( List placeholders, String placeholderId, int matchMode) { + + if(matchMode == PLACEHOLDER_MATCH_MODE_SORTED) + return null; + if (placeholders.size() == 0) return null; for (int i = 0; i < placeholders.size(); i++) { -- cgit v1.2.3