aboutsummaryrefslogtreecommitdiff
path: root/stamper/stmp-itext/src/main/java/com/lowagie
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-11-27 10:05:35 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-11-27 10:05:35 +0100
commit29ec10fb663523c4a18904c332199ce6e974dd2f (patch)
tree3d68c52ca1fd5e2cb2f90c1890db22e4fd943dcb /stamper/stmp-itext/src/main/java/com/lowagie
parentf3476576c50efd922593c82656efda7aec5ae97f (diff)
downloadpdf-as-4-29ec10fb663523c4a18904c332199ce6e974dd2f.tar.gz
pdf-as-4-29ec10fb663523c4a18904c332199ce6e974dd2f.tar.bz2
pdf-as-4-29ec10fb663523c4a18904c332199ce6e974dd2f.zip
Support for QR Placeholders in PAdES
Diffstat (limited to 'stamper/stmp-itext/src/main/java/com/lowagie')
-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
2 files changed, 55 insertions, 0 deletions
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