Remox
Remox

Reputation: 33

HTML2PDF "Error no6 impossible to load the picture"

I've a problem with HTML2PDF, I don't success to generate my PDF when I'm putting a picture. I have a message like this : "Error number 6 Impossible to load the picture /Symfony/images/logo.png" The source code :

    <img src=" {{ asset('logo.png' }} ">

I also tested with an external image and the problem is the same.

    <img src="http://www.ringencentrum.se/Images/Logos/JC_logo_CMYK.jpg">

I tested with "src=./logo.png" by putting the image at the same template folder.

Can you help me ?

Thanks !

Upvotes: 2

Views: 10445

Answers (5)

Allahbakash.G
Allahbakash.G

Reputation: 1923

First of all, please ensure you're providing URL, not the file path; for example, if you're trying to use image from c:\foo\bar\baz.gif, you'll need to use the following URL: file:///C:/foo/bar/baz.gif.

source : html2ps/faq

Upvotes: 0

I've encountered this when using .png. If I use .jpg its working. The problem was the file permissions on cache and images folder in pathtohtml2pdf/_tcpdf_5.0.022/. It should have permission to write.

Upvotes: 1

girlgeek
girlgeek

Reputation: 31

This is what I learned, I hope this solution is not too late: html2pdf doesn't know how to interpret spaces in an image path. The trick is to remove all spaces in the path and encode them.

eg. The path http://example.com/images/This - is - my - Photo.jpeg will yield the “Error no6 impossible to load the picture” error

In this case, html2pdf is looking for http://example.com/images/This%20-%20is%20-%20my%20-%20Photo.jpeg

Get rid of the spaces, use a filter to encode the spaces.

Upvotes: 0

Dragnovich
Dragnovich

Reputation: 91

Maybe too late for this answer, but I had the same problem, and the solution to this is...

DO NOT USE PNG IMAGES!

Yes HTML2PDF is suppossed to support PNG images but for some reason when you use PNG (at least in my tests) it crashed the script always.

Upvotes: 0

Skizomik
Skizomik

Reputation: 125

You can use my trick: You have to add a "." before the url, and remove some directory in the path generated by assetic. For me, i used slice 7 to infite.

 <img src=".{{asset('img/'~dossier.pageg.chemin)|slice(7,200) }}"  alt='image' />

Upvotes: 0

Related Questions