【发布时间】:2018-12-07 09:56:05
【问题描述】:
Chrome pdf viewer button is not working with jsPDF
我正在使用 jsPDF 生成 pdf,它工作正常。 Chrome 查看器 pdf 按钮不起作用。我尝试了许多不同的方法,但都没有成功。
在这里我想分享示例代码:
download() {
var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');
// Save the PDF
var string = doc.output('datauristring');
var iframe = "<iframe width='100%' height='100%' src='" + string + "'></iframe>"
var x = window.open();
x.document.open();
x.document.write(iframe);
x.document.close();
//doc.save('Test.pdf');
}
通过此代码,新选项卡已打开,但 chrome 查看器下载按钮不起作用。
那么有没有其他方法可以做到这一点。
【问题讨论】: