使用ITextSharp dll将Gridview转换为Pdf时出错... Gridview还包含一些产品图像。
try
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Gridbill.AllowPaging = false;
Gridbill.AllowSorting = false;
Gridbill.DataBind();
Gridbill.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, new FileStream(Server.MapPath("~/Admin/bills/" + random.ToString() + ".pdf"), FileMode.Create));
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
catch (Exception e)
{
clientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + e.Message + "');", true);
}
这里,random是从(1000到int max)随机生成的数字。 我在htmlParse.parse行遇到错误。 Can Any1请帮助我并建议我进行一些修改以使其正常工作..