Click here to Skip to main content
11,496,146 members (366 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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.
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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2015
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