I'm using MvcRazorToPdf in my Asp.net MVC5 project to create pdfs from model. That works fine, but I want to include an image from a base64 string, because I don't want to save the generated image.
System.Drawing.Image img = generator.GenerateImage();
string imageBase64Data = Convert.ToBase64String(Helper.ImageToByteArray(img));
string imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data);
ViewBag.Image = imageDataURL;
return new PdfActionResult(myobject);
...
<img src="@ViewBag.Image" />
Working fine, if showing the image in a normal view, but the pdf doesn't show the image.
Thank you for help or alternatives.
Probably I'm answering too late. If your needs for a base64 string based image is to avoid store the image in the filesystem, you can write an Action that returns the image file and reference that url in the
imgtag:And then your razor will look like:
Note the use of
Request.Url.SchemeUrl.Actionoverload is VERY important, because iTextSharp needs the full qualified URL.