GriedView Pdf download

GriedView Pdf download

Here  i wanna  share  something with you about Gridview PdF Format Download..

.aspx Part

<div id ="kandy" runat="Server">
Put your content Those u wana  in pDf
</div>




.CS Part


Here  u include some Namespace like :

using System.Text;
using System.IO;
using System.Diagnostics;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;





//Write This code on any Event At which you wanna generate PDF.



  string attachment = "attachment; filename='" + q_str + "'.pdf";

        Response.ClearContent();

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/pdf";

        StringWriter stw = new StringWriter();

        HtmlTextWriter htextw = new HtmlTextWriter(stw);

        kandy.RenderControl(htextw);

        Document document = new Document();

        PdfWriter.GetInstance(document, Response.OutputStream);

        document.Open();

        StringReader str = new StringReader(stw.ToString());

        iTextSharp.text.html.simpleparser.HTMLWorker htmlworker = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
        ;
        htmlworker.Parse(str);

        document.Close();

        Response.Write(document);
        Response.End();

Comments

Post a Comment

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click