退出状态代码“1”表示出了点问题 [knp snappy]
The exit status code '1' says something went wrong [knp snappy]
我正在使用 knp snappy bundle 从我的应用程序生成报告。但是不起作用,当我调用我的控制器生成 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".
我的控制器是这样的:
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 将 url 和 运行 复制到控制台 [CMD] 中。在控制台中创建了我的 pdf,但是当我看到文件时只显示我的登录屏幕。所以我认为可能是关于我的控制器权限的问题,但我不知道我是如何通过它的。
另一方面,如果您知道另一个 pdf 生成器(来自 html),它可以在 symfony 中使用,这对我也有帮助。
我在 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 }}
我曾经遇到过两种问题:
第一个是因为 kpn snappy 在尝试转换 *.js 文件时失败。所以我不得不在我的案例中使用 *.js 文件。
第二个是因为路径。我不得不使用绝对文件系统路径。通过这个,我的意思是,类似于:/home/ubuntu/workspace/bootstrap/css/bootstrap.css
这是在 *html.twig 文件中使用的 href 标记中使用的,然后由 snappy 将其转换为 pdf。
通过这样做,我使用了一些 twig 全局变量。
twig:
form:
resources:
- 'MyBundle:Form:fields.html.twig'
- 'MyUploaderBundle:Form:fields.html.twig'
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
pathToWeb: "%kernel.root_dir%/../web"
bootstrapCss: "/home/ubuntu/workspace/MyApp/web/bootstrap/css/bootstrap.css"
mainCss: "/home/ubuntu/workspace/MyApp/web/css/main.css"
layoutCss: "/home/ubuntu/workspace/MyApp/web/css/layout.css"
在树枝上
<link rel="stylesheet" type="text/css" href="{{ bootstrapCss }}">
<link rel="stylesheet" type="text/css" href="{{ layoutCss }}">
<link rel="stylesheet" type="text/css" href="{{ mainCss }}">
您可以使用 absolute_url()
树枝函数{{ absolute_url(asset('assets/image.jpg')) }}
我正在使用 knp snappy bundle 从我的应用程序生成报告。但是不起作用,当我调用我的控制器生成 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".
我的控制器是这样的:
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 将 url 和 运行 复制到控制台 [CMD] 中。在控制台中创建了我的 pdf,但是当我看到文件时只显示我的登录屏幕。所以我认为可能是关于我的控制器权限的问题,但我不知道我是如何通过它的。
另一方面,如果您知道另一个 pdf 生成器(来自 html),它可以在 symfony 中使用,这对我也有帮助。
我在 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 }}
我曾经遇到过两种问题:
第一个是因为 kpn snappy 在尝试转换 *.js 文件时失败。所以我不得不在我的案例中使用 *.js 文件。
第二个是因为路径。我不得不使用绝对文件系统路径。通过这个,我的意思是,类似于:/home/ubuntu/workspace/bootstrap/css/bootstrap.css
这是在 *html.twig 文件中使用的 href 标记中使用的,然后由 snappy 将其转换为 pdf。
通过这样做,我使用了一些 twig 全局变量。
twig:
form:
resources:
- 'MyBundle:Form:fields.html.twig'
- 'MyUploaderBundle:Form:fields.html.twig'
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
pathToWeb: "%kernel.root_dir%/../web"
bootstrapCss: "/home/ubuntu/workspace/MyApp/web/bootstrap/css/bootstrap.css"
mainCss: "/home/ubuntu/workspace/MyApp/web/css/main.css"
layoutCss: "/home/ubuntu/workspace/MyApp/web/css/layout.css"
在树枝上
<link rel="stylesheet" type="text/css" href="{{ bootstrapCss }}">
<link rel="stylesheet" type="text/css" href="{{ layoutCss }}">
<link rel="stylesheet" type="text/css" href="{{ mainCss }}">
您可以使用 absolute_url()
树枝函数{{ absolute_url(asset('assets/image.jpg')) }}