开发者

How to export GridView data to pdf file in Asp.net and C#?

Currently I am facing the tedious problem of exporting complete GridView data t开发者_如何学运维o the pdf file so that the user can save it. I am using C# as the language in Asp.net 3.5. Kindly guide me.

The gridview contains only text values.

Thanks in advance.


Export GridView to Pdf using iTextSharp ASP.NET
Exporting GridView to PDF

I haven't done this myself.


nFOP + XSLT + XML = pdf | doc | HTML

open source no cost :)

K


public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}

protected void GeneratePDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.RenderControl(hw);
    GridView1.HeaderRow.Style.Add("width", "15%");
    GridView1.HeaderRow.Style.Add("font-size", "10px");
    GridView1.Style.Add("text-decoration", "none");
    GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView1.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);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();   
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜