本文介绍了在下载使用Chrome PDF查看器打开的PDF时设置默认文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的角度应用程序具有一个可呈现PDF的iframe:
My angular app has an iframe that renders a PDF:
<iframe ng-src="{{PCtrl.docSrc}}" type="application/pdf" ...></iframe>
docSrc是作为BASE64编码的字符串生成的,类似于:
docSrc is generated as a BASE64 encoded string, something like:
Chrome可以很好地呈现嵌入式PDF.单击下载即可下载PDF,然后将向用户显示另存为"对话框. Chrome PDF查看器提供的默认文件名为"download.pdf",该如何更改?
Chrome renders the embedded PDF just fine. The PDF can be downloaded clicking on download, and the user will be presented with a "save as" dialog. The default filename given by the Chrome PDF viewer is "download.pdf", how do I change it?
推荐答案
window.onload = () => {
let blob = new Blob(["file"], {
type: "text/plain"
});
let url = URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = "file.txt";
document.body.appendChild(a);
console.log(url);
a.click();
}
也许这会对您有所帮助
这篇关于在下载使用Chrome PDF查看器打开的PDF时设置默认文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!