Good morning guys, how are you?
I have 3 files: certificate.png | style.css | certificate.html
I have a method that unites them and print the certificate in PDF, when printo on the screen with var_dump comes out right, when generating the pdf leaves the first blank sheet, the second half of the image and the third with the descriptions, and instead to print in landscape that is set, he printed in portrait, what can be? is there any schema for DOMPDF to get the correct css?
follows method that joins the files and makes the call of the creation of the pdf
public function generateCertificate(){
$this->load->library('CertificatePDF');
$certificantePDF = new CertificatePDF();
$html = file_get_contents('assets/components/certificate/certificate.html');
$keys = array('[[SITE_URL]]');
$values = array(site_url('assets/components/certificate'));
$html = str_replace($keys, $values, $html);
$filename = "certificado" . date('YmdHis');
$dir = 'assets/download/certificados/';
$download = true;
$certificantePDF->createPdfFromHtml($html, $filename, $dir, $download);
var_dump($html);
}
Method that generates PDF
use Dompdf\Dompdf;
use Dompdf\Options;
require_once(__DIR__ . "/../../assets/components/dompdf/autoload.inc.php");
class CertificatePDF {
public function createPdfFromHtml($html, $filename, $dir, $download = false) {
$option = new Options();
$option->set(array(
'isPhpEnabled' => true,
'isRemoteEnabled' => true,
'isHtml5ParserEnabled' => true
));
$dompdf = new Dompdf($option);
$dompdf->set_paper('A4', 'landscape');
$dompdf->load_html($html);
$dompdf->set_base_path(__DIR__ . "/../../");
$dompdf->render();
if ($download) {
$dompdf->stream($filename . ".pdf");
}
file_put_contents($dir . $filename . ".pdf", $dompdf->output());
}
}