diff options
author | emusic <emina.music@egiz.gv.at> | 2019-11-19 17:08:32 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2019-11-19 17:08:32 +0100 |
commit | ba0bfe16e391c13d67a34ea216e9b40ea0751c04 (patch) | |
tree | 359c497a015a3ac2340eef666d95699954193a49 /pdf-as-pdfbox-2/src/main/java/at/gv | |
parent | ba44d7d68696e76b86a82e51ecc02b1f2a3d9aa9 (diff) | |
download | pdf-as-4-ba0bfe16e391c13d67a34ea216e9b40ea0751c04.tar.gz pdf-as-4-ba0bfe16e391c13d67a34ea216e9b40ea0751c04.tar.bz2 pdf-as-4-ba0bfe16e391c13d67a34ea216e9b40ea0751c04.zip |
SignatureFieldsExtractor added
Diffstat (limited to 'pdf-as-pdfbox-2/src/main/java/at/gv')
2 files changed, 34 insertions, 21 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsExtractor.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsExtractor.java new file mode 100644 index 00000000..a8473858 --- /dev/null +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsExtractor.java @@ -0,0 +1,33 @@ +package at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; +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.util.ArrayList; +import java.util.List; + +public class SignatureFieldsExtractor { + + //Search for empty signature fields + public static List<String> findEmptySignatureFields(PDDocument doc) + { + PDSignature signature; + List<PDField> signatureField; + List<String> signatureFieldNames = new ArrayList<>(); + PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(); + if (acroForm != null) { + signatureField = acroForm.getFields(); + for (PDField pdField : signatureField) { + if(pdField instanceof PDSignatureField && pdField.getPartialName()!=null) + { + signature = ((PDSignatureField) pdField).getSignature(); + if(signature == null) signatureFieldNames.add(pdField.getPartialName()); + } + } + } + return signatureFieldNames; + } +} 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 ccf99902..c37002c4 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 @@ -35,6 +35,7 @@ import at.gv.egiz.pdfas.lib.impl.ErrorExtractor; import at.gv.egiz.pdfas.lib.impl.SignaturePositionImpl; import at.gv.egiz.pdfas.lib.impl.configuration.SignatureProfileConfiguration; import at.gv.egiz.pdfas.lib.impl.pdfbox2.PDFBOXObject; +import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsExtractor; import at.gv.egiz.pdfas.lib.impl.pdfbox2.positioning.Positioning; import at.gv.egiz.pdfas.lib.impl.pdfbox2.utils.PdfBoxUtils; import at.gv.egiz.pdfas.lib.impl.placeholder.PlaceholderFilter; @@ -872,7 +873,6 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // Find an existing signature. private PDSignature findExistingSignature(PDDocument doc, String sigFieldName) { - findEmptySignatureFields(doc); PDSignature signature = null; PDSignatureField signatureField; PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(); @@ -899,24 +899,4 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } return signature; } - - //Find empty signature fields - private List<String> findEmptySignatureFields(PDDocument doc) - { - PDSignature signature; - List<PDField> signatureField; - List<String> signatureFieldNames = new ArrayList<>(); - PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm(); - if (acroForm != null) { - signatureField = acroForm.getFields(); - for (PDField pdField : signatureField) { - if(pdField instanceof PDSignatureField && pdField.getPartialName()!=null) - { - signature = ((PDSignatureField) pdField).getSignature(); - if(signature == null) signatureFieldNames.add(pdField.getPartialName()); - } - } - } - return signatureFieldNames; - } }
\ No newline at end of file |