Rendering PDF on WebPage

浪子不回头ぞ 提交于 2019-12-22 08:36:18

问题


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 complete 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


回答1:


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




回答2:


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.




回答3:


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?



来源:https://stackoverflow.com/questions/2559054/rendering-pdf-on-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!