Generating .pdf popup using jsPDF library

QuestionsGenerating .pdf popup using jsPDF library
C3media asked 2 years ago

Hello, i have this code to generate .pdf popup:

// JSPDF auto generate pdf on edit
$grid["add_options"]["afterSubmit"] = 'function(response) {
if(response.status == 200)
{
if (response.responseText)
{
var data = JSON.parse(response.responseText);
if (data && data.msg)
fx_success_msg(data.msg,data.fade);
}

var rowid = jQuery("#list1").jqGrid("getGridParam","selrow");

var row = $("#list1").getRowData(rowid);

var cliente = row["customer"];

var llegada = row["staff_note"];

var minutos = row["reference_no"];

var total = row["total"];

var recobro = row["updated_at"];

var estado = row["sale_status"];

var pre_puntos = row["suspend_note"];

var puntos = parseInt(minutos) + parseInt(pre_puntos);

switch (estado) {
case "Completed":
total = recobro
break;

default:
total = row["total"]
break;
}
// 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]});

// set font size
doc.setFont("helvetica");
doc.setFontType("bold");
doc.setFontSize(16);
doc.setFontType("italic");
doc.text("SHOPPING EXPRESS",4,10);

doc.setFont("courier");
doc.setFontType("normal");
doc.setFontSize(14);
doc.text("NIT: 30238315-7",4,14);
doc.text("CC Nuestro Urabá",4,18);
doc.text("Apartadó, Antioquia.",4,22);

doc.text("————————",4,24);

doc.setFont("courier");
doc.setFontType("normal");
doc.setFontType("bold");
doc.setFontSize(12);
doc.text("Factura N°:" + row["id"],4,26);
doc.text("Tarifa minutos: " + row["reference_no"], 4, 30);
doc.text("Carro N°: " + row["attachment"], 4, 34);
doc.text("Salida:" + row["note"], 4, 38);
doc.text("Llegada:" + llegada, 4, 42);
doc.text("Estado: " + row["sale_status"], 4, 46);
doc.setFontType("normal");
doc.text("Subtotal: $" + total, 4, 50);
doc.setFontType("bold");
doc.text("Total: $" + total, 4, 54);
doc.setFontSize(6);
doc.setFontType("italic");
doc.text("Firma acudiente", 4, 57);

doc.text("_________________________________________________________", 4, 66);
doc.setFontSize(10);
doc.setFontType("bold");
doc.text(''+ row["customer"], 4, 72);
doc.text("Tus puntos disponibles: " + puntos, 4, 78);
doc.text("———————————-",4,81);

doc.autoPrint();

// this opens a new popup, after this the PDF opens the print window view

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");

return [true,""];
}
}';

But not works…

Thank you by your help!

3 Answers
Abu Ghufran answered 2 years ago

This demo popups pdf in new window (with autoprint) on submitting edit dialog and print button click.
https://gist.github.com/gridphp/dd5c7382e8eb859ab0716ca481509570

C3media answered 2 years ago

Hello Abu,

It´s just working for after editing, then we need it works after add row from form.

Thank you!

Abu Ghufran answered 2 years ago

For add submit, you need same code with:
$grid["add_options"]["afterSubmit"] = "…..";

Your Answer

16 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!