Pdf.js: 例を使用した非推奨のAPIの使用

作成日 2018年12月24日  ·  4コメント  ·  ソース: mozilla/pdf.js

構成:

  • Webブラウザとそのバージョン:Firefox 64.0
  • オペレーティングシステムとそのバージョン:Windows 10
  • PDF.jsバージョン: '2.6.1'( //mozilla.github.io/pdf.js/build/pdf.js直接含まれています)
  • ブラウザ拡張機能ですか:いいえ

問題を再現する手順:
1.経由で含める
- <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
2.セット:
- pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
3.次の例を使用します: https

何が悪かったのか? (スクリーンショットを追加)

99733b699429b48a9982577efb14fdde

1-other

最も参考になるコメント

v1からv2にアップグレードするときにこのエラーが発生したため、ここに来ました。

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

つまり、 .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;

全てのコメント4件

例は、この新しいAPIの使用法ですでに更新されていますが、JSFiddleではまだ更新されていません。 @yurydelendik examplesフォルダーの現在のコードで、そのページのすべての例を更新できますか?

修理済み

v1からv2にアップグレードするときにこのエラーが発生したため、ここに来ました。

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

つまり、 .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;

ビューポートエラーは、バージョン1の方法を使用することで死にます。
var viewport = pdfPage.getViewport(scale, rotate);

GetViewportParametersを使用するように変更します。
https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L158

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

このページは役に立ちましたか?
0 / 5 - 0 評価