This is working great for my needs. I do have one request, however. Could someone quickly explain how to save a copy of a PDF file generated with dompdf to my server so I can send it via email as an attachment?
I just need to know what to configure to set dompdf to ‘savefile’ instead of only ‘stream’. Thanks so much.
Hmm, its been a bit since I wrote it, but it should accept an optional third argument, in this case, just set it to “false”. So your controller will look roughly like this:
function pdf() { $this->load->plugin('to_pdf'); // page info here, db calls, etc. $html = $this->load->view('controller/viewfile', $data, true); pdf_create($html, 'filename', false); }
Sorry ben, I had modified it for Bamboo and not put my changes back into the wiki. I’ve modified it in the wiki. Hopefully that will solve address your problem.
Wonderful! I’ve gotten that part working… I can stream or write a file without any problem. The issue now is that if I put any functions or commands after the “pdf_create” function in my controller, it gives me this error message:
Warning: require_once(C:\htdocs\im_website\cisys\plugins\dompdf/include/ci_exceptions.cls.php) [function.require-once]: failed to open stream: No such file or directory in C:\htdocs\im_website\cisys\plugins\dompdf\dompdf_config.inc.php on line 194
Fatal error: require_once() [function.require]: Failed opening required ‘C:\htdocs\im_website\cisys\plugins\dompdf/include/ci_exceptions.cls.php’ (include_path=‘.;C:\php5\pear’) in C:\htdocs\im_website\cisys\plugins\dompdf\dompdf_config.inc.php on line 194
EDIT: solved by updating PHP to the latest version
With dompdf I’m getting an error on which I can’t find much additional info. I know it’s a longshot, but perhaps someone around here can help me with this problem.
Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in dompdf.cls.php on line 165
Fatal error: Call to undefined method domdocument::loadHTML() in dompdf.cls.php on line 284
I thought I missed the appropriate .DLL, but phpinfo() says this:
dom
DOM/XML enabled
DOM/XML API Version 20031129
libxml Version 2.6.11
HTML Support enabled
XPath Support enabled
XPointer Support enabled
Schema Support enabled
RelaxNG Support enabled
domxml
DOM/XML enabled
DOM/XML API Version 20030407
libxml Version 20611
HTML Support enabled
XPath Support enabled
XPointer Support enabled
Last but not least the piece of script I testted Dompdf with:
<?php require_once("dompdf_config.inc.php");
$html = '<html><body>'. '<p>Put your html here, or generate it with your favourite '. 'templating system.</p>'. '</body></html>';
$dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("sample.pdf"); ?>
I’ve problems using dompdf with codeIgniter. The problem is that all the generated pdf are corrupted and Adobe can’t read them.
I’ve followed all the instructions to get dompdf working as a plugin in codeIgniter but I doesn’t work for me.
Yes, outside Code Ingniter it works well and there is not any problem.
My plugin looks like:
<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
function pdf_create($html, $filename)
{
require_once(“dompdf/dompdf_config.inc.php”);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($filename.“.pdf”);
}
?>
And I call this function inside a my controller as:
function pdf(){
$this->load->plugin(‘to_pdf’);
$html=‘<html><body>‘.‘<p>kk</p>‘.‘</body></html>‘;
pdf_create($html,‘test’);
}
i got also a problem with dompf and the various browsers: in IE7 it works well (the pdf is opened in the browser), in opera the generated pdf is downloaded (also ok), but in FF2.0 the page hangs up. in the title bar there’s written the controller name and (application/pdf-Object), but the pdf is never loaded
any suggestions?
this is my code:
to_pdf_pi.php
<?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(); $dompdf->load_html($html); $dompdf->render(); if ($stream) { $dompdf->stream($filename.".pdf"); } } ?>
don’t ask me why, but it works now. could an empty variable in the controller (which is added to the filename and passed to the view) cause this misbehaviour?