Home > Net >  DomPDF not showing encoded svg in img tag on Windows IIS 10
DomPDF not showing encoded svg in img tag on Windows IIS 10

Time:06-05

Lately I've developed a Laravel application that generates a PDF, the development process was made in ubuntu 21.10 using laravel sail, and it has been deployed to a Windows Server with IIS 10.

The PDF contains an image that is rendered using an encoded svg:

<img style="width: 200px;" src="data:image/svg xml;base64,{{ $base64_image }}" alt="">

the $base64_image is obtained by the following line of code:

base64_encode(str_replace('<svg', '<svg fill="#000000" ',file_get_contents("img/image.svg"))),

this line uses the file_get_contents() function to retrieve the svg image, then it fills the svg with #000000 (black), and finally converts to a base64 string.

So basically what my <img> receives is a plain string. This approach works flawlessly in my dev server with ubuntu, but in IIS no image is showing at all.

What I have tried so far:

  • Updating MIME Types in the IIS site manager.
  • Updating the web.config to allow SVG
  • I've used an url for a PNG image hosted online

Basically on the IIS server no image is showing at all when generating the PDF, just a square with the message

image not found or type unknown

CodePudding user response:

I was able to solve this problem.

My previous comment made me think that rather than being an issue with DomPDF, it was an issue with IIS blocking the content somehow. after some investigation I found: CSS, Images, JS not loading in IIS

Basically IIS blocks static content by default, and a PDF being a static document, was not able to render properly. Allowing static content in the site solved the issue.

  • Related