【问题标题】:smarty template and dompdfsmarty模板和dompdf
【发布时间】:2013-10-22 09:55:11
【问题描述】:

我正在使用 smarty 模板即时生成一个页面,该页面由用户提交的表单数据和上传的图像组成。我可以按预期显示所有内容。我希望将其输出为 PDF。该模板名为 index.tpl,位于模板文件夹内。我无法弄清楚如何将这两个放在一起。任何帮助将不胜感激,谢谢。我尝试了以下方法,但不起作用。没有输出。

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");

当我检查 error_log 时,我注意到“PHP 致命错误:找不到类 'DOMPDF'”行。但是,当我创建一个如下所示的简单文件时,它可以正常工作(生成 PDF)。

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");

这里发生了什么?为什么会有差异?

【问题讨论】:

  • dompdf 的哪个版本? v0.5.1 有一个相当简单的自动加载器,可能根本无法加载。 v0.6.0(测试版)应该适用于您的情况。

标签: php smarty dompdf


【解决方案1】:

我想你的答案在这里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);
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    相关资源
    最近更新 更多