I am using dompdf library to convert my html content to pdf.
I am sending html content from view to controller with ajax post request.
In this controller, I am calling dompdf helper class to convert my html to pdf file and save it on client side.
Here is my ajax request:
$.ajax({
type: "POST",
url: "<?php echo $this->config->base_url('reports/exportPDF')?>",
data:
{
report : totalHtml
},
success: function (response) {
console.log(response);
},
error: function (err) {
//console.log(err);
}
});
Here is my controller code where I am submitting my html content:
$this->load->helper('url');
$this->load->helper(array('dompdf', 'file'));
$html = $this->input->post('report');
$data = pdf_create($html);
Finally, Here is my dompdf helper library integration code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$htmlData = $dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );
$dompdf->render();
$dompdf->stream("report.pdf");
}
?>
As per dompdf documentation, the download dialogue box should appear but I am unable to get it.
How should I save the pdf file on client side with dompdf?
Thanks in advance.