1

我必须将用 TWIG 编写的动态页面转换为 PDF。我无法让他解释 TWIG 代码,每个 php、html 输出都会被渲染,但 TWIG 会被忽略。你能告诉我是否有一个不是“在php中重写相同的模板”的解决方案吗?

4

1 回答 1

3

使用渲染功能?它输出 html,以便您可以在 DomPDF 中传递它。

$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
$dompdf->load_html($twig->render('index.html', array('name' => 'Fabien')));
$dompdf->render(); 
$dompdf->stream("sample.pdf");

如果你在 Symfony 下

$dompdf->load_html($this->renderView('index.html', array('name' => 'Fabien')));
$dompdf->render(); 
$dompdf->stream("sample.pdf");
于 2012-09-24T08:34:08.667 回答