如何使用itextsharp在表格列中以pdf格式显示图像 [英] How to display image in pdf in table column using itextsharp
本文介绍了如何使用itextsharp在表格列中以pdf格式显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上我能够以pdf格式插入图片但无法在pdf格式的表格列中插入图片..
我尝试过:
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();
}
}
}
推荐答案
试试看,告诉我。
如何在C#中将图像插入PDF网格单元格 [ ^ ]
Try this out and let me know.
How to Insert an Image to PDF Grid Cell in C#[^]
这篇关于如何使用itextsharp在表格列中以pdf格式显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文