Pdf.js: Deprecated API usage with examples

Created on 24 Dec 2018  路  4Comments  路  Source: mozilla/pdf.js

Configuration:

  • Web browser and its version: Firefox 64.0
  • Operating system and its version: Windows 10
  • PDF.js version: '2.6.1' (included directly by //mozilla.github.io/pdf.js/build/pdf.js)
  • Is a browser extension: No

Steps to reproduce the problem:
1. include via
- <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
2. set:
- pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
3. use examples from: https://mozilla.github.io/pdf.js/examples/

What went wrong? (add screenshot)

99733b699429b48a9982577efb14fdde

1-other

Most helpful comment

Came here because I was getting this error when upgrading from v1 to v2:

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

In short, we now have to explicitly refer to .promise

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

All 4 comments

The examples have already been updated with this new API usage, just not yet on JSFiddle. @yurydelendik Could you perhaps update all examples on that page with the current code from the examples folder?

Fixed

Came here because I was getting this error when upgrading from v1 to v2:

Deprecated API usage:  PDFDocumentLoadingTask.then method, use the `promise` getter instead.

In short, we now have to explicitly refer to .promise

//V1
const loadPDF = await PDFJS.getDocument(file);
const pages = loadPDF.numPages;


//V2
const loadPDF = await PDFJS.getDocument(file).promise; //<-- simply change it here
const pages = loadPDF.numPages;

the view port error is die to using version 1 way:
var viewport = pdfPage.getViewport(scale, rotate);

change it to use GetViewportParameters :
https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L158

var viewport = pdfPage.getViewport({scale:scale, rotate:rotate});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SehyunPark picture SehyunPark  路  3Comments

smit-modi picture smit-modi  路  3Comments

brandonros picture brandonros  路  3Comments

hp011235 picture hp011235  路  4Comments

PeterNerlich picture PeterNerlich  路  3Comments