KnpSnappyBundle – Local image path in Docker

I can’t seem to get external images to work, and local images only work if I use the full path in the docker php container. Is there any way around having to input the path manually?

Controller

return new Response($this->snappy->getOutputFromHtml($html, [
        'page-width' => 297,
        'page-height' => 210,
        'images' => true,
        'lowquality' => false,
        'enable-external-links' => true,
        'enable-internal-links' => true,
        'header-html' => $header,
        'footer-html' => $footer,
        'margin-top' => 60,
        'margin-right' => 7,
        'margin-bottom' => 48,
        'margin-left' => 7,
    ]), 200, [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; filename="'.$fileName.'"',
    ]
);

Working

<img src="/var/www/app/public/build/images/logo.png" />

Not working (returns: http://localhost/build/images/logo.png)

<img src="absolute_url(asset('build/images/logo.png'))"/>

Not working (returns: /build/images/logo.png)

<img src="asset('build/images/logo.png')"/>

Not working

<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"/>

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *