2012-01-30 52 views
0

我的工作从创建HTML模板文件中的PDF在那里我定义的占位符代替占位符。我能够与像如何与图像中iTextSharp的

content.Replace([ “PRODUCT_ID”],TextBox1.text)一些文本替换占位符;

是没有什么办法还可以取代有一个复选框的占位符(带有选中还是未选中根据条件)?

回答

0

创建两个图像,一个是“选中”状态,“未选中”复选框,并使用IF语句来得到正确的图像:即:

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(); 
} 
+0

古斯塔沃嗨,我很欣赏你的答案。但我怎么能插入图像到一个占位符以类似的方式,我们用文本替换一个占位符:(content.Replace([“Product_ID”],TextBox1.text);) – 2012-01-30 23:31:53

+0

什么是内容? – 2012-01-30 23:34:08

+0

内容是一个包含html中所有文本的变量。我想知道是否有一种方法来替换占位符与图像通过使用类似的方法,如替换() – 2012-01-31 00:24:53