IText学习手册——插入图片
通过iTextSharp.text.Image.GetInstance(sysPath + @"Pic\girl.jpg")创建一个图片对象,并将其插入文档,就可以显示出来
/// <summary> /// 插入图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button24_Click(object sender, EventArgs e) { var sysPath = System.AppDomain.CurrentDomain.BaseDirectory; Document doc = new Document(); PdfWriter.GetInstance(doc, File.Open(path, FileMode.Create)); doc.Open(); var font = new iTextSharp.text.Font(BaseFont.CreateFont(), 30); doc.Add(new Paragraph("beautiful girl", font)); //插入图片 doc.Add(iTextSharp.text.Image.GetInstance(sysPath + @"Pic\girl.jpg")); doc.Close(); }
显示效果: