diff options
author | Christian Maierhofer <cmaierhofer@iaik.tugraz.at> | 2016-06-15 08:32:49 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2016-08-17 16:49:29 +0200 |
commit | 922c5faaa0bbf5ace05dcc68ac8a2452ddec560a (patch) | |
tree | 71b362944875516e662eaefda7978a9b6057c269 | |
parent | eaee8b0b0fe684279a9128f7616512dd9249fd72 (diff) | |
download | pdf-as-4-922c5faaa0bbf5ace05dcc68ac8a2452ddec560a.tar.gz pdf-as-4-922c5faaa0bbf5ace05dcc68ac8a2452ddec560a.tar.bz2 pdf-as-4-922c5faaa0bbf5ace05dcc68ac8a2452ddec560a.zip |
modified placeholder extraction for pdfbox2
3 files changed, 51 insertions, 8 deletions
diff --git a/pdf-as-lib/src/main/resources/placeholder/pdfbox-reader-2.properties b/pdf-as-lib/src/main/resources/placeholder/pdfbox-reader-2.properties new file mode 100644 index 00000000..759fb51c --- /dev/null +++ b/pdf-as-lib/src/main/resources/placeholder/pdfbox-reader-2.properties @@ -0,0 +1,23 @@ +cm = org.apache.pdfbox.contentstream.operator.state.Concatenate
+gs = org.apache.pdfbox.contentstream.operator.state.SetGraphicsStateParameters
+q = org.apache.pdfbox.contentstream.operator.state.Save
+Q = org.apache.pdfbox.contentstream.operator.state.Restore
+Tm = org.apache.pdfbox.contentstream.operator.state.SetMatrix
+w = org.apache.pdfbox.contentstream.operator.state.SetLineWidth
+BT = org.apache.pdfbox.contentstream.operator.text.BeginText
+ET = org.apache.pdfbox.contentstream.operator.text.EndText
+T* = org.apache.pdfbox.contentstream.operator.text.NextLine
+Tc = org.apache.pdfbox.contentstream.operator.text.SetCharSpacing
+Td = org.apache.pdfbox.contentstream.operator.text.MoveText
+TD = org.apache.pdfbox.contentstream.operator.text.MoveTextSetLeading
+Tf = org.apache.pdfbox.contentstream.operator.text.SetFontAndSize
+Tj = org.apache.pdfbox.contentstream.operator.text.ShowText
+TJ = org.apache.pdfbox.contentstream.operator.text.ShowTextAdjusted
+TL = org.apache.pdfbox.contentstream.operator.text.SetTextLeading
+Tr = org.apache.pdfbox.contentstream.operator.text.SetTextRenderingMode
+Ts = org.apache.pdfbox.contentstream.operator.text.SetTextRise
+Tw = org.apache.pdfbox.contentstream.operator.text.SetWordSpacing
+Tz = org.apache.pdfbox.contentstream.operator.text.SetTextHorizontalScaling
+\' = org.apache.pdfbox.contentstream.operator.text.ShowTextLine
+\" = org.apache.pdfbox.contentstream.operator.text.ShowTextLineAndSpace
+#Do = org.apache.pdfbox.contentstream.operator.graphics.DrawObject
\ No newline at end of file diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java index 39d66c3c..c239ed94 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java @@ -52,20 +52,23 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.util.HashMap; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; import java.util.Vector; -import org.apache.pdfbox.contentstream.PDContentStream; +import javassist.bytecode.stackmap.TypeData.ClassName; + import org.apache.pdfbox.contentstream.PDFStreamEngine; import org.apache.pdfbox.contentstream.operator.Operator; +import org.apache.pdfbox.contentstream.operator.OperatorProcessor; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.common.PDStream; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDFontFactory; import org.apache.pdfbox.pdmodel.graphics.PDXObject; @@ -109,12 +112,26 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl private List<SignaturePlaceholderData> placeholders = new Vector<SignaturePlaceholderData>(); private int currentPage = 0; private PDDocument doc; + + private SignaturePlaceholderExtractor(String placeholderId, - int placeholderMatchMode, PDDocument doc) throws IOException { + int placeholderMatchMode, PDDocument doc) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { super(); - //super(ResourceLoader.loadProperties( //TODO: pdfbox2 - properties need to be set - // "placeholder/pdfbox-reader.properties", true)); + + final Properties properties = new Properties(); + properties.load(ClassName.class.getClassLoader().getResourceAsStream("placeholder/pdfbox-reader-2.properties")); + + Set<Entry<Object, Object>> entries = properties.entrySet(); + for(Entry<Object, Object> entry:entries){ + String processorClassName = (String)entry.getValue(); + Class<?> klass = Class.forName( processorClassName ); + org.apache.pdfbox.contentstream.operator.OperatorProcessor processor = + (OperatorProcessor) klass.newInstance(); + + addOperator( processor ); + } + this.doc = doc; } @@ -139,7 +156,7 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl try { extractor = new SignaturePlaceholderExtractor(placeholderId, matchMode, doc); - } catch (IOException e2) { + } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e2) { throw new PDFIOException("error.pdf.io.04", e2); } 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 58ebb7f5..8a0a5e72 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 @@ -35,6 +35,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -316,7 +317,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // Placeholder found! // replace placeholder - PDImageXObject img = PDImageXObject.createFromFile("/placeholder/empty.jpg", doc); + URL fileUrl = PADESPDFBOXSigner.class.getResource("/placeholder/empty.jpg"); + + PDImageXObject img = PDImageXObject.createFromFile(fileUrl.getPath(), doc); img.getCOSObject().setNeedToBeUpdated(true); // PDDocumentCatalog root = doc.getDocumentCatalog(); |