0

I implemented with success domPDF (barryvdh-DOMPDF Wrapper for Laravel) in my Laravel 5 project.

The report is rendering fine, but I was unable to add to my PDF report parameters (like in CodeIgniter): PAGE_NUM, PAGE_COUNT, date and other stuff in the header or footer of the report.

Do you have any solutions to this issue?

My code in Laravel 5:

$data['company'] = Company::find($company_id)->name;
$dompdf = PDF::loadView('admin.inputs.report',$data)->setPaper('A4');

In CodeIgniter was simple to insert a header:

$canvas = $this->dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
$canvas->page_text(36, 18, "Page: {PAGE_NUM} from {PAGE_COUNT}", $font, 6, array(0,0,0));
return $dompdf->stream('invoice.pdf');
Mario Ene
  • 843
  • 1
  • 10
  • 22

1 Answers1

2
  1. Enable PHP in your dompdf (version: 0.6.*, domPDF)

Change DOMPDF_ENABLE_PHP to true in dompdf.php config (file path: "...\vendor\barryvdh\laravel-dompdf\config").

  1. Add lines to your pdf view:
<script type="text/php">
 $text = 'page: {PAGE_NUM} / {PAGE_COUNT}';
 $font = Font_Metrics::get_font("helvetica", "bold");
 $pdf->page_text(36, 18, $text, $font, 9);
</script>
Mario Ene
  • 843
  • 1
  • 10
  • 22