Rotativa / Wkhtmltopdf images not displaying

user1866606 picture user1866606 · Jan 4, 2013 · Viewed 14.7k times · Source

I am currently creating an MVC 4 web application.

I have an action that has a base background image which is always the same then an arrow image which changes in degrees depending on the information that is collected within the action.

I call this action using

<img src="@Url.Action("trend-image", "NonReg_Reports")" alt="background" width="245" height="105" />

This works fine when it is called and is just displaying a HTML webpage. It gives me the HTML.

<img src="/nonreg-report/01495344/trend-image" alt="background" width="245" height="105">

I am then using Rotativa / Wkhtmltopdf to convert this HTML page into a PDF. This runs the same piece of code as above.

The problem is I am just getting a white box with the alternative text in it if I use the code above.

If I use <img src="~/Content/images/trend_back_medium.png" alt="astuff" /> which is the actual background image in my project it works fine.

The image from the code above can not be saved anywhere due to how it is used. I am thinking that it is a path problem, but after trying lots of different things I can still not get it to work.

Any suggestions or help would be greatly appreciated Thank you.

Answer

adam picture adam · Jul 14, 2014

I had the same problem. Normal html view was ok with pictures, pdf was not display it. I used Server.MapPath to point to picture and it was ok...

<img src="@Server.MapPath("~/Folder/SubFolder/Subfolder/ImageName.png")" />

I hope this will help

Adam