简体   繁体   中英

How to set background color of HTML table for output to PDF with iTextSharp

I have some HTML that I am rendering out to a PDF file with iTextSharp. However, I'm having some issues with setting the background colors of my table cells. Here is some sample HTML I am using:

<tr align="center">
<th width="16%" colspan="2" style="height: 16px; font-weight:bold;" color="#FF0000">Test Colored Text</th>
<td width="28%" colspan="2" style="height: 16px;"><asp:Literal runat="server" ID="litData" /></td>
</tr>

The <th> element in this case has some properties being set via the style property. In this case height and font-weight. Also, I have a color property being set on this as well.

This outputs a table to my PDF file where the "Test Colored Text" text is set to Red as per the color property. My goal is to set the background color of this cell, and have tried adding the css property background-color to the style tag with no luck.

Being that the color property is being read I tried a few other properties to see if any would take: background-color , backgroundcolor , basecolor

However, none of these effectively change the background color of the cell in the PDF file.

My question is, what is the property name that it is looking for to set the background color? I've looked around a bit and have only found ways where people do this buy building the cells in the code, which for me is not an option as I am stuck with this HTML that needs to be styled.

Edit: Using the bgcolor property sets the background of the cell. Thanks Louis!

尝试使用bgcolor属性。

<th  bgcolor="#FFFF00" color="#FF0000">Test Colored Text</th>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM