diff options
author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-07-22 13:21:06 +0200 |
---|---|---|
committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-07-22 16:20:35 +0200 |
commit | 980eed2c3ffe3784747abd5dc6a6fdebbbe2caff (patch) | |
tree | 785fa406ee89957e04234e6ebe3b8d88088d7bd4 /pdf-as-pdfbox-2/src/main/java/at/gv | |
parent | e1f63b5fa88dfa2a5ca3fe91d8b065753ce63a68 (diff) | |
download | pdf-as-4-980eed2c3ffe3784747abd5dc6a6fdebbbe2caff.tar.gz pdf-as-4-980eed2c3ffe3784747abd5dc6a6fdebbbe2caff.tar.bz2 pdf-as-4-980eed2c3ffe3784747abd5dc6a6fdebbbe2caff.zip |
added getNextUnusedSignaturePlaceHolder => pdf over needs next unused placeholder issue #54
Diffstat (limited to 'pdf-as-pdfbox-2/src/main/java/at/gv')
3 files changed, 37 insertions, 11 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsAndPlaceHolderExtractor.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsAndPlaceHolderExtractor.java index ca620aec..63552c2a 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsAndPlaceHolderExtractor.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsAndPlaceHolderExtractor.java @@ -8,6 +8,7 @@ import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDField; import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -35,12 +36,27 @@ public class SignatureFieldsAndPlaceHolderExtractor { /* Needed by PDF-OVER */ - public static SignaturePlaceholderData getNextSignaturePlaceHolder(PDDocument doc) { + + /** + * Returns the next unused signature placeholder + * @param doc The document to be searched for signature placeholders + * @return The next unused signature placeholder or null in case there is none + */ + public static SignaturePlaceholderData getNextUnusedSignaturePlaceHolder(PDDocument doc) { try { - SignaturePlaceholderExtractor signaturePlaceholderExtractor = new SignaturePlaceholderExtractor("1", - PlaceholderExtractorConstants.PLACEHOLDER_MATCH_MODE_SORTED, doc); - return signaturePlaceholderExtractor.extract(doc, "1", - PlaceholderExtractorConstants.PLACEHOLDER_MATCH_MODE_SORTED); + String placeholderId = "1"; + int mode = PlaceholderExtractorConstants.PLACEHOLDER_MATCH_MODE_SORTED; + SignaturePlaceholderExtractor signaturePlaceholderExtractor = new SignaturePlaceholderExtractor( placeholderId, + mode, doc); + List<SignaturePlaceholderData> results = signaturePlaceholderExtractor.extractList(doc, placeholderId, + mode); + List<String> used = getExistingSignatureLocations(doc); + //return first not used + for(SignaturePlaceholderData result : results) { + if(!used.contains(result.getPlaceholderName())) + return result; + } + return null; } catch (Exception e) { e.printStackTrace(); return null; @@ -69,4 +85,19 @@ public class SignatureFieldsAndPlaceHolderExtractor { return null; } } + + public static List<String> getExistingSignatureLocations(PDDocument doc) { + List<String> existingLocations = new ArrayList<>(); + try { + List <PDSignature> pdSignatureList = doc.getSignatureDictionaries(); + if(pdSignatureList.size() != 0) { + for(PDSignature sig : pdSignatureList) { + existingLocations.add(sig.getLocation()); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return existingLocations; + } } 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 71eef856..6df4f0b1 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 @@ -126,11 +126,6 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl this.doc = doc; } -// public static List<SignaturePlaceholderData> getPlaceholders() { -// return placeholders; -// } - - /** * Search the document for placeholder images and possibly included * additional info.<br/> 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 3cf0853f..3e1b7d9a 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 @@ -162,7 +162,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { signature.setFilter(COSName.getPDFName(signer.getPDFFilter())); signature.setSubFilter(COSName.getPDFName(signer.getPDFSubFilter())); // SignaturePlaceholderData signaturePlaceholderDataInit = - placeholders =PlaceholderFilter.checkPlaceholderSignatureLocationList(pdfObject.getStatus(), + placeholders = PlaceholderFilter.checkPlaceholderSignatureLocationList(pdfObject.getStatus(), pdfObject.getStatus().getSettings(), placeholder_id); // placeholders = SignaturePlaceholderExtractor.getPlaceholders(); |