ItextSharp - RazorPdf put image to Pdf

How can I put the image in the itextSharp generated pdf?

I have a simple method on a controller ...

    public ActionResult Pdf()
    {

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

        return pdfResult;
    }

      

And a simple look ...

@{
    Layout = null;
}

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

    Html Text for test.

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

</itext>

      

Any help would be appreciated!

0


source to share


3 answers


try:

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



and check the samples on github

+1


source


just change the source like below:



 <img src="@Context.Server.MapPath("~/Images/sampleImage.png")" width="100" height="100"/>

      

0


source


this worked for me:

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

      

0


source







All Articles