سؤال

I am using KNP Snappy with Symfony2. When I use a response from a controller I get the following response:

The exit status code '2' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[============================> ] 48%
[============================================================] 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 3
[=======================================> ] Page 2 of 3
[============================================================] Page 3 of 3
Done 
Exit with code 2 due to http error: 404 Page not found
"
stdout: ""
command: /usr/bin/wkhtmltopdf --lowquality --no-outline      '/tmp/knp_snappy527f3354ad21d2.78976975.html' '/tmp/knp_snappy527f3354ad6e37.45993260.pdf'.

Part of the controller looks like this:

    $html = $this->renderView('MyBundle:Visit:print.html.twig', array(
        'visit'  => $visit,
        'themes' => $themes
    ));

    return new Response(
        $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="file.pdf"'
        )
    );

The file is generated, and it looks fine. But the response is above error.

Does anybody know what the problem could be?

هل كانت مفيدة؟

المحلول

This is a known issue that usually happens when resources are missing, even if the page itself is found and returns 200. It's reported here - the supremely horrible thing about it is that it doesn't always return 2 when something is 404. That's why I (and often I see others too) treat exitcode 2 and 0 the same.

I also started an issue to get the exit codes documented, but Antialize and the others don't really have time to update the project. (Although there are rumors of forking and 0.12, but they are not really substiantial yet.)

So, the first thing I would check is if there is anything that might cause a 404 (or anything else than 2xx actually) within the page. Something like a missing CSS, JavaScript or Image file.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top