1

How do I embed an image (PNG,SVG or JPG) into a CraftCMS Commerce 2 PDF receipt? I tried importing the svg using an includes. I tried using an img tag and referencing a local file. Nothing seems to work.

David

3 Answers 3

2

Have you tried to use a absolute path without the «/» at the beginning? (or actually a relative one from the webroot…) <img src="assets/images/site/logo.png" />

This did the trick in my case.

2

The PDF renderer uses DOMPDF, which expects a HTML document to be supplied. See the DOMPDF documentation to see what types of images are supported.

If you are linking images from a different domain you will need to set the commerce.php config setting of pdfAllowRemoteImages to true.

https://docs.craftcms.com/commerce/v2/configuration.html#pdfallowremoteimages

4
  • I have the pdfallowremoteimages setting already. I guess my question is where do I grab the image from? The local shop/_pdf directory or somewhere else? I am getting an "Image not found" error in the PDF so it seems like dompdf cannot locate the resource. I have tried <img src="logo.png" /> ans well as <img src="/assets/images/site/logo.png" /> Aug 7, 2018 at 18:01
  • Am also struggling with this, I have pdfAllowRemoteImages set to true, and have tried an absolute path to an image on the frontend website (eg blah) and a relative path - still getting an empty square and "image not found" error as per comment above Aug 7, 2019 at 16:30
  • Having the same issue myself. @jamesgreig did you resolve this? Feb 19, 2021 at 17:19
  • No I gave up I'm afraid @TerryUpton Feb 22, 2021 at 9:56
1

Also had the issue, it seems like neither the valid path nor url work, despite of the setting pdfAllowRemoteImages being adjusted. But you can always base64 encode the image and place that inside the src="".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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