File "Dompdf_lib.php"
Full Path: /home/ichhrkpd/public_html/idcm/application/errors/Dompdf_lib.php
File size: 1.55 KB
MIME-type: text/x-php
Charset: utf-8
<?php
require_once APPPATH . 'third_party/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
use Dompdf\Options;
class Dompdf_lib {
protected $dompdf;
public function __construct() {
$options = new Options();
$options->set('defaultFont', 'NotoSansBengali'); // Or 'NotoSansBengali'
$options->set('isRemoteEnabled', true);
$options->set('isHtml5ParserEnabled', true);
$options->set('isFontSubsettingEnabled', true);
$options->set('isPhpEnabled', true);
$this->dompdf = new Dompdf($options);
}
public function generate_pdf($html, $filename = 'document.pdf', $stream = true) {
$this->dompdf->loadHtml($html);
$this->dompdf->setPaper('A4', 'portrait');
$this->dompdf->render();
// Apply page number using page_script (this will be applied on each page)
$canvas = $this->dompdf->getCanvas();
$canvas->page_script('
if ($PAGE_COUNT > 0) {
$pdf->line(50, 790, 550, 790, array(0, 0, 0), 0.5);
}
');
$canvas->page_text(50, 800, "Powered by IT Cell, HSTU", "Times-Italic", 7, array(0, 0, 255)); //
$canvas->page_text(500, 800, "Page {PAGE_NUM} of {PAGE_COUNT}", null, 7, array(0, 0, 0)); // Customize position
if ($stream) {
$this->dompdf->stream($filename, ["Attachment" => true]);
} else {
return $this->dompdf->output();
}
}
}
?>