0% found this document useful (0 votes)
17 views1 page

To PDF Helper Function

Uploaded by

adarsha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

To PDF Helper Function

Uploaded by

adarsha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

function pdf_create($html, $filename, $stream = true, $papersize = 'a4',

$orientation = 'portrait')
{
require_once 'dompdf/autoload.inc.php';
$domOptions = new Options();
$domOptions->set('defaultFont', 'lato-regular');
$domOptions->set('isHtml5ParserEnabled', true);
$domOptions->set('isRemoteEnabled', true);
$fontDir = __DIR__ . '/dompdf/lib/fonts';
$domOptions->set('fontDir', $fontDir);
$dompdf = new Dompdf($domOptions);
$fonts = [
'arial' => ['normal' => 'Arial.ttf'],
'courier new' => ['normal' => 'Courier New.ttf'],
'georgia' => ['normal' => 'Georgia.ttf'],
'tahoma' => ['normal' => 'Tahoma.ttf'],
'times new roman' => ['normal' => 'Times New Roman.ttf'],
'trebuchet ms' => ['normal' => 'trebuc.ttf'],
'verdana' => ['normal' => 'VERDANAI.ttf'],
];
foreach ($fonts as $name => $styles) {
foreach ($styles as $style => $file) {
$fontPath = $fontDir . '/' . $file;
if (file_exists($fontPath)) {
$dompdf->getOptions()->set('fontCache', $fontDir);
}
}
}
$dompdf->loadHtml($html, 'utf-8');
$dompdf->setPaper($papersize, $orientation);
$dompdf->set_option('defaultMediaType', 'all');
$dompdf->set_option('isFontSubsettingEnabled', true);
$dompdf->render();
if ($stream) {
$options['Attachment'] = 1;
$options['Accept-Ranges'] = 0;
$options['compress'] = 1;
$dompdf->stream($filename.".pdf", $options);
} else {
$CI =& get_instance();
$CI->load->helper('file');
if (@write_file($filename.".pdf", $dompdf->output())) {
return 1;
}
return 1;
}
}

You might also like