I'm using java i text for generating pdf. Some data in my pdf is from h开发者_StackOverflow中文版tml. I'm using HTMLWorker.parseToList
to create it.
My problem is that it ignores the background color that is written inside the html tags. Any idea why? How can i solve this?
Thanks in advance.
Spotty CSS Support strikes again.
iText doesn't currently support the backgroundcolor
style. It does support the bgcolor
attribute however, and attributes and styles are mapped into the same namespace.
So if you XSLT your incoming HTML, you could add a matching bgcolor attribute, or simply change the style string to bgcolor
.
Ugly, but effective.
iText's HTML->PDF conversion code is supposed to get a major upgrade in the next release. The groundwork was laid in the 5.0.6 release, though I haven't seen any code changes that will actually improve the output as yet.
It works with bgcolor when used as a direct attribute (but not in style attribute with "background-color")
<table border="1" cellpadding="2">
<tr bgcolor="#C0C0C0">
<td><b>Gray Header</b></td>
<td><b>Second header</b></td>
</tr>
<tr>
<td style="color:green">Green text</td>
<td bgcolor="#FFC0C0">Red background</td>
</tr>
</table>
I tried the below workaround and it perfectly works for me.
.tr-bg{
background-color: #D3D3D3;
}
And use this class for required dom element.
精彩评论