Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 567
Rodrigo Díaz R. Avatar asked Dec 29 '15 13:12

Rodrigo Díaz R.


1 Answers

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 }}
like image 109
Anas EL KORCHI Avatar answered Oct 01 '22 09:10

Anas EL KORCHI