jsPDF显示打印页面而不是下载文件

jsPDF show print page instead of downloading the file

嗨,我有一个问题,谁能告诉我如何在浏览器中显示打印页面而不是下载文件。我正在使用 jsPDF 库。

var pdf = new jsPDF('p', 'mm', 'a4');
pdf.text(30, 30, 'Hello world!');
pdf.save('hello_world.pdf');

这是一个示例代码。 当我 运行 它下载文件但不显示打印页面。我只想显示打印页面而不是下载文件然后打印它。

谢谢!!!

只需使用 doc.output()

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?');

// Output as Data URI
 doc.output('datauri');

CHROME

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?');

var base64string = doc.output('datauristrlng');
debugBase64( base64string );

function debugBase64(base64URL){
    var win = window.open();
    win.document.write('<iframe src="' + base64URL  + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
}