Add compatibility with PDF.js v2.x

Closes #4237
This commit is contained in:
Florian Bruhin 2018-09-22 20:26:25 +02:00
parent ee5d98d5d0
commit 75bfb547ba

View File

@ -83,10 +83,20 @@ def _generate_pdfjs_script(filename):
return jinja.js_environment.from_string(""" return jinja.js_environment.from_string("""
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
{% if disable_create_object_url %} if (typeof window.PDFJS !== 'undefined') {
PDFJS.disableCreateObjectURL = true; // v1.x
{% endif %} {% if disable_create_object_url %}
PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info; window.PDFJS.disableCreateObjectURL = true;
{% endif %}
window.PDFJS.verbosity = window.PDFJS.VERBOSITY_LEVELS.info;
} else {
// v2.x
const options = window.PDFViewerApplicationOptions;
{% if disable_create_object_url %}
options.set('disableCreateObjectURL', true);
{% endif %}
options.set('verbosity', pdfjsLib.VerbosityLevel.INFOS);
}
const viewer = window.PDFView || window.PDFViewerApplication; const viewer = window.PDFView || window.PDFViewerApplication;
viewer.open("{{ url }}"); viewer.open("{{ url }}");