How to convert an HTML table to PDF?

I have an HTML file that looks like this when I render it in a browser: When I export the String with this HTML to PDF using a Paragraph object, I get the following output: This is not w

I have an HTML file that looks like this when I render it in a browser:

HTML input

When I export the String with this HTML to PDF using a Paragraph object, I get the following output:

HTML output

This is not what I want. I want the PDF to look like the HTML in the browser.

Posted on StackOverflow on Jul 2, 2014 by user3152748

Please take a look at the examples ParseHtmlTable1 and ParseHtmlTable2. They create the following PDFs: html_table_1.pdf and html_table_2.pdf.

The table is created like this:

StringBuilder sb = new StringBuilder();
sb.append(""");

Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now