简体   繁体   中英

jsPDF show print page instead of downloading the file

hi i've an issue can anybody tell me how to display the print page in browser instead of downloading the file. i'm using jsPDF library.

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

here's an example code. when i run this it downloads the file but don't show the print page. all i want is to show the print page instead of downloading the file then printing it.

Thank You!!!

Just use 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>');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM