Skip to content

PDF DOWNLOAD Question

Vasanthakumar

Asked Sep 7, 2015, 5:27 AM EDT1 answer
Share
LinkedInX
Hai Everyone,
                         When i click  the hyperlink ,I need to download the pdf document . ASP.net C# coding ??
 
Kindly help me .
 
 
Explain me step by step process
 
 
 
Thanks,
Vasanth 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sathish Kumar
    0
    Hi vasanth,
     
       When the Hyperlink_Click event triggered, there was a page load occurs, right?. You just write your PDF code on Page Load event.
     
       You just write this code on Page 
     
     
    Code
    Response.ContentType = "application/pdf";
    Code
    Response.AddHeader("content-disposition","attachment;filename= YOUR_PDF_FILENAME.pdf");
    Code
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Code
    StringWriter sw = new StringWriter();
    Code
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    Code
    YOUR_GridView.RenderControl(hw);
    Code
    StringReader sr = new StringReader(sw.ToString());
    Code
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    Code
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    Code
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    Code
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    Code
    pdfDoc.Open();
    Code
    htmlparser.Parse(sr);
    Code
    pdfDoc.Close();
    Code
    Response.Write(pdfDoc);
    Code
    Response.End();
    Code
    Code
    Code
    0