use viewer in atom package
See original GitHub issueI’m developing an Atom package including a PDF viewer, and I’m trying to do that based on pdf.js. My package inserts an iframe
into its view, and loads viewer.html
into it.
As a first test, I loaded https://mozilla.github.io/pdf.js/web/viewer.html
into the iframe
, and that worked perfectly, both with the hardlinked pdf and with local files.
But I don’t want to depend on Internet access, so I made my package depend on pdfjs-dist.
First problem: Unlike pdf.js, pdfjs-dist does not contain viewer.html
under web/
. I’ve read the remark
However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.
and that that is the reason not to include it, but I honestly intend to reskin the viewer, that in itself is not a reason not to include it. Moreover, if that’s the reason, then the viewer JavaScript and CSS should not be included either.
My solution was to download viewer.html
from pdf.js. I had to adjust some paths in the HTML, and add a dependency on systemjs, and download systemjs.config.js
.
Unfortunately, now I’ve run into a second problem I don’t know how to fix:
pdfjs.js:23 Uncaught ReferenceError: require is not defined
at Object.defineProperty.value (pdfjs.js:23)
at __w_pdfjs_require__ (bootstrap:19)
at Object.pdfjsLib (annotation_layer_builder.js:1)
at __w_pdfjs_require__ (bootstrap:19)
at Object.defineProperty.value (pdf_viewer.component.js:17)
at __w_pdfjs_require__ (bootstrap:19)
at Object.defineProperty.value (bootstrap:83)
at bootstrap:83
at webpackUniversalModuleDefinition (universalModuleDefinition:9)
at universalModuleDefinition:10
Can you tell me how to fix this?
Or, is there something fundamentally wrong in how I approach this?
Configuration:
- Atom 1.41.0
- Debian GNU/Linux 10.2
- PDF.js version: pdfjs-dist 2.3.200
- Is a browser extension: no
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
I’m afraid building a custom viewer is a bit beyond my abilities, at least for the moment. Moreover, examples only get you so far if the API exposed by
viewer.js
is basically undocumented.Is there a problem with me using
viewer.html
in my own project, as long as I re-skin it?As far as I understand, pdfjs-dist contains a pre-built version.
I got it working for now by a combination of scraping from
https://mozilla.github.io/pdf.js/web/viewer.html
and downloading select files from the official repository pdf.js. (Btw., does that mean that pdfjs-dist is unofficial?)I ended up with the files
Is this actually everything I (could possibly) need? The two directories contain many more files…
It would be great if you could tell me which files exactly I would have to include from the repository in my code to be sure everything works.
Thanks, the added text looks good!