1
Reply

How i Print the Datagrid Record in Pdf Format.....?

    use itextsharp.dlluse this method public void WritePDF(){switch (FileType){case "PDF":{try{StringWriter sw = new StringWriter();System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);System.Web.UI.HtmlControls.HtmlForm frm = new System.Web.UI.HtmlControls.HtmlForm();HttpContext.Current.Response.ContentType = "application/pdf";HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Export.pdf");HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);GV.Parent.Controls.Add(frm);frm.Attributes["runat"] = "server";frm.Controls.Add(GV);frm.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, HttpContext.Current.Response.OutputStream);pdfDoc.Open();htmlparser.Parse(sr);pdfDoc.Close();HttpContext.Current.Response.Write(pdfDoc);HttpContext.Current.Response.End();}catch (Exception f){}break;}case "Word":{HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Export.doc");HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);HttpContext.Current.Response.ContentType = "application/vnd.word";StringWriter stringWrite = new StringWriter();System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);System.Web.UI.HtmlControls.HtmlForm frm = new System.Web.UI.HtmlControls.HtmlForm();GV.Parent.Controls.Add(frm);frm.Attributes["runat"] = "server";frm.Controls.Add(GV);frm.RenderControl(htmlWrite);HttpContext.Current.Response.Write(stringWrite.ToString());HttpContext.Current.Response.End();break;}case "Excel":{try{string attachment = "attachment; filename=Export.xls";HttpContext.Current.Response.ClearContent();HttpContext.Current.Response.AddHeader("content-disposition", attachment);HttpContext.Current.Response.ContentType = "application/ms-excel";StringWriter sw = new StringWriter();System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);System.Web.UI.HtmlControls.HtmlForm frm = new System.Web.UI.HtmlControls.HtmlForm();GV.Parent.Controls.Add(frm);frm.Attributes["runat"] = "server";frm.Controls.Add(GV);frm.RenderControl(htw);HttpContext.Current.Response.Write(sw.ToString());HttpContext.Current.Response.End();}catch (Exception f){}break;}}}