I'm having an issue when trying to do a preview of a PDF file generated using jsPDF API, when I add more than 3 images to the document (each one of 300-400KB) I can download the document correctly, but I cannot display it in the browser using the jsPDF method: doc.output('dataurlnewwindow'). A new tab is being opened on my web browser but it's blank (and at the top of the tab it states "charging..." but its never displayed. However, I can download the PDF file without any issue to my PC using jsPDF method: doc.save( this.reportFileName );
Do you have any idea of why this is happening? could be an issue related to the size of the PDF file that I need to preview in the web browser? is there any maximum size for doing this? Any help would be really appreciated.
Thanks!
this.doc = new jsPDF({orientation: "p", unit: "pt", format: "a4"})
// ....
// doing some stuff in the doc file
// adding images of 400 KB aprox. (it works with 3 images... but with 4 or more doesn't
this.doc.addImage('data:image/jpeg;base64,'+ logoFooter, 'JPEG', this.marginLeft+40, 794, 40, 45);
// ....
preview () {
try {
this.doc.output('dataurlnewwindow'); // >> doesn't work and an empty tab is being opened in muy web browser
}
catch(error){
console.log(error);
}
save () {
try {
this.doc.save( this.reportFileName ); // this works fine and the PDF file is being downloaded
}
catch(error){
console.log(error);
},
well, I found the solution here: https://github.com/parallax/jsPDF/issues/300#issuecomment-49363483
summary... doing the following:
var blob = this.doc.output("blob");
window.open(URL.createObjectURL(blob));
thanks for your help!