我在用户记录数据库中有一个表,其中有一列Profile Pic
,其中包含~/images/user.JPEG
等图像。我想将此数据导出为PDF。
我正在使用名为iTextSharp的第三方库,我想在用户名前面的PDF文件中显示图像。我该怎么做?。
我将网格视图与数据库绑定,它在网格视图中显示,但当我以PDF格式导出时,它显示图像的位置而不是图像。
这是我的代码,它使用表格和PdfPCell。
System.Web.UI.WebControls.Image image = (System.Web.UI.WebControls.Image)rows.FindControl("imgprofile");
string imagedummy = image.ImageUrl;
PdfPCell c1 = new PdfPCell(new Phrase(id.Text, verdana));
PdfPCell c2 = new PdfPCell(new Phrase(firstname.Text, verdana));
PdfPCell c3 = new PdfPCell(new Phrase(lastname.Text, verdana));
PdfPCell c14 = new PdfPCell(new Phrase(image dummy));
t1.Add Cell(c14);
答案 0 :(得分:1)
如果您有图像的路径,例如imgPath
,您可以通过创建Image
对象在PDF中使用该图像。请参阅本书第10章的示例:http://tinyurl.com/itextsharpIIA2C10
Image img = Image.GetInstance(imgPath);
拥有此Image
对象后,您可以使用该图片作为参数创建PdfPCell
,您可以使用PdfPCell
将其添加到addElement()
, Chunk
内的图片,...
所有这些不同的方法,都会表现出不同的行为。这些都在the iText documentation中解释过。