0

I am using smarty template to generate a page on-the-fly that consists of user-submitted form data and uploaded images. I can get to display all the contents as expected. I want the same to be output as PDF. The template is named index.tpl, and is located inside the template folder. I can't figure out how to put these two together. Any help would be appreciated, thanks. I tried the following, but doesn't work. There is no output.

require_once("dompdf/dompdf_config.inc.php");
$html = $smarty->fetch('index.tpl');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("pdf_file.pdf");

When I checked the error_log, I noticed "PHP Fatal error: Class 'DOMPDF' not found" line. HOWEVER, when I created a simple file as shown below, I get it working perfectly (PDF is generated).

require_once("dompdf/dompdf_config.inc.php");
$html =
    '<html><body>'.
    '<p>Hello World!</p>'.
    '</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("pdf_file.pdf");

What is happening here? Why the difference?

4

1 回答 1

2

我想你的答案在这里http://www.smarty.net/docsv2/en/api.fetch.tpl

// capture the output
$output = $smarty->fetch('index.tpl');

$tmpfile = tempnam("/tmp", "dompdf_");
file_put_contents($tmpfile, $output);
...
于 2013-10-22T10:03:28.670 回答