mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.59k stars 9.99k forks source link

Impossibility to render correctly a form-fillable PDF #12593

Open Luni-4 opened 4 years ago

Luni-4 commented 4 years ago

Attach (recommended) or Link to PDF file here: form.pdf

Configuration:

Steps to reproduce the problem:

  1. Open the PDF file attached above with Mozilla 82.0.2
  2. Only the basic sheet is rendered, but it is not possible to fill the forms and view the JavaScript menu that allows the generation of some additional pages

What is the expected behavior? (add screenshot)

The possibility to fill the sheet, in addition to view and use the JavaScript menu that allows to generate the additional pages.

The JavaScript code present within the PDF file is open-source and you can find it here. Since that code makes use of the AcroJS API, the PDF file could be rendered correctly using the last free version of Adobe Acrobat Reader.

Thanks in advance for your help!

Snuffleupagus commented 4 years ago

Attach (recommended) or Link to PDF file here: PDF files can be downloaded here

Please actually attach the test-case here, since that generally helps save everyone's time, given that the link doesn't point directly to a PDF file and even more importantly that it also also seems to require payment to even access the files.

As-is, this issue unfortunately isn't actionable and should probably be closed as a duplicate of one (or more) of the already open issues in the https://github.com/mozilla/pdf.js/labels/4-form-xfa category.

Luni-4 commented 4 years ago

Attach (recommended) or Link to PDF file here: PDF files can be downloaded here

Please actually attach the test-case here, since that generally helps save everyone's time, given that the link doesn't point directly to a PDF file and even more importantly that it also also seems to require payment to even access the files.

Oh, sorry about that, I didn't want to waste your time, but I don't think those files can be re-uploaded somewhere else, that's why I posted the link. Anyway, it is not necessary to pay anything in order to access them, you can download the files the same setting up the amount to 0, it is just a voluntary offer to help developers.

As-is, this issue unfortunately isn't actionable and should probably be closed as a duplicate of one (or more) of the already open issues in the https://github.com/mozilla/pdf.js/labels/4-form-xfa category.

If there are other issues about running JavaScript code inside a PDF file, this is fine on my part, but I can't see any of them among the ones you linked. Could you please point me to one of that? Thanks!

Luni-4 commented 3 years ago

@Snuffleupagus

I read with more attention the distribution polices described here and it seems I can attach the sheet. Updated the first comment. I think it is now actionable

timvandermeij commented 3 years ago

Some initial observations. The console is full of warnings for this PDF file:

Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 5 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 7 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 3 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 6 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 2 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 12 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 2 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 8 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 5 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 8 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 8 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 6 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 8 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 5 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 4 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 26 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 6 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 3 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 55 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 5 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 45 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 6 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 3 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 25 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 3 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 24 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 2 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 17 pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 51 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 4 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Annotation is missing the required /Subtype. 3 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 2 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 58 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: JavaScript is not supported app.js:1541:8
Not all pages have the same size. The printed result may be incorrect! pdf_print_service.js:105:6
Warning: Push buttons without action dictionaries are not supported 7 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 45 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 3 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 2 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported 4 pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 3 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13
Warning: parseDestDictionary: unsupported action type "JavaScript". 21 pdf.worker.js:1067:13
Warning: Push buttons without action dictionaries are not supported pdf.worker.js:1067:13

"Annotation is missing the required /Subtype" indicates a kind of a corruption since this property is required in order to be able to render the annotation. The other logs are mainly about unimplemented features.

Luni-4 commented 3 years ago

@timvandermeij

I re-uploaded the file, I hope it is correct now. Thanks for your investigation!

timvandermeij commented 3 years ago

The fields now render correctly when I open the new file with https://mozilla.github.io/pdf.js/web/viewer.html (the latest development version of PDF.js) and the warnings about missing subtypes are gone. These warnings remain:

Warning: Push buttons without action dictionaries are not supported
Warning: parseDestDictionary: unsupported action type "JavaScript".

Relabeling this since the PDF file is no longer corrupt from a spec point of view.

calixteman commented 3 years ago

I partially analyzed the file here, there some interesting things:

but the method toSource (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource) is used (54 occurences) and there are absolutely no chance that we'll spend time to implement such a thing. And I stopped my investigations here. If you really want to use this pdf in Firefox, you first need to rewrite the js code to remove all non-standard stuff, once this is done I'll be happy to fix bugs if any to see it in Firefox.

Luni-4 commented 3 years ago

I partially analyzed the file here, there some interesting things:

* bookmarks can have JS actions and we should support that.

* bookmarks can be accessed from JS

but the method toSource (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource) is used (54 occurences) and there are absolutely no chance that we'll spend time to implement such a thing. And I stopped my investigations here. If you really want to use this pdf in Firefox, you first need to rewrite the js code to remove all non-standard stuff, once this is done I'll be happy to fix bugs if any to see it in Firefox.

Thanks for the analysis @calixteman!

About the js code, I don't know whether the most recent version of that PDF has been updated, I can investigate on that and report back. Could you please tell me what are the non-standard stuff in it?

marco-c commented 3 years ago

About the js code, I don't know whether the most recent version of that PDF has been updated, I can investigate on that and report back. Could you please tell me what are the non-standard stuff in it?

@Luni-4 it's the toSource method. It's not out of the standard from a PDF perspective, but it is a very old feature that has been deprecated from browsers' JS (see #13289). Basically no PDF we know of (except the one you uploaded here) is using toSource.

Luni-4 commented 3 years ago

Ok, thank you @marco-c for the clarification!

I thought that with the the term all non-standard stuff, more functions were involved.