diff options
Diffstat (limited to 'pdf-as-pdfbox-2/src')
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 |