Skip to content Skip to sidebar Skip to footer

Jspdf Create Pdf From .html And Open In New Window

I am trying to use jsPDF to convert a .html file to PDF and open it in a new window. I am gnerating de PDF like this: function PDFFromHTML() { var doc = new jsPDF(); // We

Solution 1:

From what I can tell, there isn't much documentation on the APIs other than looking directly at the codes and existing examples.

I am able to get the PDF file to open in a new window by adding a call to the output API after doc.fromHTML(..), specifying the dataurlnewwindow argument like this:

doc.output('dataurlnewwindow');

As to why doc.fromHTML('ticket.html') doesn't work, again referring to the code, the source argument needs to be:

either a HTML-formatted string, or a reference to an actual DOM element.

So you may have to use the jquery $.get() method to load in the content of ticket.html. Essentially, something that looks like:

$.get('ticket.html', function(content){
    doc.fromHTML(content), 15, 15, {'width': 170, 'elementHandlers': specialElementHandlers});
    doc.output('dataurlnewwindow');
}, 'html');

Post a Comment for "Jspdf Create Pdf From .html And Open In New Window"