Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open generated pdf using jspdf in new window

I am using jspdf to generate a pdf file. Every thing is working fine. But how to open generated pdf in new tab or new window.

I am using

doc.output('datauri'); 

Which is opening the pdf in same tab.

like image 566
Satendra Jindal Avatar asked Jul 19 '13 06:07

Satendra Jindal


2 Answers

Based on the source you can use the 'dataurlnewwindow' parameter for output():

doc.output('dataurlnewwindow'); 

Source in github: https://github.com/MrRio/jsPDF/blob/master/jspdf.js#L914

All possible cases:

doc.output('save', 'filename.pdf'); //Try to save PDF as a file (not works on ie before 10, and some mobile devices) doc.output('datauristring');        //returns the data uri string doc.output('datauri');              //opens the data uri in current window doc.output('dataurlnewwindow');     //opens the data uri in new window 
like image 94
kardave Avatar answered Sep 24 '22 09:09

kardave


I have to use this to load the PDF directly. Using doc.output('dataurlnewwindow'); produces an ugly iframe for me. Mac/Chrome.

  var string = doc.output('datauristring');   var x = window.open();   x.document.open();   x.document.location=string; 
like image 30
William Entriken Avatar answered Sep 21 '22 09:09

William Entriken