From 10b659782e65a4c337f591acb1210f547a58a298 Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Mon, 12 Jul 2021 13:10:13 +0200 Subject: v4.2.0-pdfOver API for PDF-OVER issue #52 --- .../placeholder/SignatureFieldsExtractor.java | 39 ++++++++++++++++++++++ .../placeholder/SignaturePlaceholderExtractor.java | 9 ----- 2 files changed, 39 insertions(+), 9 deletions(-) (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 index a8473858..0ccce1f8 100644 --- 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 @@ -1,5 +1,7 @@ package at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder; +import at.gv.egiz.pdfas.lib.impl.placeholder.PlaceholderExtractorConstants; +import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -30,4 +32,41 @@ public class SignatureFieldsExtractor { } return signatureFieldNames; } + /* + Needed by PDF-OVER + */ + public static SignaturePlaceholderData getNextSignaturePlaceHolder(PDDocument doc) { + try { + SignaturePlaceholderExtractor signaturePlaceholderExtractor = new SignaturePlaceholderExtractor("1", + PlaceholderExtractorConstants.PLACEHOLDER_MATCH_MODE_SORTED, doc); + return signaturePlaceholderExtractor.extract(doc, "1", + PlaceholderExtractorConstants.PLACEHOLDER_MATCH_MODE_SORTED); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static SignaturePlaceholderData getSignaturePlaceHolder(PDDocument doc, String placeholderId, + int mode) { + try { + SignaturePlaceholderExtractor signaturePlaceholderExtractor = new SignaturePlaceholderExtractor( placeholderId, + mode, doc); + return signaturePlaceholderExtractor.extract(doc, placeholderId, mode); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static List getSignaturePlaceHolderList(PDDocument doc, String placeholderId, int mode) { + try { + SignaturePlaceholderExtractor signaturePlaceholderExtractor = new SignaturePlaceholderExtractor( placeholderId, + mode, doc); + return signaturePlaceholderExtractor.extractList(doc, placeholderId, mode); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } } 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 4031d07f..71eef856 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 @@ -194,14 +194,6 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl public List extractList(PDDocument doc, String placeholderId, int matchMode) throws PdfAsException { SignaturePlaceholderContext.setSignaturePlaceholderData(null); -// List placeholders = new ArrayList<>(); -// SignaturePlaceholderExtractor extractor; -// try { -// extractor = new SignaturePlaceholderExtractor(placeholderId, -// matchMode, doc); -// } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e2) { -// throw new PDFIOException("error.pdf.io.04", e2); -// } int pageNr = 0; for(PDPage page : doc.getPages()){ @@ -236,7 +228,6 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl if (matchMode == PLACEHOLDER_MATCH_MODE_STRICT) { throw new PlaceholderExtractionException("error.pdf.stamp.09"); } - return null; } -- cgit v1.2.3