So, I have dynamically created a pdf, and now i want to print it:
var doc = new jsPDF();
var name = "Doe, John"
doc.setFontType("normal");
doc.setFontSize(12);
doc.text(20,20,'Name: '+ name);
//do something that prints the pdf...
So, how do I take this doc variable and print it. Everywhere else I found uses the url of the pdf. Do I need to create a url for it first?
So, the solution I am currently going with is to show the pdf in a new tab/window, from which the pdf can be printed.
window.open(doc.output('datauristring'));
Unfortunately, this only works in Chrome. Anyone know how to get it working in IE, Firefox, Safari, etc.?
I still wonder if there is a way to skip this step (of opening the pdf and then requiring another button to be pushed).
There is a method autoPrint()
provided by jsPDF library.
You can use that as shown below
var doc = new jsPDF();
var name = "Doe, John"
doc.setFontType("normal");
doc.setFontSize(12);
doc.text(20,20,'Name: '+ name);
doc.autoPrint();
//This is a key for printing
doc.output('dataurlnewwindow');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With