I have this code to generate my PDF files using jsPDF library:
// JSPDF, docs: http://rawgit.com/MrRio/jsPDF/master/docs/global.html
// Default export is a4 paper, portrait, using milimeters for units
var doc = new jsPDF()
// set font size
doc.setFontSize(12);
doc.text("Invoice #" + row["client_id"],10,10);
doc.text("Name: " + row["name"],10,14);
doc.text("Gender: " + row["gender"], 10, 18);
doc.text("Company: " + row["company"], 10, 22);
//doc.save("a4.pdf");
doc.autoPrint();
doc.output("dataurlnewwindow");
¿It´s possible to open in modal window?
Using this script:
$.ajax({
type : "POST",
url : getPrintablePDF,
dataType : "json",
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(params),
success : function(data) {
var myResponse = eval(data);
$("<iframe />") // create an iframe
// add the source
.attr('src', 'data:application/pdf;base64,' + myResponse.base64EncodedResponse)
.appendTo('.modal-body'); // append to modal body or wherever you want
}});
Thank you!
function print_row()
{
//Logic to print the item
var YourVar= My var value;
// JSPDF, docs: http://rawgit.com/MrRio/jsPDF/master/docs/global.html
// Default export is a4 paper, portrait, using milimeters for units
var doc = new jsPDF({orientation: 'portrait', unit: 'mm', format: [210, 80]});
doc.setFont("helvetica");
doc.setFontType("bold");
doc.setFontSize(16);
doc.setFontType("italic");
doc.text("Your text "+ YourVar, 4, 10);
doc.autoPrint();
// doc.save("a4.pdf");
// this opens a new popup, after this the PDF opens the print window view
// doc.output("bloburi");
window.open(doc.output('bloburl'), '_blank',"toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes,top=200,left=350,width=600,height=400");
};
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