iText pdf library
Website search

Why doesn't CSS and RowSpan work?

I am trying to convert Html to PDF. I found that iTextSharp does not support CSS well. In fact, I think HtmlWorker does not support it all, nor does not it seem to support RowSpan either.

Unwanted result

Posted on StackOverflow on Oct 31, 2014 by arbaaz

Please take a look at the following screen shot:

HTML to PDF conversion

HTML to PDF conversion

To the left, you see an HTML file rendered in a browser. To the right, you see that HTML file rendered to PDF using iText (the Java version).

There are three reasons why your application doesn't work:

  1. Your HTML doesn't make sense. I had to clean it up (change
    <br />
    into , introduce the correct CSS, correct the column-count for some rows,...) and make it XHTML before it rendered correctly in a browser. You can find the HTML that was used in the screen shot here: table2_css.html
  2. You are using HTMLWorker instead of XML Worker, and you are right: HTMLWorker has no support for CSS. Saying CSS doesn't work in iTextSharp is wrong. It doesn't work when you use HTMLWorker, but that's documented: the CSS you need works in XML Worker.
  3. You are probably using an old version of iTextSharp, and you are right: CSS and table support wasn't as good as in older versions of iTextSharp when compared to the most recent version.

Apart from iTextSharp, you also need to download XML Worker. Most of the examples on the web site are written in Java, but you should have no problem converting them to C#. The example I used to make the PDF in the screen shot (html_table_4.pdf) can be found here: ParseHtmlTable4

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

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