I work with Codeigniter and I have successfully implemented dompdf to create PDF files. Now I am having problems adding the header and footer in the generated PDF file.
Here is 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 my controller to call the 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 to get the page number, but it is printed only if the second page comes out, otherwise it will not 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 account number as a title on each page, and then in the footer. I want to add a page number, for example "1 of 3".
codeigniter dompdf
user936565
source share