aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas <>2023-12-19 13:29:12 +0100
committerThomas <>2023-12-19 13:29:12 +0100
commit1bf5a6f022837a28a41778f68c1b278bd2462512 (patch)
treea5cd0aaef58aeb119f3f2b7d3a42dba85559b0b3
parente139d108925c6c5bdd8eaf6aab09f4275b7c2171 (diff)
parentf6d416f004ed294cff71e25358d7b37a9750a1b6 (diff)
downloadpdf-as-4-1bf5a6f022837a28a41778f68c1b278bd2462512.tar.gz
pdf-as-4-1bf5a6f022837a28a41778f68c1b278bd2462512.tar.bz2
pdf-as-4-1bf5a6f022837a28a41778f68c1b278bd2462512.zip
Merge branch 'feature/issue_68' into development
# Conflicts: # pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java # pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java
-rw-r--r--pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SigblockPreviewMain.java37
-rw-r--r--pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/SignatureBlockParameterTest.java (renamed from pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java)2
-rw-r--r--pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java15
-rw-r--r--pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsTemplateCreator.java49
-rw-r--r--pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsVisualSignatureProperties.java10
-rw-r--r--pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java3
6 files changed, 91 insertions, 25 deletions
diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SigblockPreviewMain.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SigblockPreviewMain.java
new file mode 100644
index 00000000..dba52463
--- /dev/null
+++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SigblockPreviewMain.java
@@ -0,0 +1,37 @@
+package at.gv.egiz.pdfas.cli.test;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+
+import javax.imageio.ImageIO;
+
+import at.gv.egiz.pdfas.lib.api.PdfAs;
+import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import iaik.x509.X509Certificate;
+import lombok.SneakyThrows;
+
+public class SigblockPreviewMain {
+
+ private static final String PDFAS_CONFIG_DIR = "/home/tlenz/Projekte/pdfas4/config/default_4.2.0/";
+
+
+ @SneakyThrows
+ public static void main(String[] args) throws Exception {
+ String cwd = System.getProperty("user.dir");
+ File output = new File(cwd + File.separator + "build/output.png");
+ X509Certificate cert = new X509Certificate(new FileInputStream("/home/tlenz/diverses/cert_debug/binding3.pem"));
+
+ PdfAs pdfas = PdfAsFactory.createPdfAs(new File(PDFAS_CONFIG_DIR));
+ SignParameter param = PdfAsFactory.createSignParameter(pdfas.getConfiguration(), null, null);
+ param.setSignatureProfileId("ERROR_LOGO");
+ //param.setSignatureProfileId("SIGNATURBLOCK_DE");
+
+
+ Image placeholder = pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4);
+ ImageIO.write((BufferedImage)placeholder, "png", output);
+ }
+
+}
diff --git a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/SignatureBlockParameterTest.java
index 23422e8e..378cc19d 100644
--- a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/SignatureBlockParameterTest.java
+++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/stamping/SignatureBlockParameterTest.java
@@ -1,4 +1,4 @@
-package at.gv.egiz.pdfas.lib.test.mains;
+package at.gv.egiz.pdfas.lib.test.stamping;
import at.gv.egiz.pdfas.common.settings.DefaultSignatureProfileSettings;
import at.gv.egiz.pdfas.common.utils.CheckSignatureBlockParameters;
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 ea139e87..36d7dade 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
@@ -252,7 +252,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
}
properties = new PDFAsVisualSignatureProperties(pdfObject.getStatus().getSettings(), pdfObject,
- (PdfBoxVisualObject) visualObject, positioningInstruction, signatureProfileSettings);
+ (PdfBoxVisualObject) visualObject, positioningInstruction, signatureProfileSettings, false);
properties.buildSignature();
if (signatureProfileSettings.isPDFA() || signatureProfileSettings.isPDFA3()) {
@@ -763,7 +763,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
positioningInstruction = Positioning.determineTablePositioning(new TablePos(), origDoc,
visualObject, pdfObject.getStatus().getSettings(), signatureProfileSettings);
}
-
+
origDoc.close();
final SignaturePositionImpl position = new SignaturePositionImpl();
@@ -777,15 +777,16 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
final PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject,
- positioningInstruction, signatureProfileSettings);
-
+ positioningInstruction, signatureProfileSettings, true);
+
+ // build visual-signature form
properties.buildSignature();
- PDDocument visualDoc;
+
+ PDDocument visualDoc;
synchronized (PDDocument.class) {
visualDoc = PDDocument.load(properties.getVisibleSignature());
}
-
final float stdRes = 72;
final float targetRes = resolution;
final float factor = targetRes / stdRes;
@@ -797,7 +798,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
visualDoc.close();
pdfRenderer = null;
-
+
final BufferedImage cutOut = new BufferedImage(
(int) (position.getWidth() * factor),
(int) (position.getHeight() * factor),
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsTemplateCreator.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsTemplateCreator.java
index b07e6ed5..62ad4dbf 100644
--- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsTemplateCreator.java
+++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsTemplateCreator.java
@@ -23,11 +23,11 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
-import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
-import at.gv.egiz.pdfas.lib.impl.stamping.TableFactory;
-import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
public class PDFAsTemplateCreator extends PDFTemplateCreator {
@@ -54,7 +55,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
}
- public InputStream buildPDF(PDFAsVisualSignatureDesigner properties, PDDocument originalDocument)
+ public InputStream buildPDF(PDFAsVisualSignatureDesigner properties, PDDocument originalDocument, boolean buildPreviewOnly)
throws IOException, PdfAsException {
logger.debug("pdf building has been started");
PDFTemplateStructure pdfStructure = pdfBuilder.getStructure();
@@ -80,7 +81,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
// create signature
this.pdfBuilder.createSignature(pdSignatureField, page, properties.getSignatureFieldName());
-
+
// that is /AcroForm/DR entry
this.pdfBuilder.createAcroFormDictionary(acroForm, pdSignatureField);
@@ -92,6 +93,8 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
this.pdfBuilder.createSignatureRectangle(pdSignatureField, properties, properties.getRotation() + properties.getPageRotation());
this.pdfBuilder.createFormaterRectangle(properties.getFormaterRectangleParams());
PDRectangle formater = pdfStructure.getFormatterRectangle();
+
+
//this.pdfBuilder.createSignatureImage(template, properties.getImageStream());
@@ -108,11 +111,13 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
// inner formstream, form and resource (hlder form containts inner form)
this.pdfBuilder.createInnerFormStreamPdfAs(template, originalDocument);
+
this.pdfBuilder.createInnerFormResource();
PDResources innerFormResource = pdfStructure.getInnerFormResources();
+
this.pdfBuilder.createInnerForm(innerFormResource, pdfStructure.getInnerFormStream(), formater);
PDFormXObject innerForm = pdfStructure.getInnerForm();
-
+
// inner form must be in the holder form as we wrote
this.pdfBuilder.insertInnerFormToHolerResources(innerForm, holderFormResources);
@@ -127,10 +132,10 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
// now inject procSetArray
/*this.pdfBuilder.injectProcSetArray(innerForm, page, innerFormResource, imageFormResources, holderFormResources,
pdfStructure.getProcSet());*/
+
this.pdfBuilder.injectProcSetArray(innerForm, page, innerFormResource, null, holderFormResources,
pdfStructure.getProcSet());
-
/*String imgFormName = pdfStructure.getImageFormName();
String imgName = pdfStructure.getImageName();*/
String innerFormName = pdfStructure.getInnerFormName().getName();
@@ -138,13 +143,16 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
// now create Streams of AP
/*this.pdfBuilder.injectAppearanceStreams(holderFormStream, imageFormStream, imageFormStream, imgFormName,
imgName, innerFormName, properties);*/
- this.pdfBuilder.injectAppearanceStreams(holderFormStream, null, null, null,
- null, innerFormName, properties);
+
+ if (!buildPreviewOnly) {
+ this.pdfBuilder.injectAppearanceStreams(holderFormStream, null, null, null,
+ null, innerFormName, properties);
+
+ }
+
this.pdfBuilder.createVisualSignature(template);
this.pdfBuilder.createWidgetDictionary(pdSignatureField, holderFormResources);
-
-
ByteArrayInputStream in = null;
//COSDocument doc = pdfStructure.getVisualSignature();
@@ -152,8 +160,8 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
//in = pdfStructure.getTemplateAppearanceStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
template.save(baos);
- baos.close();
-
+ baos.close();
+
SignatureProfileSettings signatureProfileSettings =
this.pdfBuilder.signatureProfileSettings;
@@ -188,4 +196,17 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
// return result of the stream
return in;
}
+
+// @SneakyThrows
+// private void saveDebuggingSnapshot(PDDocument template, String fileName) {
+// ByteArrayOutputStream baos = new ByteArrayOutputStream();
+// template.save(baos);
+// baos.close();
+//
+// FileOutputStream fos = new FileOutputStream("/home/tlenz/Projekte/pdfas4/source/pdf-as-cli/build/" + fileName + ".pdf");
+// fos.write(baos.toByteArray());
+// fos.close();
+//
+// }
+
}
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsVisualSignatureProperties.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsVisualSignatureProperties.java
index 8a030927..623347ff 100644
--- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsVisualSignatureProperties.java
+++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFAsVisualSignatureProperties.java
@@ -57,9 +57,13 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
private String alternativeTableCaption="";
+ private boolean buildPreviewOnly;
+
public PDFAsVisualSignatureProperties(ISettings settings, PDFBOXObject object,
- PdfBoxVisualObject visObj, PositioningInstruction pos, SignatureProfileSettings signatureProfileSettings) {
- this.settings = settings;
+ PdfBoxVisualObject visObj, PositioningInstruction pos, SignatureProfileSettings signatureProfileSettings,
+ boolean buildPreviewOnly) {
+ this.buildPreviewOnly = buildPreviewOnly;
+ this.settings = settings;
this.signatureProfileSettings = signatureProfileSettings;
try {
main = visObj.getTable();
@@ -114,7 +118,7 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
PDFAsVisualSignatureBuilder builder = new PDFAsVisualSignatureBuilder(this, this.settings, designer, this.signatureProfileSettings);
PDFAsTemplateCreator creator = new PDFAsTemplateCreator(builder);
try {
- setVisibleSignature(creator.buildPDF(designer, this.origDoc));
+ setVisibleSignature(creator.buildPDF(designer, this.origDoc, buildPreviewOnly));
} catch (PdfAsException e) {
throw new PdfAsWrappedIOException(e);
}
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 61a1199d..0ed05eb5 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
@@ -8,10 +8,13 @@ import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsAndPlaceHolderExtractor;
import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
+@RunWith(JUnit4.class)
public class SignatureFieldsAndPlaceHolderExtractorTest {
public String getPath(String resourceName) {