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
It is not working because localhost for your php container is not the same than your localhost nor nginx localhost.
You are probably using docker-compose so you can do and it should work.
For it should work, if it do not work it means that your container do not have access to internet.
You will have this problem only in local, in production it should work with .
It seams that this form is removing codes …
Let’s do it again :
It is not working because localhost for your php container is not the same than your localhost nor nginx localhost.
You are probably using docker-compose so you can do ‘http://{name of your nginx/apache container}/build/images/logo.png’ and it should work.
For https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png it should work, if it do not work it means that your container do not have access to internet.
You will have this problem only in local, in production it should work with the absolute_url.