Repository navigation
Update PDF.js to 1.9.426 - #54
Merged
Merged
Conversation
The example PDF ("compressed.tracemonkey-pldi-09.pdf") is not needed and
thus was not included; "templates/viewer.php" acts as "viewer.html", so
the later was not included either.
On the other hand, source maps were kept so they could be used in case
of need.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
In PDF.js 1.9.426 it is no longer possible to simply set the custom values for "PDFJS" and "PDFViewerApplication" when "js/workersrc.js" is parsed. When "PDFViewerApplication.initialize" is executed it overwrites the value of "PDFJS.workerSrc", so the custom initialization has to be executed after that. As "PDFViewerApplication" does not provide any hookable point for custom initialization in its initialization routine a dirty hack has to be used. When "vendor/pdfjs/web/viewer.js" is parsed at the end it calls "PDFViewerApplication.initialize" (either directly or as a "DOMContentLoaded" event handler), and "PDFViewerApplication.initialize" sends an asynchronous XHR request to initialize the locales, which causes the execution flow to continue with the next script or the next "DOMContentLoaded" handler. Thanks to this "initializeCustomPDFViewerApplication" can be executed at that point by parsing "js/workersrc.js" after "vendor/pdfjs/web/viewer.js" and either calling it directly or adding it as a "DOMContentLoaded" event handler (using the same conditions as in "vendor/pdfjs/web/viewer.js"). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
The "viewer.php" acts as the "viewer.html" file included in the PDF.js package. This commit updates "viewer.php" with the changes to "viewer.html" from PDF.js 1.4.20 to 1.9.426 while respecting the customized parts of "viewer.php" (like the close button or the "nonce" attribute). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Due to the changes from PDF.js 1.4.20 to 1.9.426 now trying to open a different PDF file fails with a Content Security Policy violation. Instead of fixing that the "Open file" button was disabled, as being able to open a different PDF file from the local file system to view it instead of the PDF file in the server did not provide much value. The button was disabled by setting the "hidden" attribute to "true" instead of with the CSS class for consistency with how it is done in "vendor/pdfjs/web/viewer.js" when the browser does not support any of the APIs needed to open the local file. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Closed
MorrisJobke
approved these changes
Feb 24, 2018
MorrisJobke
left a comment
Member
There was a problem hiding this comment.
Tested and works nicely. Sharing page as well as integrated 👍
Member
This was referenced Feb 24, 2018
Member
Author
As the backport to stable12 was trivial and it improves the PDF support I did that too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #52
This pull request updates PDF.js to 1.9.426 (the latest stable version at the time of this writing).
The PDF.js code in vendor had no patches, so the files were simply replaced with the new ones (although some unneeded files like the example PDF were removed); templates/viewer.php and js/workersrc.js were updated with the changes needed for the new version, but respecting their customizations.
Besides that, due to the changes from PDF.js 1.4.20 to 1.9.426 opening a local file failed with a Content Security Policy violation; instead of fixing that the Open file button was simply hidden, as being able to open a local PDF file provided no value (at least, in most cases; it was probably a must have feature for someone out there).
Finally, the Current view (copy or open in new window) button does not seem to work, but it did not either in PDF.js 1.4.20. To be honest I do not know what is the expected behaviour of that button, so I left it as is.