如何在浏览器中使用BASE64键打开PDF [英] How to open PDF using the BASE64 key in the browser

查看:1200
本文介绍了如何在浏览器中使用BASE64键打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到许多使用base64打开PDF的参考.什么都没有为我工作.

I have seen a number of references to open the PDF using the base64. Nothing is working for me.

我尝试使用window.open('data:application/pdf;base64,' + base64data);,但是它只是在浏览器中显示空白页面.

I tried using window.open('data:application/pdf;base64,' + base64data); but it's just showing the empty page in the browser.

如果将base64data保留在iFrame标记中,则可以查看pdf.根据我的要求,我需要在新标签中打开此PDF.

I can able to view the pdf if I keep the base64data in iFrame tag. For my requirement, I need to open this PDF in the new tab.

请帮助我解决此问题.

推荐答案

尝试此代码

let pdfWindow = window.open("")
pdfWindow.document.write("<iframe width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(base64data) + "'></iframe>")

这篇关于如何在浏览器中使用BASE64键打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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