Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php smarty模板和dompdf_Php_Smarty_Dompdf - Fatal编程技术网

Php smarty模板和dompdf

Php smarty模板和dompdf,php,smarty,dompdf,Php,Smarty,Dompdf,我正在使用smarty模板动态生成一个页面,其中包含用户提交的表单数据和上载的图像。我可以按预期显示所有内容。我希望相同的输出为PDF格式。模板名为index.tpl,位于模板文件夹中。我想不出怎么把这两个放在一起。任何帮助都将不胜感激,谢谢。我尝试了以下方法,但不起作用。没有输出 require_once("dompdf/dompdf_config.inc.php"); $html = $smarty->fetch('index.tpl'); $dompdf = new DOMPDF()

我正在使用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");
当我检查错误日志时,我注意到“PHP致命错误:未找到类'dompd'notfound”行。然而,当我创建了一个简单的文件,如下图所示,我得到了完美的工作(PDF生成)

require_once(“dompdf/dompdf_config.inc.php”);
$html=
''.
“你好,世界

"。 ''; $dompdf=新的dompdf(); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream(“pdf_file.pdf”);

这里发生了什么?为什么不同?

我想你的答案在这里


dompdf的哪个版本?v0.5.1有一个相当简单的自动加载器,可能只是没有加载。v0.6.0(beta版)应该适合您的情况。
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");
// capture the output
$output = $smarty->fetch('index.tpl');

$tmpfile = tempnam("/tmp", "dompdf_");
file_put_contents($tmpfile, $output);
...