In codeigniter,
DOMPDF showing blank screen..
no errors (in development mode)..
html generating properly..
but pdf not generating.. only blank screen is there
My Code Snippet:
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->setPaper('A4', 'potrait');
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf", array("Attachment" => 0));
} else {
return $dompdf->output();
}
}
function invoicepdf()
{
$orderId = base64_decode($this->uri->segment('3'));
$this->load->helper(array('dompdf', 'file'));
$query = "SELECT * FROM `ci_booking` WHERE id='".$orderId."'";
$this->data['order_details'] = $this->home->customQuery($query);
$html = $this->load->view('reports/printinvoice', $this->data, true);
//echo $html; die;
$this->pdf_create($html, 'Invoice -'.$orderId);
}
When I un-comment echo statement of invoicepdf() function.. then output generating properly. but when it passes to pdf_create() function then its showing blank screen, no errors after setting ini_reporting to 1.
I have attached blank screen inspect code, why its showing like this?
please suggest me the changes.
There's two issues with your code:
1.- A small typo that goes a long way:
You're setting a paper orientation which is unknown to DomPDF here $dompdf->setPaper('A4', 'potrait'); you need to change that to portrait or DomPDF may not really understand what you want and fail to render.
2.- All the human-readable text (not HTML formatting) in your view is being generated with Javascript, which requires a browser rendering engine that DomPDF doesn't have (DomPDF renders server-side, not client-side, which is important to consider).
The fact that everything works fine when loading the view in the browser is because in that case your browser handles the document.write correctly. DomPDF however does not (because it's not a real DOM/JS rendering engine, it just formats a plain HTML in a way that fits in a given paper size and orientation).
Try making the text a regular non-JS HTML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With