如何使dompdf处理树枝页面 [英] how to make dompdf handle twig page

查看:47
本文介绍了如何使dompdf处理树枝页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to convert a dynamic page written with TWIG to PDF. I am unable to make him interpret the TWIG code, every php, html output is rendered but TWIG is ignored. Can you tell me if there is a solution that is not "to rewrite the same template in php" ?

推荐答案

使用render函数吗?它会输出html,以便您可以在DomPDF中传递它。

use the render function? it outputs html so that you can pass it in your 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之下

If you are under Symfony

$dompdf->load_html($this->renderView('index.html', array('name' => 'Fabien')));
$dompdf->render(); 
$dompdf->stream("sample.pdf");

这篇关于如何使dompdf处理树枝页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆