question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have an alias (e.g. PDFJS or PDFJS2) instead of window['pdfjs-dist/build/pdf'] or window.pdfjsDistBuildPdf

See original GitHub issue

#9493 removed the PDFJS global, so now the only way to access the PDF.js library from a browser in a non-module context (i.e. not AMD or CommonJS) is through window['pdfjs-dist/build/pdf'] or window.pdfjsDistBuildPdf.

This is an unfriendly name, and seemingly just an artefact of the implementation. Can we use a global such as PDFJS, or if you wish, PDFJS2?

The name originates from here: https://github.com/mozilla/pdf.js/blob/6662985a20b769d7e78e7cf4486eb6b7130f0cf0/gulpfile.js#L228-L235 https://github.com/mozilla/pdf.js/blob/6662985a20b769d7e78e7cf4486eb6b7130f0cf0/gulpfile.js#L241-L253

The window['pdfjs-dist/build/pdf'] export is done by Webpack, and can probably be configured by replacing the library string with an object, and set root to the desired name.

The window.pdfjsDistBuildPdf export is generated by our custom replaceJSRootName function. An alternative to reconfiguring Webpack is to add an extra parameter to the replaceJSRootName function, so that the caller defines jsName instead of auto-generating it.

I would personally be in favor of configuring Webpack to use the custom name, because I cannot imagine anyone wanting to use window['pdfjs-dist/build/pdf'] to import the JS variable.

Relevant Webpack documentation for configuring the library:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brendandahlcommented, Mar 15, 2018

I missed that we have three export like things now. In light of that, I’m in favor of Jonas’ suggestions of pdfjsLib, pdfjsViewer, pdfjsWorker.

1reaction
brendandahlcommented, Mar 12, 2018

I’m leaning towards keeping PDFJS and letting the version number be the indication of change. If we change the name this time it seems like we should change it every major release, which I’d rather not do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examples
This tutorial shows how PDF.js can be used as a library in a web browser. examples/ provides more examples, including usage in Node.js...
Read more >
How to use the pdfjs-dist/build/pdf.js.GlobalWorkerOptions ...
To help you get started, we've selected a few pdfjs-dist/build/pdf.js.GlobalWorkerOptions examples, based on popular ways it is used in public projects.
Read more >
How to import Mozilla PDF.js in Vue project? - Stack Overflow
I think the error occurs if pdfjsLib does not fall into the global scope , see also codesandbox : <template> <div id="pageContainer"> <div ......
Read more >
PDF.js 'Hello, world!' example - JSFiddle - Code Playground
var pdfjsLib = window['pdfjs-dist/build/pdf'];. 7. ​. 8. // The workerSrc property shall be specified. 9. pdfjsLib.GlobalWorkerOptions.
Read more >
Can't access 3rd party JS in Stimulus controller with Turbo ...
pdfjsLib = window["pdfjs-dist/build/pdf"]; ... } This works fine when Turbo Drive is off and the page reloads fully. However, if I have Turbo ......
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