How to load PDF pages asynchronously?

1.7k Views Asked by At

I'm looking for a pdf viewer that can load a pdf asynchronously. This is a big need in our site since the PDF documents have at least 50 pages.

I've already looked into pdf.js by mozilla but I can't seem to make it work (I think the examples are broken)

Any help would greatly be appreciated! Thanks!

UPDATED: Got it working but my solution was messy. I integrated the web/viewer codebase of the pdf.js repo in my site. So whenever I need to view a pdf, I just used an iframe with a source #{pdf_viewer_path}?file=#{file_path}.

Is there a better solution than this?

NOTE: The above method does not work in a production setting. There are some js errors showing up when displaying the page. The only way I got it to work is to not precompile the js files of pdf.js.

1

There are 1 best solutions below

0
On

This is an experimental solution. I just compiled the mozilla pdf.js library and integrated it with a rails engine. You can use the gem I made here: https://github.com/normancapule/pdfjs-rails-engine.