Pdf.js: 「GlobalWorkerOptions.workerSrc」が指定されていません。

作成日 2019年01月21日  ·  4コメント  ·  ソース: mozilla/pdf.js

if(!fallbackWorkerSrc && typeof document!== 'undefined'){
var pdfjsFilePath = document.currentScript && document.currentScript.src;
if(pdfjsFilePath){
fallbackWorkerSrc = pdfjsFilePath.replace(/(。(?: min。)?js)(?。*)?$ / i、 '。worker $ 1 $ 2');
}
}
「document.currentScript」=== null、pdfjsFilePath === null、

関数getWorkerSrc(){
if(_worker_options.GlobalWorkerOptions.workerSrc){
return _worker_options.GlobalWorkerOptions.workerSrc;
}
if(typeof fallbackWorkerSrc!== 'undefined'){
fallbackWorkerSrcを返します。
}
新しいエラーをスローします( '「GlobalWorkerOptions.workerSrc」が指定されていません。');
}
image

最も参考になるコメント

これを試してみてください:

  const pdfjs = await import('pdfjs-dist/build/pdf');
  const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...

全てのコメント4件

あなたは、常に設定することにより、すなわち、明示的にworkerSrcを指定する必要がありますpdfjsLib.GlobalWorkerOptions.workerSrc呼び出す前にpdfjsLib.getDocumentフォールバックは、すべての状況で正しく動作することが保証されていないだけでベストエフォート型ソリューションであるため、。

これを試してみてください:

  const pdfjs = await import('pdfjs-dist/build/pdf');
  const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...

これを試してみてください:

  const pdfjs = await import('pdfjs-dist/build/pdf');
  const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...

私はあなたが反応で与えたアイデアを使うのに苦労しました
問題は、コンポーネントがマウントされているときに機能しないことです
公式スクリプトを使用すると、すべて問題ありませんが、 pdfjs-dist機能しません。

const pdfjsLib = window['pdfjs-dist/build/pdf
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

そのためのアイデアはありますか? スクリプトを使用したくない

pdf.jsは公式にreactをサポートしていないので、心から私はpdfよりもreact抽象化を使用します:(

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