开发者

Rendering PDF on WebPage

开发者 https://www.devze.com 2022-12-25 02:40 出处:网络
We are trying to load a pdf file in web browser using pdfobject javascript api. Currently the size of the pdf\'s that we are trying to display is close to 10MBs. This creates a long delay in displayin

We are trying to load a pdf file in web browser using pdfobject javascript api. Currently the size of the pdf's that we are trying to display is close to 10MBs. This creates a long delay in displaying a PDF on web page; while the complete PDF gets downloaded.

We need to remove this lag by achieving either of the alternatives:

  • Show a progress bar until the PDF is actually displayed. We couldn't find an event which is triggered and can be used to find out if pdf is visible now. This lacking doesn't let us decide when to stop showing progress bar/spinner
  • OR lazy load the PDF such that it gets displayed as soon as first page gets loaded. With that ateast user will have a visual indication as to something is happening. We couldn'find anything in pdf object that lets us do a lazy load.
  • User alternative pdf rendering api; this is a low priority as we already have comple开发者_StackOverflow中文版te code in place; but in an event of first 2 alternatives not being met; we'd have to consider this option. So please feel free to suggest.

Any other ideas as to how user interaction can be made more intuitive or pleasant; would be welcome.

Cheers


You might consider using something like Google Documents to show your PDF to your users. I don't know if it is applicable to your situation. You can use it to show external PDFs (PDF files not saved in Google Documents). It comes with a progress bar built-in so even if the loading takes long...

See: http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html


Option 3:

I had a similar situation. My pdfs were more big (100 MB or more). I used Ghostscript to create jpeg/png previews. The process is very cpu intensive and required disk access. But the users were very happy: they could preview very big pdf pages in few seconds.


Nowadays, browsers (and CPUs!) are powerful enough to render PDF using nothing but Javascript, and there are projects taking advantage of that.

Notably https://mozilla.github.io/pdf.js/

As for lazy load, it appears you can display the first page of a document before it has loaded: PDF JS - Lazy load?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号