I'm using this (https://github.com/KnpLabs/KnpSnappyBundle) to render an HTML file to a pdf. I've built it on a test server and it all works perfectly but when I move it to the live server none of the images show at all. Both of the servers are AWS EC2. I've tried using png and jpg images as well as relative, absolute and full paths but nothing I do seems to work.

To me it seems like the problem is the configuration of the live server, but I didn't set it up myself and not sure how to check it.

The images are displayed if I go to them directly and before the pdf is generated so I know that the images are there okay.

I've tried typing /home/ubuntu/wkhtmltox/bin/wkhtmltopdf http://www.google.com test.pdf into the console and this is what I get

Loading pages (1/6) QSslSocket: cannot resolve SSLv2_client_method ] 10% QSslSocket: cannot resolve SSLv2_server_method Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6) Done

Then it saves a copy of the homepage to the server. So it's definitely working but I don't understand why it's not working working when I use it on the site.

All of the paths are absolute, originally they were http://{{ domain }}/pdf/images/background_logo.png, etc. I changed them to http://subdomain.livesite.com/pdf/images/background_logo.png, etc to make sure that the path was definitely correct but that didn't make any difference. I've tested the paths in a browser and they load no problems. This works fine on the test server so I'm not sure why its not working on the live site. The code used to generate the pdf is:

public function generatePdf($app)
    $products = $this->getRecurringOrderProducts();    
    if (count($products) > 0)
        $filename = $this->getPdfFilename($app);
        if (!file_exists($filename))
            // Generate HTML
            $html = $app['twig']->render('order/pdf.twig', array(    
                'entry' => $this,    
                'products' => $products,    
                'expiry_date' => $this->getExpiryDate(), // Add this line
                'content_height' => intval( (8*100*count($products))/95 )+1,    
                'domain' => $app['config']['domain'],    
            // Generate PDF
            $snappy = new Pdf($app['wkhtmltox_bin']);    
            $snappy->setOption('orientation', 'landscape');    
            $snappy->generateFromHtml(utf8_decode($html), $filename);    

I'm using wkhtmltopdf version 0.9.9 if that helps

I'm not sure what I'm doing wrong, but would be so grateful for any help please.

  • Does anybody have any suggestions for how I can get this to work? – Lucy Aug 7 '14 at 11:36

I've managed to fix this, the problem was that the image url needed to be absolute but when I tested it before the server hadn't cached it so was displaying the old file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.