aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-pdfbox-2/src/main
diff options
context:
space:
mode:
authorThomas <>2023-12-19 13:29:12 +0100
committerThomas <>2023-12-19 13:29:12 +0100
commit1bf5a6f022837a28a41778f68c1b278bd2462512 (patch)
treea5cd0aaef58aeb119f3f2b7d3a42dba85559b0b3 /pdf-as-pdfbox-2/src/main
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
Diffstat (limited to 'pdf-as-pdfbox-2/src/main')
-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
3 files changed, 50 insertions, 24 deletions
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);
}