Open PDF from HTML5 Storage

假如想象 提交于 2019-12-11 03:26:35

问题


I want to store pdf files client side in one of the HTML5 storages (indexedDB or localstorage) and then open them later with the adobe reader.

The scenario is as follows:

  1. The user visites my site and downloads a bunch of pdf's into a storage
  2. Later the user revisits the site and wants to view one of the pre downloaded pdf's.
    He chooses one of the stored pdf's and it gets rendered with the adobe reader (or the default pdf renderer).

Is this possible with pure html5/js or do i have to write a firefox extension?


回答1:


You can use the data URI scheme (http://en.wikipedia.org/wiki/Data_URI_scheme).

Something like this, but with a PDF:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAKBJREFUeNpiYBjpgBFd4P///wJAaj0QO9DEQiAg5ID9tLIcmwMYsDgABhqoaTHMUHRxpsGYBv5TGqTIZsDkYWLo6gc8BEYdMOqAUQeMOoAqDgAWcgZAfB9EU63SIAGALH8PZb+H8v+jVz64KiOK6wIg+ADEArj4hOoCajiAqMpqtDIadcCoA0YdQIoDDtCqQ4KtBY3NAYG0csQowAYAAgwAgSqbls5coPEAAAAASUVORK5CYII=

You can see this example at its original page: http://iconhandbook.co.uk/reference/examples/data/




回答2:


Create links with PDF type and base64 encoded data (representing the PDF binary)

<a href="data:[<mime type>][;charset=<charset>][;base64],<encoded data>">PDF name</a>

The base64 encoded content can be stored in HTML5 storage.

Warning: does not work for IE (excuses for security reasons).



来源:https://stackoverflow.com/questions/26124025/open-pdf-from-html5-storage

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