|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
html to pdf conversionHi,
I wanted to convert my html files to pdf .I have tried iTextSharp but could not get an API which takes html file as input and give me pdf. i tried using below code but getting "Document has no pages" ERROR. Please help me to know how to use iTEXTSHARP Thanks Document document = new Document(PageSize.A4); PdfWriter pdf = PdfWriter.GetInstance(document, new FileStream("C:\\HelloWorld.pdf", FileMode.Create)); document.Open(); string htmlStr = "This is my test string"; System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlStr)); HtmlParser.Parse(document, _xmlr ); document.Close(); |
|
|
Re: html to pdf conversionHtmlParser.Parse does NOT throw any error , but the pdf file generated from this could be blank/empty.
Debug output shows the messages from parser, if Html file has invalid structure. This is a big problem: HtmlParser.Parse is very strict and any minor mistakes in HTML causes exceptions or almost silent creation of empty PDF file. At the meantime you can try to use HTML Agility Pack(http://www.codeplex.com/htmlagilitypack) as suggested at http://geekswithblogs.net/casualjim/archive/2005/11/13/59943.aspx#393262. Question to authors of the package: Is it possible to modify HtmlParser.Parse to return list of errors? Also it will be good to make it more tolerant to html mistakes, similar to most browsers tolerance. Regards, Michael Freidgeim Blog: http://geekswithblogs.net/mnf/
|
|
|
|
|
|
Re: html to pdf conversionI guess you should use HTMLWorker instead of HtmlParser. It's more flexible and is supported. HtmlParser is not supported anymore.
|
| Free Forum Powered by Nabble | Forum Help |