aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox
diff options
context:
space:
mode:
authorThomas <>2023-06-26 21:11:26 +0200
committerThomas <>2023-06-26 21:11:26 +0200
commit8e0ccca7cfd1680e33737e0db8d6e1091661568c (patch)
tree33ae7a462976eecbda355921706412a1ff60131a /pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox
parent203eaa42d83da699ed9cc6c7e286906b5aeb6d44 (diff)
downloadpdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.tar.gz
pdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.tar.bz2
pdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.zip
refact(placeholder): clean-up, bugfix and optimize QR-Code placeholder detection
Major re-factoring of QR-Code detection with huge clean-up of code.
Diffstat (limited to 'pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox')
-rw-r--r--pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/PDFBoxPlaceholderExtractorTest.java51
-rw-r--r--pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java21
2 files changed, 66 insertions, 6 deletions
diff --git a/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/PDFBoxPlaceholderExtractorTest.java b/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/PDFBoxPlaceholderExtractorTest.java
new file mode 100644
index 00000000..fbe3cdea
--- /dev/null
+++ b/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/PDFBoxPlaceholderExtractorTest.java
@@ -0,0 +1,51 @@
+package at.gv.egiz.pdfas.lib.testpdfbox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Test;
+
+import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsAndPlaceHolderExtractor;
+import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
+import lombok.SneakyThrows;
+
+public class PDFBoxPlaceholderExtractorTest {
+
+ @Test
+ @SneakyThrows
+ public void nextPlaceholder() {
+ SignaturePlaceholderData result = getNextSignaturePlaceHolder("/data/platzhalter_en_de_test.pdf");
+ assertEquals("Im48", result.getPlaceholderName());
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void allPlaceHolders() {
+ List<String> listOfPlaceHolders = getPlaceHolders("/data/platzhalter_en_de_test.pdf");
+ assertNotNull(listOfPlaceHolders);
+
+ }
+
+ private static List<String> getPlaceHolders(String filePath) throws IOException {
+ final PDDocument doc = PDDocument.load(PDFBoxPlaceholderExtractorTest.class.getResourceAsStream(
+ filePath));
+ final List<String> results = SignatureFieldsAndPlaceHolderExtractor.findEmptySignatureFields(doc);
+ return results;
+
+ }
+
+ private static SignaturePlaceholderData getNextSignaturePlaceHolder(String filePath) throws IOException {
+ final PDDocument doc = PDDocument.load(PDFBoxPlaceholderExtractorTest.class.getResourceAsStream(
+ filePath));
+ final SignaturePlaceholderData result =
+ SignatureFieldsAndPlaceHolderExtractor.getNextUnusedSignaturePlaceHolder(doc);
+ return result;
+
+ }
+
+}
diff --git a/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java b/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java
index 0d85c82b..61a1199d 100644
--- a/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java
+++ b/pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java
@@ -1,16 +1,17 @@
package at.gv.egiz.pdfas.lib.testpdfbox;
-import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsAndPlaceHolderExtractor;
-import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.junit.Assert;
-import org.junit.Test;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Assert;
+import org.junit.Test;
+
+import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsAndPlaceHolderExtractor;
+import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
+
public class SignatureFieldsAndPlaceHolderExtractorTest {
public String getPath(String resourceName) {
@@ -48,6 +49,14 @@ public class SignatureFieldsAndPlaceHolderExtractorTest {
SignaturePlaceholderData result = getNextSignaturePlaceHolder(getPath("manySignFields.pdf"));
Assert.assertEquals(null,result);
}
+
+ @Test
+ public void firstQrCodeOnUnsignedDoc() {
+ SignaturePlaceholderData result = getNextSignaturePlaceHolder(getPath("new_qr_2-2.pdf"));
+ Assert.assertEquals("Image5",result.getPlaceholderName());
+
+ }
+
@Test
public void subsequentCalls(){
SignaturePlaceholderData result = getNextSignaturePlaceHolder(getPath("new_qr_2_signed_signed_signed.pdf"));