protected void Submitbtn_Click(object sender, EventArgs e) { { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter w = new HtmlTextWriter(sw); print.RenderControl(w) string htmWrite = sw.GetStringBuilder().ToString(); htmWrite = Regex.Replace(htmWrite, "", ""); htmWrite = htmWrite.Replace("\r\n", ""); StringReader reader = new StringReader(htmWrite); Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); string pdfFilePath = Server.MapPath(".") + "/PDFFiles"; HTMLWorker htmlparser = new HTMLWorker(doc); PdfWriter.GetInstance(doc, Response.OutputStream); doc.Open(); try { htmlparser.Parse(reader); doc.Close(); Response.Write(doc); Response.End(); } catch (Exception ) { } finally { doc.Close(); } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)