aboutsummaryrefslogtreecommitdiff
path: root/stamper/stmp-itext
diff options
context:
space:
mode:
Diffstat (limited to 'stamper/stmp-itext')
-rw-r--r--stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java14
-rw-r--r--stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/ITextStamperAccess.java47
-rw-r--r--stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/package-info.java8
3 files changed, 66 insertions, 3 deletions
diff --git a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java
index ff68dcd8..b0801a9c 100644
--- a/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java
+++ b/stamper/stmp-itext/src/main/java/at/gv/egiz/pdfas/stmp/itext/ITextStamper.java
@@ -2,6 +2,7 @@ package at.gv.egiz.pdfas.stmp.itext;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
import at.gv.egiz.pdfas.lib.impl.stamping.IPDFStamper;
import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject;
import at.gv.egiz.pdfas.lib.impl.status.PDFObject;
@@ -444,7 +445,7 @@ public class ITextStamper implements IPDFStamper {
}
public byte[] writeVisualObject(IPDFVisualObject visualObject, PositioningInstruction positioningInstruction,
- byte[] pdfData) throws PdfAsException {
+ byte[] pdfData, String placeholderName) throws PdfAsException {
try {
ITextVisualObject object = null;
@@ -479,14 +480,21 @@ public class ITextStamper implements IPDFStamper {
throw new PdfAsException("The provided page (=" +
positioningInstruction.getPage() + ") is out of range.");
}
-
+
+ if(placeholderName != null) {
+ ITextStamperAccess.replacePlaceholder(stamper, targetPage, placeholderName);
+ }
+
PdfContentByte content = stamper.getOverContent(targetPage);
PdfPTable table = object.getTable();
+ logger.info("Visual Object: " + visualObject.getWidth() + " x " + visualObject.getHeight());
+ //PdfTemplate table_template = content.createTemplate(visualObject.getWidth(), visualObject.getHeight());
+
table.writeSelectedRows(0, -1, positioningInstruction.getX(),
positioningInstruction.getY(), content);
-
+
stamper.close();
baos.close();
diff --git a/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/ITextStamperAccess.java b/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/ITextStamperAccess.java
new file mode 100644
index 00000000..65b4ba77
--- /dev/null
+++ b/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/ITextStamperAccess.java
@@ -0,0 +1,47 @@
+package com.lowagie.text.pdf;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.stmp.itext.ITextStamper;
+
+import com.lowagie.text.BadElementException;
+import com.lowagie.text.Image;
+
+public class ITextStamperAccess {
+
+ private static final Logger logger = LoggerFactory.getLogger(ITextStamperAccess.class);
+
+ public static void replacePlaceholder(PdfStamper stamper, int pageNr, String placeholderName)
+ throws BadElementException, MalformedURLException, IOException,
+ BadPdfFormatException, PdfAsException {
+ Image img = Image.getInstance(ITextStamper.class.getResource("/placeholder/empty.jpg"));
+ PdfImage pImg = new PdfImage(img, "Imwurscht", null);
+ PdfStamperImp stamperImp = (PdfStamperImp)stamper.getWriter();
+ PdfIndirectObject ind = stamperImp.addToBody(pImg);
+
+ PdfDictionary resources = stamper.getReader().getPageN(pageNr).getAsDict(PdfName.RESOURCES);
+ if (ind != null && resources != null)
+ {
+ PdfDictionary xobjDict = resources.getAsDict(PdfName.XOBJECT);
+ if (xobjDict != null)
+ {
+ xobjDict.put(new PdfName(placeholderName), ind.getIndirectReference());
+ stamperImp.markUsed(resources);
+ }
+ else
+ {
+ throw new PdfAsException("failed to write PDF", new NullPointerException("Image dictionary not found in document structure!"));
+ }
+ }
+ else
+ {
+ throw new PdfAsException("failed to write PDF", new NullPointerException("Resource dictionary not found in document structure!"));
+ }
+ }
+
+}
diff --git a/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/package-info.java b/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/package-info.java
new file mode 100644
index 00000000..131f9340
--- /dev/null
+++ b/stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package com.lowagie.text.pdf; \ No newline at end of file