🏠 back to Observable

pdf.js in Observable?

#1

I would like to put up a view to a PDF file, but I haven’t figured out how to require all the components.

Here’s amy attempt:

I started by trying to follow this JSFiddle example, Which calls in pdf.js, but
pdf.js is not npm, so I have to find a work-around to requiring.

pdfjs =  require('https://mozilla.github.io/pdf.js/build/pdf.js').catch(() => window.pdfjs)

… appears to work, but the JSFiddle example returns Error: No "GlobalWorkerOptions.workerSrc" specified.

pdf-dist.js is on npm, and can be required:

require('pdfjs-dist@2.0.943/build/pdf.js')

… But using this doesn’t make the error go away.

There are some discussions online about workarounds and alternative approaches. For example, one thread suggests explicitly requiring the 'worker. I tried:

PDFJSWorker =  require('https://mozilla.github.io/pdf.js/build/pdf.worker.js').catch(() => window.PDFJSWorker)

but no dice.

Any insights?

[sorry for the many edits; I accidentally hit ‘submit’ early in drafting this question…]

#2

Trying to recreate Mozilla’s helloworld example, I have managed to boil this all down better:

… still haven’t made it work yet, but resolved nearly all errors. Happy for help to get over this last hurdle!

#3

Hope this helps:

3 Likes
#4

Thanks Fabian! It certainly does!!