jsPDF - 如何将 doc.output('dataurlnewwindow') url 标题重命名为“doc.pdf”

Kev*_*nto 1 jspdf

在jsPDF中使用doc.output('dataurlnewwindow')时,窗口的标题是一个随机抽象的url字符串。实际上是否可以根据网站域名后跟文件名重命名 url,例如 doc.pdf?

在此处输入图片说明

谢谢!

小智 7

对我来说,这就是我管理这个的方式。我创建了自己的自定义页面,我希望在其中显示 pdf,并在其中添加了逻辑。所以网址会是这样的http://example.com/pdfpage

设置一些关于 pdf 标题、作者等的属性,并创建一个带有 text/html 数据的 iframe。由于您将调用此页面,因此您可以将其称为带有 target="_blank" 的链接,并且在 pdf 输出中,您将使用“datauristring”,如下所示。

pdf.setProperties({
    title: 'PDF Title',
    subject: 'Info about PDF',
    author: 'PDFAuthor',
    keywords: 'generated, javascript, web 2.0, ajax',
    creator: 'My Company'
});

var iframe = document.createElement('iframe');
iframe.setAttribute('style','position:absolute; top:0;bottom:0;right:0;left:0; height:100%; width:100%');
document.body.appendChild(iframe);
iframe.src = pdf.output('datauristring');
pdf.save('doc.pdf'); /* download the file immediately on loading */
Run Code Online (Sandbox Code Playgroud)