2

How can I put an image on the itextSharp generated pdf?

I have a simple method at the controller...

    public ActionResult Pdf()
    {

        var pdfResult = new PdfResult(null,"Pdf");
        pdfResult.ViewBag.Title = "Title";

        return pdfResult;
    }

And a simple view...

@{
    Layout = null;
}

<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF">

    Html Text for test.

    <img src="~/Images/sampleImage.png" />

</itext>

Any help would be appreciated!

3 Answers3

1

try:

<image url="@Context.Server.MapPath("~/Images/sampleImage.png")" />

and check out the samples over at github

Marc Wittke
  • 2,991
  • 2
  • 30
  • 45
  • Marc How to add custom height and width to the image instead of re-sizing it?? – Nikitesh Jan 27 '14 at 11:27
  • @NikiteshKolpe I've never been able to find that out but I usually just throw it into a table and change the `widths` in ``. the Image then seems to scale
    – joetinger Sep 16 '14 at 19:40
0

just change the source as shown below:

 <img src="@Context.Server.MapPath("~/Images/sampleImage.png")" width="100" height="100"/>
Nikitesh
  • 1,287
  • 1
  • 17
  • 38
0

this worked for me:

<div style="margin:auto;width:60%;padding:10px;">
    <img src="@Server.MapPath("~/assets/img/image.png")" />
</div>
JustLearning
  • 3,164
  • 3
  • 35
  • 52