0

When including images in the HTML I'm trying to generate a PDF from, only static images will be rendered. For example, I have an image PRD005.png saved in my project in the ~/Content/Images folder. Including it as below will render the image in my HTML view and in the PDF file that is generated.

However, when I try to include images from an URL, like from a controller that serves a File of type image/png, it will only render in the HTML view, but not in the generated PDF.

Since our images are generated by a Barcode API or read from a BLOB entry in the database, I'd like to find out if it's even possible to render images like this in the generated PDF. If not, is there any work-around to achieve this?

var imagePath = Server.MapPath("~/Content/Images");

<img src="/Barcode/Get/@r.ProductCode" />  // doesn't work
<img src="@imagePath\PRD005.png" />        // works
Ivo Coumans
  • 759
  • 8
  • 23
  • Replace the relative links with absolute ones. – stuartd Feb 24 '15 at 15:24
  • 2
    Also [see this](http://stackoverflow.com/q/25164257/231316), specifically the fourth paragraph that tells you that you need to provide iText with HTML and not ASP.Net code. HTML doesn't have variables so you need to take care of that first and then pass *that* string to iText. – Chris Haas Feb 24 '15 at 18:32
  • I see, thanks for clearing that up. Looks like I'll have to find an alternative solution to solve this. I'm afraid absolute links isn't an option - we can't generate an image for each generated ID beforehand. – Ivo Coumans Feb 25 '15 at 07:20

0 Answers0