how can I add cellspacing to pdftable when parsing html using XMLWorker and itext

不问归期 提交于 2019-12-20 07:16:52

问题


I am using XMLWorker and itext to convert html to pdf . my html have a table and I need to set it's cellspacing =0 cellpadding=0 . does anyone know how to do it ?

in html I saw I can replace it by setting the style :

border-collapse: collapse; border-spacing: 0px ; border : 0; padding : 0;

thanks Tami


回答1:


I've tried what you're doing using the CSS you propose and it works for me:

You can find my test here: ParseHtmlTable5

This is my HTML (including the CSS): table3_css.html

<html>
<head>
<style>
    table, td {
        border: 1px solid green;
        border-spacing: 0px;
        padding: 0px;
    }
</style>
</head>
<body>
<table class='test'>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>Peter</td>
    <td>Griffin</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>Lois</td>
    <td>Griffin</td>
    <td>$150</td>
  </tr>
  <tr>
    <td>Joe</td>
    <td>Swanson</td>
    <td>$300</td>
  </tr>
  <tr>
    <td>Cleveland</td>
    <td>Brown</td>
    <td>$250</td>
</tr>
</table>
</body>
</html>

I suggest that you compare your HTML with mine to find out what you're doing wrong. You should also use the latest version of XML Worker and iText(Sharp) as we've improved HTML parsing significantly in the latest releases.

Note that I've defined a solid, green border of 1px to prove that there is no padding and no spacing between the cells. If you change the CSS like this:

<style>
    table, td {
        border: 0px;
        border-spacing: 0px;
        padding: 0px;
    }
</style>

You'll get the (ugly) version of a table without borders, without spacing between the cells and without padding inside the cells.



来源:https://stackoverflow.com/questions/26698532/how-can-i-add-cellspacing-to-pdftable-when-parsing-html-using-xmlworker-and-itex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!