foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.9k stars 1.15k forks source link

Limits entry is not emitted when attaching files #1227

Open blikblum opened 3 years ago

blikblum commented 3 years ago

Bug Report

Limits entry is not emitted when attaching files due to incompatibility with Adobe Reader

Description of the problem

See info at https://github.com/foliojs/pdfkit/pull/1226

We should evaluate if is possible to implement file attachment in a more compliant way

smatheis commented 3 years ago

I modified the demo/attachment.js test script (source here) to reproduce this issue with a second embedded file (resulting pdf here, then validated it with verapdf's PDF/A-3A validation profile, this is the result. (Github doesn't allow .js or .xml uploads, so those files are uploaded as .txt instead)

A few issues came up with the embedded files (some of which should probably be fixed), but none of them mentioned the missing /Limits key. Is it possible verapdf doesn't check for that?

I can not create the same pdf with Adobe Acrobat, because embedding files seems to be a paid feature. The free version can only add files with annotations, which as far as I know doesn't add entries to the /EmbeddedFiles dictionary anyways.

Here is a pdf with multiple embedded files created with Foxit Reader instead, which also opens correctly in Adobe Reader. If you (or anyone else) want to take a closer look at the pdf created with Foxit, I recommend these PDF Tools to make sense of the compressed /ObjStm at 20 0 obj, it includes the /Pages and /EmbeddedFiles dictionaries.

Anyways, these are the contents of that Object stream:

"1 0 2 37 6 81 8 125 13 229 14 290 16 362 17 429 19 505 
<</Type/Pages/Kids[ 7 0 R ]/Count 1>>
<</Dests<</Names[]>>/EmbeddedFiles 17 0 R >>
<</ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>
<</ModDate(D:20210326135820+01'00')/Producer 9 0 R /Title 12 0 R /Creator 10 0 R /CreationDate 11 0 R >>
<</Fields[]/DA(/Helv 0 Tf 0 g)/DR<</Font<</Helv 14 0 R >>>>>>
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
<</UF(test.png)/EF<</F 15 0 R >>/Desc()/F(test.png)/Type/Filespec>>
<</Names[(\xfe\xff\x00C\x00H\x00A\x00N\x00G\x00E\x00L\x00O\x00G\x00.\x00m\x00d) 19 0 R (\xfe\xff\x00t\x00e\x00s\x00t\x00.\x00p\x00n\x00g) 16 0 R ]>>
<</UF(CHANGELOG.md)/EF<</F 18 0 R >>/Desc()/F(CHANGELOG.md)/Type/Filespec>>"

I believe the <</Names[(\xfe… part is the /EmbeddedFiles dictionary, and it seems to not include /Limits in here either - did the specification on Name Trees change so that Limits is not required anymore? Maybe it's not actually an issue if Foxit Reader is doing the same thing.

blikblum commented 3 years ago

Maybe it's not actually an issue if Foxit Reader is doing the same thing.

Yes. its a possibility. Just want to keep track