From ba0bfe16e391c13d67a34ea216e9b40ea0751c04 Mon Sep 17 00:00:00 2001 From: emusic Date: Tue, 19 Nov 2019 17:08:32 +0100 Subject: SignatureFieldsExtractor added --- .../placeholder/SignatureFieldsExtractor.java | 33 ++++++++++++++++++++++ .../impl/signing/pdfbox2/PADESPDFBOXSigner.java | 22 +-------------- 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignatureFieldsExtractor.java (limited to 'pdf-as-pdfbox-2/src/main') 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 findEmptySignatureFields(PDDocument doc) + { + PDSignature signature; + List signatureField; + List 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 findEmptySignatureFields(PDDocument doc) - { - PDSignature signature; - List signatureField; - List 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 -- cgit v1.2.3