Hi
After digging through some information regarding document object level
Javascript injecting, I created what I believe to be the shortest
PDF-compliant PDF file that works with Adobe and prints out a "Hello
World!" upon opening it:
$ cat ../pdftools/smallJShack.pdf
%PDF-1.
trailer <</Root<<
/Pages <<>>
/OpenAction <<
/S /JavaScript
/JS (app.alert({cMsg: 'Hello World!'});)>>>>>>
Running the following fails:
$ java -jar app/target/pdfbox-app-2.0.0-SNAPSHOT.jar PrintPDF
../pdftools/smallJShack.pdf
Exception in thread "main" java.io.IOException: Missing root object
specification in trailer.
at
org.apache.pdfbox.pdfparser.COSParser.parseTrailerValuesDynamically(COSParser.java:2004)
at
org.apache.pdfbox.pdfparser.PDFParser.initialParse(PDFParser.java:235)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:267)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:915)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:844)
at org.apache.pdfbox.tools.PrintPDF.main(PrintPDF.java:98)
at org.apache.pdfbox.tools.PDFBox.main(PDFBox.java:67)
While this file opens correctly in Adobe Acrobat and prints out the "Hello
World!", is this a case that should be implemented in the PDFBox parser, or
is it too esoteric?
The background is that in my project, I'm trying to "infiltrate" the
Doc/Open Event to execute all existing javascripts inside the PDF I'm
working on when opened within Adobe Acrobat. This would allow me to
short-circuit the manual labour of implementing each and every javascript's
functionality in Java using PDFBox, since PDFBox does not currently have a
JS or Event handler.
Most of what my PDFs do is check if a certain field is set and if so, set
some fields visible and certain others invisible. The form fields whose
visibility are toggled are basically gray boxes which upon visibility patch
over a predefined geographic section of the PDF's form fields.
Best regards
Roberto