aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.java25
-rw-r--r--pdf-as-pdfbox-2/src/test/java/at/gv/egiz/pdfas/lib/testpdfbox/SignatureFieldsAndPlaceHolderExtractorTest.java16
6 files changed, 106 insertions, 38 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 ef1f14b2..42f16598 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
@@ -363,7 +363,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();
@@ -825,7 +825,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc,
visualObject, pdfObject.getStatus().getSettings());
}
-
+
origDoc.close();
final SignaturePositionImpl position = new SignaturePositionImpl();
@@ -839,15 +839,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;
@@ -859,7 +860,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 f482f49f..34093a9d 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
@@ -23,12 +23,8 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2;
-import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
-import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException;
-import at.gv.egiz.pdfas.common.settings.ISettings;
-import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
-import at.gv.egiz.pdfas.lib.impl.pdfbox2.PDFBOXObject;
-import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
+import java.io.IOException;
+
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageTree;
@@ -36,7 +32,12 @@ import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleS
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException;
+import at.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
+import at.gv.egiz.pdfas.lib.impl.pdfbox2.PDFBOXObject;
+import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
@@ -56,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();
@@ -113,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 0d85c82b..40522504 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,20 @@
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 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) {