andyhutch77 / MvcRazorToPdf

Create pdf documents within an asp .net mvc project by generating your views as normal but returning a PdfActionResult. This converts regular produced razor/html to pdf documents in the browser using the iTextXmlWorker.
125 stars 105 forks source link

Issue displaying images #19

Closed JSetti closed 10 years ago

JSetti commented 10 years ago

My PDFs are rendering perfectly except that I cannot get the images to show up. I am retrieving the image path from the model and rendering it with code like this:

string url = "http://" + HttpContext.Current.Request.Url.Authority; var sVal = value.sValue; @* For example: /Content/Images/ent_apps.jpg *@ string imageURL = "<img src = '" + url + sVal + "'/>"; @Html.Raw(imageURL)

The sVal value ends up being something like: <img src = 'http://localhost:2000/Content/Images/ent_apps.jpg'/&gt;

I know that the URL to the image is correct as I tested it in the browser.

Thank you in advance for any advice.

ElanHasson commented 10 years ago

Pdfs can't render the URL, but use server.mappath to provide the URL.

See the views in the example for reference. On Oct 16, 2014 3:25 PM, "JLS7" notifications@github.com wrote:

My PDFs are rendering perfectly except that I cannot get the images to show up. I am retrieving the image path from the model and rendering it with code like this:

string url = "http://" + HttpContext.Current.Request.Url.Authority; var sVal = value.sValue; @* For example: /Content/Images/ent_apps.jpg *@ string imageURL = ""; @Html.Raw(imageURL)

The sVal value ends up being something like: https://camo.githubusercontent.com/16439271aebb3f3d360abaf1ccb4bbc9da9980ff/687474703a2f2f6c6f63616c686f73743a323030302f436f6e74656e742f496d616765732f656e745f617070732e6a7067

I know that the URL to the image is correct as I tested it in the browser.

Thank you in advance for any advice.

— Reply to this email directly or view it on GitHub https://github.com/andyhutch77/MvcRazorToPdf/issues/19.

andyhutch77 commented 10 years ago

@ElanHasson is correct.

The example project is here: https://github.com/andyhutch77/MvcRazorToPdf/tree/master/MvcRazorToPdfExample