我正在使用 this将 HTML 转换为 PDF 文件的 bundle 。
实际转换有效,但我在理解路由时遇到问题。
这是我的代码:
/**
* @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");
}
}
该包创建了 2 个文件,rasterize-UNIQUEID.html
和 rasterize-UNIQUEID.pdf
。 html 文件包含正确的输出。
在 /bundles/padam87rasterize/temp/
中创建 html 文件后,脚本的第二部分通过 url 调用打开此文件 here .
不幸的是,实际呈现的页面是一个 symfony 错误页面,上面写着:
No route found for
GET /bundles/padam87rasterize/temp/rasterize-UNIQUEID.html
我必须设置什么才能呈现 html 文件?
最佳答案
我认为您实际上必须创建一个单独的路由来呈现 html。据我所知,rasterize
函数从临时 html 文件生成 pdf(关键字是临时的)。
关于php - Symfony 和 Phantom JS 包 - 路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34130093/