javascript - 如何在Angular 8中使用base64 pdf字符串显示pdf?
问题描述
我正在使用 Angular 8 获取带有 iframe 的 base64 pdf 字符串以在新选项卡中打开,但它没有在 Internet Explorer 中打开,在 IE 中显示空白页面。所以我不想使用 iframe 打开 pdf。谁能帮我在 IE 中显示 base64 pdf 字符串。
解决方案
萨拉姆伴侣,
您应该首先将 Base64 转换为 blob,您可以按照此问题中的说明进行操作:
在 JavaScript 中从 Base64 字符串创建 BLOB
然后您应该使用 [window.URL.createObjectURL(fileblob)] 将您的 blob 转换为 URL,然后创建锚点并单击它,如下所示:
var fileblob = b64toBlob('<your_base64>', 'application/pdf');
var url = window.URL.createObjectURL(fileblob);
let anchor = document.createElement("a");
anchor.href = url;
anchor.target = "_blank"
anchor.click();
推荐阅读
- c++ - 类模板中的多个可选成员,无需开销
- redis - 使用 Jredisearch 创建索引时添加前缀
- javascript - 从 csv 添加数字
- android - 来自 IntentService 的启动活动在 Android 12 中不起作用
- node.js - 反应生产 npm 运行命令以代码 0 退出
- javascript - 我的请求在 Postman 中有效,而不是在浏览器中(React、Node、Cloudinary)
- mysql - 如何使用 SQL 获取列中某个值的百分比?
- c# - 顶级委托引用无法解析
- python - pandas.series.diff 奇怪的输出
- java - 在 Windows 上使用 Jar 文件启动 JMeter 时出现白色空白屏幕