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

Images not rendered when inside a div #32

Closed mnahirny closed 9 years ago

mnahirny commented 9 years ago

The following renders an image: @{ Layout = "~/Views/Shared/_PdfLayout.cshtml"; ViewBag.Title = "PeptideInfo"; var imagePath = Server.MapPath("~/Content/Images"); }

But this does not: @{ Layout = "~/Views/Shared/_PdfLayout.cshtml"; ViewBag.Title = "PeptideInfo"; var imagePath = Server.MapPath("~/Content/Images"); }

The specifci stlye elements do not seem to matter. It appears that the div prevents the img from rendering.

andyhutch77 commented 9 years ago

Unfortunately the images are broken and I can't see the code you are using to render the images. Please add them and I will see if there's anything obvious.

rebeccapowell commented 9 years ago

I can also confirm this issue. If you take the demo code:

@model MvcRazorToPdfExample.Models.PdfExample
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_PdfLayout.cshtml";
    var imagePath = Server.MapPath("~/Content/Images");
}
<h1>@Model.Heading</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum a urna metus. In id magna eget sapien vehicula sollicitudin fermentum nec ante. Ut iaculis vehicula leo nec posuere. Duis ornare hendrerit sem, nec volutpat nisi placerat a. Nullam convallis vitae augue vitae fringilla. Nunc viverra commodo laoreet. Vivamus fermentum ligula eros, eget sagittis justo euismod eget. Donec dolor neque, scelerisque vel vulputate quis, tincidunt et odio. Duis eget est risus. Phasellus ut nulla accumsan, malesuada sapien non, ornare nibh.
</p>
<img src="@imagePath\avatar.jpg" alt="mug shot" /><br />
<a href="http://www.highviewsoftwaresolutions.co.uk">http://www.highviewsoftwaresolutions.co.uk</a>

and surround the image with a div:

@model MvcRazorToPdfExample.Models.PdfExample
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_PdfLayout.cshtml";
    var imagePath = Server.MapPath("~/Content/Images");
}
<h1>@Model.Heading</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum a urna metus. In id magna eget sapien vehicula sollicitudin fermentum nec ante. Ut iaculis vehicula leo nec posuere. Duis ornare hendrerit sem, nec volutpat nisi placerat a. Nullam convallis vitae augue vitae fringilla. Nunc viverra commodo laoreet. Vivamus fermentum ligula eros, eget sagittis justo euismod eget. Donec dolor neque, scelerisque vel vulputate quis, tincidunt et odio. Duis eget est risus. Phasellus ut nulla accumsan, malesuada sapien non, ornare nibh.
</p>
<div><img src="@imagePath\avatar.jpg" alt="mug shot" /></div><br />
<a href="http://www.highviewsoftwaresolutions.co.uk">http://www.highviewsoftwaresolutions.co.uk</a>

The image no longer renders.

It seems that images that are too large (for the canvas) do not resize within a div, whilst when not inside a div they scale to the document container width.

andyhutch77 commented 9 years ago

Hi @benpowell I've not seen this before however I am restricted to what the xmlWorker does with the xhtml. I'm surprised it won't output that mind, seems pretty simple mark-up.