In order to convert HTML data into a pdf file here are the followings steps you need to follow:
Step 1: Download the DOMPDF file from Github. here is the link
https://github.com/dompdf/dompdf
or you can download from the zip attached at the end of this post
Step2: After downloading DOMPDF library put it into the app/vendors directory. Make sure the library folder name is dompdf.
Step:3 In you Controller create a function that will use the DOMPDF library.
public function htmltopdf(){
App::import('Vendor', 'dompdf', array('file' => 'dompdf' . DS . 'dompdf_config.inc.php'));
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$papersize = 'legal';
$orientation = 'landscape';
$dompdf->load_html($html);
$dompdf->set_paper($papersize, $orientation);
$dompdf->render();
echo $dompdf->output();
$output = $dompdf->output();
file_put_contents('Brochure.pdf', $output);
}
0 Comment(s)