Custom pdf render.

QuestionsCustom pdf render.
Montemaggiore Sebastian asked 3 years ago

Hello community!!. I use pdf export with "render_type" = html. Here is my code:


$grid["export"] = array("format"=>"pdf", "filename"=>"pedidos", "heading"=>"Pedidos", "orientation"=>"landscape", "paper"=>"a4");
$grid["export"]["render_type"] = "html";
$grid["export"]["range"] = "filtered";

$e["on_render_pdf"] = array("set_pdf_format", null);

// Esta función de callback permite actuar al capturar el evento "on_render_pdf".
function set_pdf_format($param)
{
$grid = $param["grid"];
$arr = $param["data"];
$pdf = $param["pdf"];

$pdf->SetFont('helvetica', 'B', 11);

$html .= "<h1>".$grid->options["export"]["heading"]."</h1>";
$html .= '<table border="0" cellpadding="4" cellspacing="2">';
$i = 0;
$j=0;
foreach($arr as $v)
{
$shade = ($i++ % 2) ? 'bgcolor="#efefef"' : '';
$html .= "<tr>";
foreach($v as $d)
{
if ($i == 1)
switch ($j)
{
case 0:
$html .= "<td width="50" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 1:
$html .= "<td width="130" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 2:
$html .= "<td width="150" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 3:
$html .= "<td width="80" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 4:
$html .= "<td width="75" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 6:
$html .= "<td width="90" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 7:
$html .= "<td width="70" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
case 11:
$html .= "<td width="70" bgcolor="lightgrey"><strong>$d</strong></td>";
break;
default:
$html .= "<td width="60" bgcolor="lightgrey"><strong>$d</strong></td>";
}
else
$html .= "<td $shade>$d</td>";
$j = $j+1;
};
$html .= "</tr>";
};
$html .= "</table>";
return $html;
};

Does someone know why this line "$pdf->SetFont('helvetica', 'B', 11);" doesn't work?.
Thanks!!.

2 Answers
Montemaggiore Sebastian answered 3 years ago

In fact, when i use $grid["export"]["render_type"] = "html"; none sentence of the PDF format customization API works.

Abu Ghufran answered 3 years ago

You are right, in lib $pdf is instantiated after the event.

You can edit lib/inc/jqgrid_dist.php and search/replace this:
$pdf->SetFont('helvetica', '', 12);

Your Answer

14 + 9 =

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:

As you found this post useful...

Follow us on social media!

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

Let us improve this post!