To PDF Helper Function
To PDF Helper Function
$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;
}
}