Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 退出状态代码';1';说出了什么问题[knp snappy]_Symfony_Pdf Generation_Wkhtmltopdf - Fatal编程技术网

Symfony 退出状态代码';1';说出了什么问题[knp snappy]

Symfony 退出状态代码';1';说出了什么问题[knp snappy],symfony,pdf-generation,wkhtmltopdf,Symfony,Pdf Generation,Wkhtmltopdf,我正在使用knp snappy捆绑包从我的应用程序生成报告。但不起作用,当我调用控制器生成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

我正在使用knp snappy捆绑包从我的应用程序生成报告。但不起作用,当我调用控制器生成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"'
                )
            );
    }
我复制了我的url并用wkhtmltopdf.exe运行到控制台[CMD]。在控制台中创建了我的pdf,但当我看到该文件时,仅显示我的登录屏幕。所以我想可能是关于我的控制器的权限的问题,但我不知道如何传递它

另一方面,如果您知道另一个pdf生成器(来自html)正在使用symfony,这对我也有帮助


我在symfony2.7下工作,这意味着你的HTML文件中的一个资源不能被wkhtmltopdf加载,如果你的所有资源都有这样一个绝对URL,请检查你的HTML文件:

如果不是这样,请尝试设置:

{{ 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:
    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()
twig函数
{{absolute_url(asset('assets/image.jpg'))}
我在WKHTMLOPDFIN laravel 5中遇到了同样的问题和错误消息,这就是问题所在。我拥有抛出错误的CDN资产。一旦我改用本地版本,PDF生成就按预期运行。嗨,我应该把{{app.request.schemeAndHttpHost~'资源相对url'}放在哪里?在html内容中?欧欧欧