我正在使用 knp snappy 包从我的应用程序生成报告。但不起作用,当我调用 Controller 生成 pdf 时,会抛出下一个错误:
The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[=======> ] 12%
Warning: Failed to load file:///gestionresiduospel/web/bundles/usuario/css/bootstrap.css (ignore)
Warning: Failed to load file:///gestionresiduospel/web/bundles/usuario/js/bootstrap.js (ignore)
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[============================================================] Page 1 of 1
Done
Exit with code 1 due to network error: ContentNotFoundError
"
stdout: ""
command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --lowquality "C:\Users\rodrigo\AppData\Local\Temp\knp_snappy5682878973ade7.09664058.html" "C:\Users\rodrigo\AppData\Local\Temp\knp_snappy56828789746968.46649162.pdf".
我的 Controller 是这样的:
public function historicosDetallePdfAction($id)
{
$em = $this->getDoctrine()->getManager();
//gets residuos peligrosos.
$solicitudRetiro= $em->getRepository('SolicitudRetiroBundle:SolicitudRetiro')->find($id);
//gets residuos no peligrosos
$residuosPRetirados = $em->getRepository('SolicitudRetiroBundle:RetiroResiduo')->findResiduos($id);
//retorna los residuos no peligrosos en la solicitud
$residuosNPRetirados = $em->getRepository('SolicitudRetiroBundle:RetiroResiduoNoPeligroso')->findResiduosNoPeligrosos($id);
// view generator
$html = $this->renderView('SolicitudRetiroBundle:Pdf:resumenSolicitudResiduoRetirado.html.twig', array(
'solicitudRetiro' => $solicitudRetiro,
'residuosRetirados' => $residuosPRetirados,
'residuosNoPel' => $residuosNPRetirados ));
// pdf generator
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="historico.pdf"'
)
);
}
我复制了我的网址并使用 wkhtmltopdf.exe 进入控制台 [CMD]。在控制台中,我的 pdf 已创建,但当我看到该文件时,仅显示我的登录屏幕。所以我认为可能是关于我的 Controller 的权限问题,但我不知道如何传递它。
另一方面,如果您知道另一个可以在 symfony 中使用的 pdf 生成器(来自 html),这也可能对我有帮助。
我在 symfony2.7 下工作
最佳答案
这意味着您的 HTML 文件中的资源之一无法通过 wkhtmltopdf 加载,请检查您的 HTML 文件,如果您的所有资源都具有如下所示的绝对 URL:http://www.yourserver.com/images/myimage.jpg
如果不是这种情况,请尝试设置它:
{{ app.request.schemeAndHttpHost ~ 'resource relative url' }}
如果您在 {% stylesheets %}
或 {% javascript %}
或 {% image %}
中使用 assetic 加载资源,您还可以做
{{ app.request.schemeAndHttpHost ~ asset_url }}
关于symfony - 退出状态代码 '1' 表示出现问题 [knp snappy],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512241/