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

后端 未结 1 1354
半阙折子戏
半阙折子戏 2021-01-26 05:12

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

相关标签:
1条回答
  • 2021-01-26 06:01

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

    enter image description here

    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.

    0 讨论(0)
提交回复
热议问题