Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# PDF
I want to convert my webpage to pdf , for that is it necessary to to build html then convert that html to pdf?
 
Thanks in Advance.
Posted 2-Jul-12 4:24am
Comments
nani1221 at 28-Sep-12 4:50am
   
If i run this code i got an error i.e,
 
A page can have only one server-side Form tag.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can convert the web page content into PDF using iTextSharp library. Download ITextsharp and add its reference to your project. ITextsharp is a free HTML to PDF Library at http://sourceforge.net/projects/itextsharp/[^]
 
using System.IO;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
......
protected void btnExport_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.Page.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
}
  Permalink  
Comments
nani1221 at 28-Sep-12 4:48am
   
If i run this code i got an error i.e,
 
A page can have only one server-side Form tag.
Member 8083093 at 26-Oct-13 3:03am
   
me also , getting same error
a page can have only one server side form tag
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100