From 29ec10fb663523c4a18904c332199ce6e974dd2f Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 27 Nov 2013 10:05:35 +0100 Subject: Support for QR Placeholders in PAdES --- .../com/lowagie/text/pdf/ITextStamperAccess.java | 47 ++++++++++++++++++++++ .../java/com/lowagie/text/pdf/package-info.java | 8 ++++ 2 files changed, 55 insertions(+) create mode 100644 stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/ITextStamperAccess.java create mode 100644 stamper/stmp-itext/src/main/java/com/lowagie/text/pdf/package-info.java (limited to 'stamper/stmp-itext/src/main/java/com') 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 -- cgit v1.2.3