我正在使用此捆绑包将HTML转换为PDF文件。
实际的转换是可行的,但我在理解路由时遇到了问题。
这是我的代码:
/**
* @Route("/formulare/selbstauskunft/{keycode}", name="saPrint")
*/
public function saPrintAction(Request $request, $keycode)
{
$em = $this->getDoctrine()->getManager();
$sa = $em->getRepository('AppBundle:Selfinfo')->findOneBy(array(
'keycode' => $keycode,
));
if(count($sa) > 0){
$response = new Response(
$this->get('padam87_rasterize.rasterizer')->rasterize(
$this->renderView('default/formSAPrint.html.twig', array(
'selfinfo' => $sa,
))
),
200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="my.pdf"'
]
);
return $response;
}else{
return new Response("fail");
}
}
捆绑包创建两个文件,rasterize-UNIQUEID.html
和rasterize-UNIQUEID.pdf
。html文件包含正确的输出。在/bundles/padam87rasterize/temp/
中创建html文件后,脚本的第二部分通过此处的url调用打开该文件。不幸的是,实际呈现的页面是一个符号错误页面,上面写着:
未找到
GET /bundles/padam87rasterize/temp/rasterize-UNIQUEID.html
的路由
为了呈现html文件,我必须设置什么?
我认为实际上必须创建一个separare路由来渲染html。据我所知,rasterize
函数从临时html文件中生成一个pdf(关键字是临时的)。