On Sat, Feb 6, 2016 at 5:11 AM, Tilman Hausherr <[email protected]>
wrote:

> Am 05.02.2016 um 06:27 schrieb David Lattimore:
>
>> I'm attempting to upgrade an application from PDFBox 1.8.7 to 2.0.0-RC3.
>> The following code works with the former but crashes with the latter:
>>
>> PDDocument document = PDDocument.load(new
>> File("/path/to/existing_js.pdf"));
>> document.getDocumentCatalog().getNames().getJavaScript().getNames();
>>
>> The crash is as follows:
>>
>> java.io.IOException: Error creating Javascript object, expected a
>> COSDictionary and not COSString{console.println("Hello console!");}
>> at
>> org.apache.pdfbox.pdmodel.PDJavascriptNameTreeNode.convertCOSToPD(PDJavascriptNameTreeNode.java:56)
>> at
>> org.apache.pdfbox.pdmodel.PDJavascriptNameTreeNode.convertCOSToPD(PDJavascriptNameTreeNode.java:1)
>> at
>> org.apache.pdfbox.pdmodel.common.PDNameTreeNode.getNames(PDNameTreeNode.java:261)
>>
>>
> I had a look at some correct files. Please use PDFDebugger, switch to
> "show internal structure" and enter this:
>
>     Root/Names/JavaScript/Names/[0]
>
> JavaScript is "A name tree mapping name strings to document-level
> JavaScript actions" (p. 81 of the 32000 spec)
>
> Names is an array: [key1 value1 key2 value2 … keyn valuen]  (p. 89 of the
> 32000 spec)
>
> "JavaScript Actions" are explained on p. 430 - these are dictionaries with
> two entries, S and JS. Seems that your file has only a string.


You're right. Seems the file was not according to spec. I'm guessing the
file was probably created by hand for the purposes of the test.
Interestingly, 1.8.7 doesn't accept a dictionary, only a string, crashing
with "Error creating Javascript object, expected either COSString or
COSStream and not COSDictionary...". So perhaps the test file was written
to have what 1.8.7 expected.

It looks like 1.8.7 does at least correctly write out JavaScript as a
dictionary, it just can't read it. So I don't have any reason to suspect
that files with strings would be common in the wild.

Thanks for your help,
David

Reply via email to