0

代码 :

protected void btnExportPDF_Click(object sender, EventArgs e)
{
    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);
    C1GridView1_listview.AllowPaging = false;
    C1GridView1_listview.DataBind();
    C1GridView1_listview.RenderControl(hw);
    C1GridView1_listview.HeaderRow.Style.Add("width", "15%");
    C1GridView1_listview.HeaderRow.Style.Add("font-size", "10px");
    C1GridView1_listview.Style.Add("text-decoration", "none");
    C1GridView1_listview.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    C1GridView1_listview.Style.Add("font-size", "8px");
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);//this is error line
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}

错误:

无法将“iTextSharp.text.html.simpleparser.CellWrapper”类型的对象转换为“iTextSharp.text.Paragraph”类型。

我该如何解决这个错误?

4

0 回答 0