html to pdf conversion

View: New views
4 Messages — Rating Filter:   Alert me  

html to pdf conversion

by PKSINGH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
     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 conversion

by mfreidge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HtmlParser.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/ 
 
PKSINGH wrote:
Hi,
     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();

Parent Message unknown Re: html to pdf conversion

by Gerard Hulshoff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ik ben op vakantie. Voor dringende zaken kunt u bellen met Compano of een mail sturen naar support@....

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: html to pdf conversion

by ProTurbo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I guess you should use HTMLWorker instead of HtmlParser. It's more flexible and is supported. HtmlParser is not supported anymore.



HtmlParser.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/ 
 
PKSINGH wrote:
Hi,
     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();

LightInTheBox - Buy quality products at wholesale price