简体   繁体   English

使用ITextRenderer生成PDF后,内部样式不适用

[英]Internal styles are not applying after generating PDF using ITextRenderer

I'm using ITextRenderer to generate pdf in my application by loading a html file with internal styles. 我正在使用ITextRenderer通过加载带有内部样式的html文件在我的应用程序中生成pdf。 My HTML page is like this: 我的HTML页面是这样的:

<html>
<head>
    <style type="text/css">.TFtable tr:nth-child(even) {background: #ffffff; border:none;}</style>
</head>
<body>
    <table class="TFtable" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th align="left" valign="middle" scope="col"> Customer </th> </tr>
    </table>
</body>
</html>

Interestingly, it's working fine for me. 有趣的是,它对我来说很好。 Please note that in the sample html code that you provided, you are setting background color as white. 请注意,在您提供的示例html代码中,您将背景色设置为白色。 Also, you are adding only one row to the table. 另外,您只向表添加一行。 As, you are using 'tr:nth-child(even)' as a selector, the style will not be applied to the first row (which odd number). 因为,您正在使用“ tr:nth-​​child(even)”作为选择器,所以样式将不会应用于第一行(奇数)。 Try following code, which is slight modification to your sample code. 尝试以下代码,这是对示例代码的略微修改。

 <html> <head> <style type="text/css"> .TFtable tr:nth-child(even) { background: #eee; border: none; } </style> </head> <body> <table class="TFtable" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th align="left" valign="middle" scope="col">Customer-odd</th> </tr> <tr> <th align="left" valign="middle" scope="col">Customer-even</th> </tr> </table> </body> </html> 

In output pdf (and in html) you will see second row with gray background. 在输出pdf(和html)中,您会看到第二行带有灰色背景。 I hope this is useful. 我希望这是有用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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