Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i am able to insert image in pdf but not able to insert image in table column in pdf..

What I have tried:

string imageURL = Server.MapPath(".") + "/logo.png";
       iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imageURL);

      using (StringWriter sw = new StringWriter())
      {
          using (HtmlTextWriter hw = new HtmlTextWriter(sw))
          {
              StringBuilder sb = new StringBuilder();

              sb.Append("<table  border = '0.5' cellspacing='0' cellpadding='2' width='100%'>");
              sb.Append("<tr>");

              //Resize image depend upon your need

              png.ScaleToFit(140f, 120f);

              //Give space before image

              png.SpacingBefore = 10f;

              //Give some space after the image

              png.SpacingAfter = 1f;

              png.Alignment = Element.ALIGN_LEFT;

              sb.Append("<td style='float:left;'> " + png. + " </td>");

              sb.Append("<td style='float:right;'>");
              sb.Append("web link services pvt ltd");
              sb.Append("</td>");
              sb.Append("</tr>");



              sb.Append(" </table>");

              //Export HTML String as PDF.
              StringReader sr = new StringReader(sb.ToString());
              Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
              HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
              PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
              pdfDoc.Open();
              htmlparser.Parse(sr);


              pdfDoc.Close();
              Response.ContentType = "application/pdf";
              Response.AddHeader("content-disposition", "attachment;filename=Invoice.pdf");
              Response.Cache.SetCacheability(HttpCacheability.NoCache);
              Response.Write(pdfDoc);
              Response.End();
          }
      }
  }
Posted
Updated 4-Jan-18 19:01pm

1 solution

Try this out and let me know.

How to Insert an Image to PDF Grid Cell in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900