New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable13] Update PDF.js to 1.9.426 #55

merged 4 commits into from Feb 24, 2018


None yet
2 participants

danxuliu commented Feb 24, 2018

Backport of #54

danxuliu added some commits Feb 23, 2018

Replace PDF.js v1.4.20 files with v1.9.426 files
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 <>
Set custom initialization for PDF.js
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 <>
Update "viewer.php" to PDF.js 1.9.426
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"

Signed-off-by: Daniel Calviño Sánchez <>
Disable "Open file" button
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 danxuliu added this to the Nextcloud 13.0.1 milestone Feb 24, 2018

@danxuliu danxuliu requested review from rullzer and MorrisJobke Feb 24, 2018

@rullzer rullzer merged commit b5f94c6 into stable13 Feb 24, 2018

3 checks passed

continuous-integration/drone/pr the build was successful
continuous-integration/drone/push the build was successful
continuous-integration/travis-ci/pr The Travis CI build passed

@rullzer rullzer deleted the stable13-54-update-pdf.js-to-1.9.426 branch Feb 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment