I am working with Codeigniter and I successfully implemented dompdf for generating PDF files. Now I have issues on adding a header and footer in generated PDF.
Here is the my dompdf_helper code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->set_paper("A4");
if ($stream) {
$dompdf->stream($filename.".pdf",1);
} else {
return $dompdf->output();
}
}
?>
Here is the my controller to call PDF generation:
<?php
$data['store']=$res;
$this->load->helper(array('dompdf', 'file'));
$html = $this->load->view('store/sales_pdf', $data, true);
$html.= $this->load->view('footer');
$filename="salesbill".$id;
pdf_create($html, $filename);
$data = pdf_create($html, '', false);
write_file('name', $data);
?>
I use this script for getting page number but it printed only if second page is exits otherwise it won't print.
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(500,10, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
}
</script>
I want to print the company name and contact details and bill number as header in every page then in a footer. I want to add a page number like "1 of 3".