0

i want to add company logo on the top using img control. but while downloading image in pdf it is not displaying. while giving remote url link for image its displaying , but while giving server path of folders its not displaying image

 <table style="border-collapse: collapse;border: 1px solid;width:666px" align="center">


      <tr style="border: 1px solid;">
            <td style="border: 1px solid;width:50%" colspan="2">

              <img src="img/kst.png" />
             </td>
            <td style="border: 1px solid;width:50%" colspan="2">Hyderabad, India</td>
            <br />
            <br />
        </tr>

code behind

string Projname = "Payslip";
                Response.Clear();
                Response.AddHeader("content-disposition", string.Format("attachment;filename=\"{0}.pdf\"", Projname));
                // Response.AddHeader("content-disposition", "attachment;filename=WeeklyReport.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                design.RenderControl(htmlWrite);

                string myText = stringWrite.ToString();
                StringReader sr = new StringReader(myText.ToString());
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
                Response.ContentType = "application/pdf";
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
                pdfDoc.Close();
                Response.End();
                pdfDoc.Dispose();
                design.Visible = false;
krishna mohan
  • 905
  • 4
  • 20
  • 38

2 Answers2

2

Use absolute url as image source for src="img/kst.png" try something like src="http://yourdomain.com/img/kst.png"

Pavan Teja
  • 3,192
  • 1
  • 15
  • 22
2

I Use this:

<img src="@System.Web.HttpContext.Current.Server.MapPath("~/Images/????.???")" />

It works for me.

And you haven't to changed the PATH if you release the project

mkl
  • 90,588
  • 15
  • 125
  • 265
Pàldi Gergő
  • 587
  • 6
  • 7