From a402dba783f35d533f172e63199ff507db908b71 Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Tue, 26 Nov 2019 13:02:37 +0000 Subject: [PATCH] [IMP] website_slides: adapt pdfjs 2.2.228 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use window.pdfjsLib instead of window.PDFJS. PDF returned through getDocument() has _pdfInfo variable instead of pdfInfo. task-2124443 closes odoo/odoo#40917 Related: odoo/enterprise#6900 Signed-off-by: Géry Debongnie (ged) --- .../lib/pdfslidesviewer/PDFSlidesViewer.js | 5 ++--- .../static/src/js/slides_upload.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/addons/website_slides/static/lib/pdfslidesviewer/PDFSlidesViewer.js b/addons/website_slides/static/lib/pdfslidesviewer/PDFSlidesViewer.js index 73fac349a1a..e6ceb6f5cac 100644 --- a/addons/website_slides/static/lib/pdfslidesviewer/PDFSlidesViewer.js +++ b/addons/website_slides/static/lib/pdfslidesviewer/PDFSlidesViewer.js @@ -5,7 +5,7 @@ DOC : http://mozilla.github.io/pdf.js/api/draft/api.js.html */ -// !!!!!!!!! use window.PDFJS and not PDFJS +// !!!!!!!!! use window.pdfjsLib and not pdfjsLib var PDFSlidesViewer = (function(){ @@ -34,7 +34,6 @@ var PDFSlidesViewer = (function(){ * @see http://en.wikipedia.org/wiki/Cross-origin_resource_sharing. * this is equivalent to the use_cors option in openerpframework.js */ - window.PDFJS.disableWorker = disableWorker || false; }; /** @@ -44,7 +43,7 @@ var PDFSlidesViewer = (function(){ PDFSlidesViewer.prototype.loadDocument = function(url) { var self = this; var pdf_url = url || this.pdf_url; - return window.PDFJS.getDocument(pdf_url).then(function (file_content) { + return window.pdfjsLib.getDocument(pdf_url).then(function (file_content) { self.pdf = file_content; self.pdf_page_total = file_content.numPages; return file_content; diff --git a/addons/website_slides/static/src/js/slides_upload.js b/addons/website_slides/static/src/js/slides_upload.js index 52ea4915b6d..ff01dec5bd6 100644 --- a/addons/website_slides/static/src/js/slides_upload.js +++ b/addons/website_slides/static/src/js/slides_upload.js @@ -459,7 +459,7 @@ var SlideUploadDialog = Dialog.extend({ if (file.type === 'application/pdf') { var ArrayReader = new FileReader(); this.set('can_submit_form', false); - // file read as ArrayBuffer for PDFJS get_Document API + // file read as ArrayBuffer for pdfjsLib get_Document API ArrayReader.readAsArrayBuffer(file); ArrayReader.onload = function (evt) { var buffer = evt.target.result; @@ -469,15 +469,15 @@ var SlideUploadDialog = Dialog.extend({ self.set('can_submit_form', true); }; /** - * The following line fixes PDFJS 'Util' global variable. + * The following line fixes pdfjsLib 'Util' global variable. * This is (most likely) related to #32181 which lazy loads most assets. * - * That caused an issue where the global 'Util' variable from PDFJS can be + * That caused an issue where the global 'Util' variable from pdfjsLib can be * (depending of which libraries load first) overridden by the global 'Util' * variable of bootstrap. - * (See 'lib/bootstrap/js/util.js' and 'lib/pdfjs/src/shared/util.js') + * (See 'lib/bootstrap/js/util.js' and 'web/static/lib/pdfjs/build/pdfjs.js') * - * This commit ensures that the global 'Util' variable is set to the one of PDFJS + * This commit ensures that the global 'Util' variable is set to the one of pdfjsLib * right before it's used. * * Eventually, we should update or get rid of one of the two libraries since they're @@ -485,9 +485,9 @@ var SlideUploadDialog = Dialog.extend({ * In the mean time, this small fix allows not refactoring all of this and can not * cause much harm. */ - Util = PDFJS.Util; - PDFJS.getDocument(new Uint8Array(buffer), null, passwordNeeded).then(function getPdf(pdf) { - self._formSetFieldValue('duration', (pdf.pdfInfo.numPages || 0) * 5); + Util = window.pdfjsLib.Util; + window.pdfjsLib.getDocument(new Uint8Array(buffer), null, passwordNeeded).then(function getPdf(pdf) { + self._formSetFieldValue('duration', (pdf._pdfInfo.numPages || 0) * 5); pdf.getPage(1).then(function getFirstPage(page) { var scale = 1; var viewport = page.getViewport(scale);