1

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

tamih
  • 93
  • 1
  • 15

1 Answers1

1

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.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • I tried your code and it is correct , my problem might be related to rowSpan and colspan . Do the parser support those prperties ? – tamih Nov 02 '14 at 12:03
  • 1
    If my answer is correct, accept it. Do not use the comments to add a new question. Before asking a question if something works, try. If it doesn't work, search StackOverflow. Yesterday, I provided proof that rowspan and colspan work: http://stackoverflow.com/questions/26679003/rowspan-does-not-work-in-itextsharp You could have found that proof if only you looked at the other table examples on the official iText site: http://itextpdf.com/sandbox/xmlworker – Bruno Lowagie Nov 02 '14 at 12:56
  • thanks for the help , is there a way to define that images that are parsed will have padding =0 ? so the cell will be exactly in the image size ? – tamih Nov 05 '14 at 08:48
  • I have images inside a table cells , and when I convert the html to pdf some of the images add padding , I need the cell to be exactly at the image size (without any padding ,margin ,spacing) is there a way to do it ? so the cell will be exactly at the image scale. (I know Itext can set Images like: img.setSpacingAfter(0); img.setSpacingBefore(0);) but don't know how to do that in the converting.. – tamih Nov 05 '14 at 09:27
  • Is there a way to do it? It depends. Maybe the size of the cell exceeds the size of the image. You won't get an answer from me because: (1) you don't share a SSCCE with a simple HTML that reproduces the problem, and (2) my time is limited and I've already spent plenty of free time on your questions without knowing if there will be a return on investment. Also: you're using the comment section of an answer to post a different question. (Which is not done on StackOverflow.) – Bruno Lowagie Nov 05 '14 at 09:31