No PDFJS.workerSrc specified error on using pdfjs-dist package from npm

See original GitHub issue

test

function usage(blob) {
    console.log('usage called!');
    var fileReader = new FileReader();
    fileReader.onload = function (blob) {
        require('pdfjs-dist');
        var fs = require('fs');
        PDFJS.getDocument(blob.target.result).then(function (pdfDocument) {
        console.log('Number of pages: ' + pdfDocument.numPages);
        });
    }
    fileReader.readAsArrayBuffer(blob);
}

implemented as shown in the example for node, but throws error for not specifying workingSrc. I’m using content scripts for a chrome extension which disallow document.currentscript as fcfort commented in this issue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
danielmcqcommented, Sep 24, 2019

You should try this:

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

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...

This absolutely worked for me, except I’m using native import.

import pdfjs from 'pdfjs-dist';
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';

pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
5reactions
luistakcommented, Aug 6, 2019

You should try this:

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

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

No PDFJS.workerSrc specified - Stack Overflow
I had a similar error and I fixed it by specifying the pdf.worker.js explicitly at the end of the pdf.js if (!PDFJS.workerSrc &&...
Read more >
Error: No PDFJS.workerSrc specified (#16) · Issues - GitLab
Trying to use pdf-parse in Electron and it returns this error: ...\node_modules\pdf-parse\lib\pdf.js\v1.10.100\build\pdf.js:4011 Uncaught ...
Read more >
How to use the pdfjs-dist.GlobalWorkerOptions function in ...
To help you get started, we've selected a few pdfjs-dist. ... Use Snyk Code to scan source code in minutes - no build...
Read more >
react-pdf - npm
React-PDF. Display PDFs in your React app as easily as if they were images. Lost? This package is used to display existing PDFs....
Read more >
Examples
Remember though that PDF.js uses promises, and the above will return a ... exports. var pdfjsLib = window['pdfjs-dist/build/pdf']; // The workerSrc property ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found