admin管理员组文章数量:1326088
I'm working on generating pdfs that contain the image from a html canvas element. I've managed to get an implementation of that working, but I'm having trouble opening the result in a useful way.
PDF.dataURI() returns a string that looks like data:application/pdf;base64,BASE64_ENCODED_PDF_HERE
.
I'm currently using window.location = certificate.dataURI()
to open up the pdf. I already tried window.open
, but Safari wouldn't play nice with it.
RESULTS:
In Firefox, this saves a file that is a random name, followed by .pdf(1).part. In Safari (desktop and mobile), it opens the PDF in the same tab, but doesn't bring up any pdf viewer interface. In Chrome, it opens the PDF in the same tab and brings up the PDF interface.
Basically, my question is how to open a string of that format inside of the browser as a PDF, ideally in a new tab.
Any thoughts?
I'm working on generating pdfs that contain the image from a html canvas element. I've managed to get an implementation of that working, but I'm having trouble opening the result in a useful way.
PDF.dataURI() returns a string that looks like data:application/pdf;base64,BASE64_ENCODED_PDF_HERE
.
I'm currently using window.location = certificate.dataURI()
to open up the pdf. I already tried window.open
, but Safari wouldn't play nice with it.
RESULTS:
In Firefox, this saves a file that is a random name, followed by .pdf(1).part. In Safari (desktop and mobile), it opens the PDF in the same tab, but doesn't bring up any pdf viewer interface. In Chrome, it opens the PDF in the same tab and brings up the PDF interface.
Basically, my question is how to open a string of that format inside of the browser as a PDF, ideally in a new tab.
Any thoughts?
Share Improve this question asked Jul 18, 2012 at 15:43 Will StamperWill Stamper 511 silver badge2 bronze badges 2- 1 Did you already have a look at pdf.js? – Marcel Korpel Commented Jul 19, 2012 at 17:27
- 1 Is it a problem if you sent it to the server and have it serve a normal version of the document? – Madara's Ghost Commented Aug 10, 2012 at 11:59
2 Answers
Reset to default 4You can use iframes to view the pdf like below
<object data="data:application/pdf;base64, your_base64_data" type="application/pdf">
<iframe src="https://docs.google./viewer?&embedded=true"></iframe>
</object>
have you tried document.location.href
?
you can try to control UI interface for PDF viewer from appropriate options inside generated pdf but browser may ignore it, so as al
本文标签: javascriptOpening a Base64 encoded PDF in native pdf viewerStack Overflow
版权声明:本文标题:javascript - Opening a Base64 encoded PDF in native pdf viewer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742194190a2430771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论