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.

use viewer in atom package

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
allefeldcommented, Nov 25, 2019

building of a custom viewer

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?

without actually building it first

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

web/viewer.css
web/viewer.html
web/viewer.js
web/images/*
web/locale/locale.properties
web/locale/en-US/viewer.properties
build/pdf.worker.js
build/pdf.js

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.

0reactions
allefeldcommented, Nov 28, 2019

Thanks, the added text looks good!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HOW TO PREVIEW HTML & CSS IN ATOM (THE RIGHT WAY ...
HOW TO PREVIEW HTML IN ATOM EDITOR ⚛️ https://host.promo​ BEST HOST + FREE DOMAIN + 70% OFF ...
Read more >
Package: Active Editor Info - Atom Flight Manual
Enter active-editor-info as the name of the package. ... Atom uses the same view abstractions everywhere, so we can almost use the generated ......
Read more >
7 Atom Add-ons for Running Code and Previewing Changes
In this article, I'll introduce some packages for the code editor Atom, useful for previewing changes as you type (particularly for web ...
Read more >
Quick Tip: Set Up Local Previews With Atom
Once installed, open the HTML file you want to preview, then go to Packages > Preview HTML > Enable Preview. You'll then see...
Read more >
How to Set Up & Use Atom as a Markdown Editor - Portent
Atom has thousands of packages—think of them as plugins—available at https://atom.io/packages. You can install them using the package ...
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