Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
7.04k stars 677 forks source link

PDFDocument.save() generates pdf missing trailer dictionary #1410

Open cory-zpaper opened 1 year ago

cory-zpaper commented 1 year ago

What were you trying to do?

I am generating a file input part of a multipart form via PDFDocument.save() (adding the part via FormData.append()). On the server, I'm trying to open the received pdf file with pdfBox. I'm getting the following error. Caused by: java.io.IOException: Missing root object specification in trailer. at org.apache.pdfbox.pdfparser.COSParser.parseTrailerValuesDynamically(COSParser.java:2947) ~[pdfbox-2.0.26.jar:2.0.26]

The exception says that the specification is missing in the trailer but when I look at the data that was uploaded, the trailer is completely missing.

Is there some parameter that I can send to save() to make sure the trailer dictionary is produced?

How did you attempt to do it?

I created browser-side javascript that is saving the pdf content (via PDFDocument.save()) to an array that is being posted to a server as part of a multipart form.

What actually happened?

In my server code, when I try to read the posted pdf document, pdfBox gives me this exception: Caused by: java.io.IOException: Missing root object specification in trailer. at org.apache.pdfbox.pdfparser.COSParser.parseTrailerValuesDynamically(COSParser.java:2947) ~[pdfbox-2.0.26.jar:2.0.26]

What did you expect to happen?

I expected pdfBox to be able to open the document.

How can we reproduce the issue?

The code is not short to do this, since an ajax call is being made that is posting a multipart form. I'm hoping that the problem can be duplicated without looking at my code, but if code is required, I can work up a smaller bit of code that demonstrates the problem.

Version

1.17.1

What environment are you running pdf-lib in?

Browser

Checklist

Additional Notes

No response

cory-zpaper commented 1 year ago

Please note that while pdfBox complains about a root object specification missing from trailer, actually the entire trailer is missing.