rkusa / pdfjs

A Portable Document Format (PDF) generation library targeting both the server- and client-side.
MIT License
774 stars 142 forks source link

Trouble creating local build of playground due to absolute paths to logo.pdf and opensans.ttf #270

Open jamesmarchment opened 2 years ago

jamesmarchment commented 2 years ago

Hi,

Apologies if this is just caused by my own error or unfamiliarity with npm, but when trying to recreate the Playground locally I ran into a bunch of problems... and then sorted them out by making a very small change to the code.

I kept getting 404s and failed fetch requests on "logo.pdf" and "opensans.ttf" until I opened playground.js and saw that on lines 100-103 the paths are absolute:

const fixtrues = [ fetch('/logo.pdf'), fetch('/opensans.ttf'), ]

So I changed them to relative paths:

const fixtrues = [ fetch('./logo.pdf'), fetch('./opensans.ttf'), ]

...and after repeating the npm build process it worked fine. I think this isn't a problem on http://pdfjs.rkusa.st/ because there it is in a root directory, but when running it in a folder it causes an error that stops the whole thing from working. Again, sorry if this is the kind of thing that doesn't present a problem for more experienced developers, but I in my noob-ness got really hung up on it for a while before I discovered the cause.

rkusa commented 2 years ago

You are right, fetching the assets from root will cause an error when opening the playground from e.g. a file:/// path. When I test the playground locally I usually do the following:

cd playground/public
python3 -m http.server