[IMP] website_slides: adapt pdfjs 2.2.228

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) <ged@openerp.com>
This commit is contained in:
Mohammed Shekha
2020-01-07 05:21:22 +00:00
parent 5c7892fe6b
commit a402dba783
2 changed files with 10 additions and 11 deletions
@@ -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;
@@ -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);