Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Formview to PDF

Formview to PDF

Scheduled Pinned Locked Moved ASP.NET
htmlsysadminhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RajpootRohan
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups