Я попытался экспортировать GridView
в PDF. Это дает ошибку:
Невозможно привести объект типа «iTextSharp.text.html.simpleparser.CellWrapper» к типу «iTextSharp.text.Paragraph».
Вот выдает ошибку
htmlparser.Parse(sr);
Я попытался экспортировать GridView
в PDF. Это дает ошибку:
Невозможно привести объект типа «iTextSharp.text.html.simpleparser.CellWrapper» к типу «iTextSharp.text.Paragraph».
Вот выдает ошибку
htmlparser.Parse(sr);
Вы должны отключить сортировку и разбиение на страницы перед привязкой данных и синтаксическим анализом.
Вот код:
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);
GridView1.AllowPaging = false; <----
GridView1.AllowSorting = false; <----
GridView1.DataBind();
GridView1.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, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();