The exit status code '1' says something went wrong [knp snappy]

15,516

This mean's that one of the resources in your HTML file can't be loaded by wkhtmltopdf, check in your HTML file if all your resources have an absolute URL like this : http://www.yourserver.com/images/myimage.jpg

If it's not the case try to set it :

{{ app.request.schemeAndHttpHost ~ 'resource relative url' }}

If you are loading assets with assetic in {% stylesheets %} or {% javascript %} or {% image %} you can also do

{{ app.request.schemeAndHttpHost ~ asset_url }}
Share:
15,516
Rodrigo Díaz R.
Author by

Rodrigo Díaz R.

Updated on June 08, 2022

Comments

  • Rodrigo Díaz R.
    Rodrigo Díaz R. about 2 years

    I'm working with knp snappy bundle for generate reports from my app. But doesn't work, when I call my controller for generate the pdf throws the next error:

    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". 
    

    My controller is this:

    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"'
                    )
                );
        }
    

    I copied my url and run into console[CMD] with wkhtmltopdf.exe. In console my pdf is created but when I see the file only shows my login screen. So I think could be a issue about permission into my controller but I don't know how I pass this.

    In other hand, if you know about another pdf generator(from html) that working into symfony this could be help me too.

    I'm working under symfony2.7

  • RoboBear
    RoboBear over 8 years
    I had this same issue and error message with wkhtmltopdfin laravel 5, and this was the problem. I had CDN assets that threw the errors. Once I used local versions instead, the PDF generation ran as expected.
  • Jean-Charles LUC
    Jean-Charles LUC almost 5 years
    Hi, where should i put {{ app.request.schemeAndHttpHost ~ 'resource relative url' }} ? in html html content ? o_o