Created
May 5, 2016 06:06
-
-
Save guntidheerajkumar/00dbd18918d7c8458a8a64b94f8b1e60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Response.ContentType = "application/pdf"; | |
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf"); | |
Response.Cache.SetCacheability(HttpCacheability.NoCache); | |
StringWriter sw = new StringWriter(); | |
HtmlTextWriter hw = new HtmlTextWriter(sw); | |
HtmlForm frm = new HtmlForm(); | |
GrdView.Parent.Controls.Add(frm); | |
frm.Attributes["runat"] = "server"; | |
frm.Controls.Add(GrdView); | |
frm.RenderControl(hw); | |
StringReader sr = new StringReader(sw.ToString()); | |
Document pdfDoc = new Document(PageSize.A4, 30f, 30f, 20f, 20f); | |
pdfDoc.SetMargins(40f, 40f, 40f, 40f); | |
HTMLWorker htmlparser = new HTMLWorker(pdfDoc); | |
PdfWriter.GetInstance(pdfDoc, Response.OutputStream); | |
pdfDoc.Open(); | |
htmlparser.Parse(sr); | |
pdfDoc.Close(); | |
Response.Write(pdfDoc); | |
Response.End(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment