如何从Chrome打包的应用启动PDF? [英] How to Launch a PDF from a Chrome Packaged App?

查看:98
本文介绍了如何从Chrome打包的应用启动PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的chrome打包应用程序包含PDF,我想让用户查看它.如果在当前框架中打开它,则会出现错误不允许使用Chrome PDF Viewer".

My chrome packaged app contains a PDF, and I would like to let the user view it. If I open it in the current frame I get the error "Chrome PDF Viewer is not Allowed".

坦率地说,chrome PDF查看器非常糟糕,因此无论如何我还是希望用户在他们选择的PDF查看器中查看它.如果我禁用chrome PDF插件(仅作为实验),并且尝试使用chrome.app.window.open打开PDF,它将下载" PDF,然后用户可以打开它.但这有两个问题:

Frankly, the chrome PDF viewer is pretty awful, so I'd rather let the user view it in their PDF viewer of choice anyway. If I disable the chrome PDF plugin (just as an experiment) and I try to open the PDF using chrome.app.window.open, it "downloads" the PDF, and then the user could open it. But this has two issues:

  1. 我无法现实地使用户转到chrome://plugins并禁用该功能
  2. 没有任何浏览器窗口,因此用户不知道下载发生了

有什么建议吗?打开嵌入在我的应用程序中的PDF是该应用程序的必备功能.

Any suggestions? Opening PDFs that are embedded in my app is kind of a must-have feature for this app.

推荐答案

我已经完成了这项工作,但是对于您来说这是否是解决方案在很大程度上取决于您的用例.该解决方案包括三个部分:

I've got this working, but whether it is a solution for you depends a lot on your use case. The solution has three parts:

  1. 使用pdfjs进行实际渲染.

要使其在打包的应用程序中运行,您需要对国际化支持进行一些暴力操作.即使这样做了,您仍然会发现一些PDF毫无理由地拒绝加载.因此,请不要试图使pdfjs在打包的应用程序中工作.只是:

To get this running in a packaged app, you'd need to do some violence to the internationalization support. And even after you do that, you'll find that some PDFs refuse to load for no apparent reason whatsoever. So don't bother trying to make pdfjs work in a packaged app. Just:

  1. 将整个应用程序放入具有持久分区的<webview>中,并使用HTML5缓存清单使所有文件可供脱机查看.
  1. Put your entire app into a <webview> with a persist partition, and use a HTML5 cache manifest to get all your files available for offline viewing.

是的,是的,我知道缓存清单不再很酷.但是,如果您可以列出所有文件以供打包的应用程序使用,那么您正在做一种情况,即缓存清单确实可以很好地发挥作用.

Yeah, yeah, I know that cache manifests are not cool anymore. But if you can list all your files for use in a packaged app, then you are doing the one case where cache manifests actually work great.

  1. 然后使用打包的应用在其中包含Web视图的页面上分布一个小的包装.

您还将获得不必重写应用程序即可在严格打包的应用程序规则(eval,sync xhr,2GB限制等)中使用的好处.

You'll also get the benefit that you don't have to rewrite your app to live within the draconian packaged app rules (eval, sync xhr, 2GB limit, etc.).

您可以在m.kaon.com/c/ka上看到一个工作示例(使用Chrome浏览器获取桌面应用程序;如果使用Firefox访问该应用程序,则可以访问使用该应用程序的托管应用程序技巧). PDF位于底部的为什么选择Kaon"部分.

You can see a working example at m.kaon.com/c/ka (visit with Chrome to get the desktop app; if you visit that with Firefox, you'll get access to a hosted app that is using the same tricks). PDFs are down in the bottom "Why Choose Kaon" section.

这篇关于如何从Chrome打包的应用启动PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆