簡體   English   中英

在將html導出為pdf圖像時,asp.net中的itextsharp pdf文檔中未顯示

[英]while exporting html to pdf image is not displaying in itextsharp pdf document in asp.net

我想使用img控件在頂部添加公司徽標。 但是在下載pdf格式的圖像時,它不會顯示。 在提供遠程url鏈接以顯示圖像的同時,在提供文件夾的服務器路徑而不顯示圖像的同時

 <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;

使用絕對網址作為src="img/kst.png"圖像源嘗試類似src="http://yourdomain.com/img/kst.png"

我用這個:

<img src="@System.Web.HttpContext.Current.Server.MapPath("~/Images/????.???")" />

這個對我有用。

而且,如果您發布項目,則無需更改PATH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM