1

i am developing an app in which i want to give support of export data in to pdf if user want then he can get the grid data into pdf . i have tried many methods but not working. its working by using itextsharp third party dll but not directly . Using :c# ,asp.net

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);
    GridView1.AllowPaging = 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(); 
}
user1830210
  • 31
  • 2
  • 9

3 Answers3

0

Pdf stands for portable document format. Since it is a standard format you will have to put your data in that format only. other wise it will be a corrupt file and wont be prased by pdf readers. You will have to use 3rd party tools or roll your own.

Ratna
  • 2,289
  • 3
  • 26
  • 50
0

Writing a decent PDF parser is a huge amount of work (we are talking years) so most people find it far more cost-effective so license IText or a similar library.

mark stephens
  • 3,205
  • 16
  • 19
-1

you can do it by using isharptext if you want to do it with code than you'll have to write parser .

ashi
  • 108
  • 11