Skip to content Skip to sidebar Skip to footer

How To Launch A Pdf From A Chrome Packaged App?

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'. Frankly, the

Solution 1:

I've looked at this extensively, and have come to the conclusion that there's no way to get a Chrome App to open a PDF that's local. I, too, have tried data URIs.

I don't think the issue is the PDF support in the window, as it's still Chrome, or the size of the PDFs. Rather, I think it's just an engineering problem, one that might get solved someday.

As for me, I build the PDF in my Chrome App. Since I can't display it, and there's no server to upload it to, I write it to a file of the user's choosing and let the user deal with it on his/her own.

Solution 2:

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. Use pdfjs to do the actual rendering.

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. 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. Then use a packaged app to distribute a tiny wrapper around your page with the webview in it.

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.).

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.

Post a Comment for "How To Launch A Pdf From A Chrome Packaged App?"