在网页上渲染 PDF
我们正在尝试使用 pdfobject javascript api 在网络浏览器中加载 pdf 文件。目前我们尝试显示的 pdf 大小接近 10MB。这会导致网页上显示 PDF 时出现较长的延迟;同时下载完整的 PDF。
我们需要通过实现以下任一替代方案来消除这种延迟:
- 显示进度条,直到 PDF 实际显示为止。我们找不到被触发且可用于查明 pdf 现在是否可见的事件。缺少这一点并不能让我们决定何时停止显示进度条/旋转器
- 或延迟加载 PDF,以便在加载第一页时立即显示它。有了这个 ateast,用户就会有一个关于正在发生的事情的视觉指示。我们在 pdf 对象中找不到任何可以让我们进行延迟加载的内容。
- 用户替代pdf渲染api;这是一个低优先级,因为我们已经有了完整的代码;但如果前两种选择不满足;我们必须考虑这个选择。所以请随意提出建议。
关于如何使用户交互更加直观或愉快的任何其他想法;将受到欢迎。
干杯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以考虑使用 Google 文档之类的工具向用户展示您的 PDF。不知道是否适用于你的情况。您可以使用它来显示外部 PDF(未保存在 Google 文档中的 PDF 文件)。它带有内置进度条,因此即使加载时间较长...
请参阅:http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html
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
选项3:
我也遇到过类似的情况。我的 pdf 更大(100 MB 或更多)。
我使用 Ghostscript 创建 jpeg/png 预览。该过程非常消耗 CPU 资源,并且需要磁盘访问。但用户非常高兴:他们可以在几秒钟内预览非常大的 pdf 页面。
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.
如今,浏览器(和 CPU!) 的功能已经足够强大,只使用 Javascript 即可渲染 PDF,并且有一些项目正在利用这一点。
值得注意的是 https://mozilla.github.io/pdf.js/
至于延迟加载,看来您可以在加载文档之前显示文档的第一页: PDF JS - 延迟加载?
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?