如何解决Pandas 样式不读取 css id
我正在从熊猫生成以下 html。
<style type="text/css" >
#T_header_tablerow0_col3,#T_header_tablerow0_col4{
background-color: #F5ABAB;
}
</style>
<table id="T_header_table" class="header-table">
<thead>
<tr>
<th class="col_heading level0 col0" >Threshold</th>
<th class="col_heading level0 col1" >Limit Amount</th>
<th class="col_heading level0 col2" >utilization (Historical Cost)</th>
<th class="col_heading level0 col3" >Threshold Breach</th>
<th class="col_heading level0 col4" >Limit Breach</th>
</tr>
</thead>
<tbody>
<tr>
<td id="T_header_tablerow0_col0" class="data row0 col0" >778.900000</td>
<td id="T_header_tablerow0_col1" class="data row0 col1" >1</td>
<td id="T_header_tablerow0_col2" class="data row0 col2" >2</td>
<td id="T_header_tablerow0_col3" class="data row0 col3" >0</td>
<td id="T_header_tablerow0_col4" class="data row0 col4" >0</td>
</tr>
</tbody>
</table>
但是当我尝试使用此 html 中的 itext 生成 pdf 时,基于 id 的内联样式不会生效,并且我看不到颜色。有人可以帮我吗?
这是我的itext代码
HtmlConverter.convertToPdf(new File(inputFile),new File(outputFile));
解决方法
这是pdfHTML 中的一个错误。确切的问题是它不能优雅地处理以大写字母开头的 ID。因此,作为一种解决方法,您可以将 HTML 更改为:
<style type="text/css" >
#t_header_tablerow0_col3,#t_header_tablerow0_col4{
background-color: #F5ABAB;
}
</style>
<table id="T_header_table" class="header-table">
<thead>
<tr>
<th class="col_heading level0 col0" >Threshold</th>
<th class="col_heading level0 col1" >Limit Amount</th>
<th class="col_heading level0 col2" >Utilization (Historical Cost)</th>
<th class="col_heading level0 col3" >Threshold Breach</th>
<th class="col_heading level0 col4" >Limit Breach</th>
</tr>
</thead>
<tbody>
<tr>
<td id="T_header_tablerow0_col0" class="data row0 col0" >778.900000</td>
<td id="T_header_tablerow0_col1" class="data row0 col1" >1</td>
<td id="T_header_tablerow0_col2" class="data row0 col2" >2</td>
<td id="t_header_tablerow0_col3" class="data row0 col3" >0</td>
<td id="t_header_tablerow0_col4" class="data row0 col4" >0</td>
</tr>
</tbody>
</table>
它应该产生正确的结果。
同时,如果您正在考虑为 pdfHTML 做出贡献,您可能需要查看 CssSelectorParser
中的 SELECTOR_PATTERN_STR
类和正则表达式 - (#[_a-z][\w-]*)
部分是需要修复的部分。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。