Ultimately, what I would like to do is take a .docx file, convert it to HTML, then convert that HTML into a PDF and embed that PDF in my view. I want to do this all without saving the PDF to a file, but instead, just immediately displaying it in my view.
So far, I have been able to convert the .docx into HTML and then convert that into a pdf. However, I am now stuck on how to display that pdf string in my view. Currently, I am trying to load a view that has headers for a pdf into a variable, and then send that variable to my view to display in tags. It's not working though.
Here is what I have so far...
My controller:
$doc = new Docx_reader();
$doc->setFile('testDoc3.docx');
$plain_text = $doc->to_plain_text();
$html = $doc->to_html();
$pdf = pdf_create($html, 'testDoc4', false);
$data['pdfx'] = $pdf;
$data['pdf'] = $this->load->view('test_pdf_view', $data, TRUE);
$this->load->view('results/test_viewer', $data);
The test_pdf_view:
$len = strlen($pdfx);
header("Content-type: application/pdf");
header("Content-Length:" . $len);
header("Content-Disposition: inline; filename=Resume.pdf");
print $pdfx;
And the relevant part of my test_viewer view:
<object data="<?php echo $pdf; ?>" width="600" height="775" type="application/pdf"> PDF Plugin Not Available </object>
the pdf_create function:
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("system/helpers/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf");
} else {
return $dompdf->output();
}
}
Is what I'm trying to do even possible? I know that I could save the pdf to a file or database, and then display that pdf file, and ultimately delete or unlink that file, but for a few reasons that is not the direction I would like to go. Any ideas or help is appreciated!
Thanks!