Formview to PDF
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
Hi to all, I am using formview control to generate invoice. Instead of printing html view , it is printing html code in PDF. I am doing like this:
public void generate() { MemoryStream m = new MemoryStream(); Document document = new Document(PageSize.A4, 10f, 10f, 10f, 0f); try { Response.ContentType = "application/pdf"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); FormView1.RenderControl(htw); string html = sw.ToString() ; StringBuilder str = new StringBuilder(); str.Append("<h3><b>Online Application Form Details </b></h3>"); str.Append(html); PdfWriter writer = PdfWriter.GetInstance(document, m); writer.CloseStream = false; document.Open(); document.Add(new Paragraph(str.ToString())); } catch (DocumentException ex) { Console.Error.WriteLine(ex.StackTrace); Console.Error.WriteLine(ex.Message); } document.Close(); Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); string filename = "~/Invoices/sample.pdf"; string path = Server.MapPath(filename); m.WriteTo(new FileStream(@path, FileMode.Create)); m.Close(); } public override void VerifyRenderingInServerForm(Control control) { }
please assist me.....
cheers, sneha