mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.25k stars 9.96k forks source link

examples(HTML) not working #15334

Closed OilPrince closed 2 years ago

OilPrince commented 2 years ago

Attach (recommended) or Link to PDF file here: compressed.tracemonkey-pldi-09.pdf

Configuration:

Steps to reproduce the problem:

  1. From github, download 'pdfjs-2.15.349-dist.zip' and 'pdf.js-master.zip'
  2. Copy the directories 'examples' and 'web' of pdf.js-master.zip to 'ROOT' of Tomcat webapp
  3. Copy the directories 'build' and 'web' of pdfjs-2.15.349-dist.zip to 'ROOT' of Tomcat webapp (overwrite)
  4. Change path(js and css) in .html and .js
  5. Open web page(ex: ~/examples/components/pageviewer.html, ~/examples/mobile-viewer/viewer.html) in Tomcat
  6. Error occurs and check the desc in F12 Dev Tools Uncaught SyntaxError: Cannot use import statement outside a module viewer.js:18 Uncaught ReferenceError: pdfjsViewer is not defined at viewer.js:18:31

What is the expected behavior? (add screenshot) The web page(~/examples/components/pageviewer.html, ~/examples/mobile-viewer/viewer.html) works properly!

What went wrong? (add screenshot) Where is js relating [pdfjsViewer]? I can't find 'pdfjsViewer'

How do example HTMLs work without errors?

I look forward to a good answer.

Snuffleupagus commented 2 years ago

Steps to reproduce the problem:

In general please note https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.


5. Open web page(ex: ~/examples/components/pageviewer.html, ~/examples/mobile-viewer/viewer.html) in Tomcat

Those examples are intended for the "viewer components", which are distributed through the pdfjs-dist repository; please refer to https://github.com/mozilla/pdfjs-dist/tree/master/web (Hence the releases found at https://mozilla.github.io/pdf.js/getting_started/#download cannot be used together with the mentioned examples.)

kwisatz commented 1 year ago

Those examples are intended for the "viewer components", which are distributed through the pdfjs-dist repository; please refer to https://github.com/mozilla/pdfjs-dist/tree/master/web (Hence the releases found at https://mozilla.github.io/pdf.js/getting_started/#download cannot be used together with the mentioned examples.)

I just stumbled into the same pit and I can't really say I understand what the difference is between the releases and the viewer components ?

It might also be worth mentioning that there no longer is any pdfjs-dist package within node_modules.

I can see now that there are two distinct repos, pdf.js and pdfjs-dist, but the version of pdf.js inside pdfjs-dist seems very old.