Convert HTML to PDF in C# using iTextSharp

You can use iTextSharp in a commercial application and it does not require your app to be released as open source. But it will not work with complex HTML pages and will give fairly good results with simple HTML pages. Specially, tables are not yet supported.


iTextSharp-- http://itextsharpsl.codeplex.com/.


Code Snippet
  1. // create converter
  2. HtmlToPdfConverter html2pdf = new HtmlToPdfConverter();
  3. // open new pdf file
  4. html2pdf.Open(@"test");
  5. // start a chapter
  6. html2pdf.AddChapter(@"Dummy Chapter");
  7. string html = ...;
  8. // convert string
  9. html2pdf.Run(html);
  10. // add a new chapter
  11. html2pdf.AddChapter(@"Boost page");
  12. // read web page
  13. html2pdf.Run(new Uri(@"http://www.apple.com"));
  14. // close and finish pdf file.
  15. html2pdf.Close();  


Post a Comment