我想使用img控件在顶部添加公司徽标。但在以pdf格式下载图像时,它不会显示。同时为图像显示远程网址链接,但同时为文件夹的服务器路径提供不显示图像
<table style="border-collapse: collapse;border: 1px solid;width:666px" align="center">
<tr style="border: 1px solid;">
<td style="border: 1px solid;width:50%" colspan="2">
<img src="img/kst.png" />
</td>
<td style="border: 1px solid;width:50%" colspan="2">Hyderabad, India</td>
<br />
<br />
</tr>
背后的代码
string Projname = "Payslip";
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename=\"{0}.pdf\"", Projname));
// Response.AddHeader("content-disposition", "attachment;filename=WeeklyReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
design.RenderControl(htmlWrite);
string myText = stringWrite.ToString();
StringReader sr = new StringReader(myText.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
Response.ContentType = "application/pdf";
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
Response.End();
pdfDoc.Dispose();
design.Visible = false;
答案 0 :(得分:1)
使用绝对网址作为src="img/kst.png"
的图片来源,尝试使用src="http://yourdomain.com/img/kst.png"
答案 1 :(得分:1)
我用这个:
<img src="@System.Web.HttpContext.Current.Server.MapPath("~/Images/????.???")" />
它对我有用。
如果您发布项目,则无法更改PATH