how to replace placeholder with image in iTextSharp

2.4k Views Asked by At

I am working on creating a pdf from html template file where i defined placeholders. i am able to replace the place holders with some text like

content.Replace(["Product_ID"],TextBox1.text);

is there any way i can also replace a placeholder with a checkbox(with either checked or unchecked depending on a condition) ?

1

There are 1 best solutions below

3
On

Create two images, one for the checkbox "checked" state, and "unchecked", and use an IF statement to get the right image: i.e:

string pdfpath = Server.MapPath("PDFs");
string imagepath = Server.MapPath("Images");
Document doc = new Document();
try
{
  PdfWriter.GetInstance(doc, new FileStream(pdfpath + "/Images.pdf", FileMode.Create));
  doc.Open();

  doc.Add(new Paragraph("GIF"));
  Image gif;
  if (chkBoxExample.Checked)
  { 
      gif = Image.GetInstance(imagepath + "/checked.gif");
  }
  else
  {
      gif = Image.GetInstance(imagepath + "/unchecked.gif");
  }
  doc.Add(gif);
}
finally
{
  doc.Close();
}