Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an offline version of pdf.js by combiing pdf.js and pdf.worker.js

I am attempting to create a javascript pdf reader that can work offline in the browser (it uses the browser but not the internet), and am using Mozilla's pdf.js to do it. Pdf.js has a main file of the same name, which uses the internet to inject script from a pdf.worker.js file. One obstacle to creating an offline version of pdf.js is to stop it from using the internet to do this, by either pasting the pdf.worker.js code into the parts of pdf.js code that ask for it, or to convert the pdf.worker.js into a Data URI and use that as the url that pdf.js asks for. Doing the former has not yielded any success, and doing the latter has only worked on Firefox. We want this to work any way we can make it work, so I have pretty much two questions pertaining to making pdf.js offline.

1) If I am going with the method of physically pasting pdf.worker.js code into the spots where pdf.js uses the internet to inject pdf.worker code in, how would I make it work? I tried doing it, and I couldn't get it to work. Are there any things I must pay attention to?

2) I have had more success with converting pdf.worker.js into a Data URI and having pdf.js use that instead of the url it was using to access worker.js. However, this process only works on Firefox. Any idea why? And, do you know of a way I can make this process work with the other browsers?

Any input is welcome. Thanks in advance!

like image 872
user3735903 Avatar asked Sep 03 '25 16:09

user3735903


1 Answers

  • Go to https://github.com/mozilla/pdf.js/
  • Follow the instructions in "Getting the Code" and "Building PDF.js"
  • Then run node make singlefile
  • Combined file will be in build\singlefile\build\pdf.combined.js

Worked for me on Windows. Should work on other platforms too.

like image 79
Philip Beber Avatar answered Sep 05 '25 06:09

Philip Beber