RGriffiths
RGriffiths

Reputation: 5970

HTML2PDF not showing the left border of <td>

I have a table of 5 columns that is generated using php. I want only the cells containing text to have a border but the length of the columns may differ. The following works fine in a browser but when using HTML2PDF I lose the left border of some cells as shown below.

numberOfRowsInTable will hold the total size of the table

$arrayCol*[ ] holds the values for each cell (one array for each column)

CSS

table {
border-collapse: collapse;    
}

.leftCell
{
border: 1px solid black;
}

.noborder
{
border: 0px;
}

PHP

<?php
$numberOfRowsInTable = 0;

if ($numberOfRowsInCol1> $numberOfRowsInTable )
{$numberOfRowsInTable = $numberOfRowsInCol1;}

if ($numberOfRowsInCol2> $numberOfRowsInTable)
{$numberOfRowsInTable = $numberOfRowsInCol2;}

.... etc from 1 to 5

if ($numberOfRowsInCol5> $numberOfRowsInTable )
{$numberOfRowsInTable = $numberOfRowsInCol5;}

<table>
for ($loop = 1; $loop <=$numberOfRowsInTable ; $loop ++)
{?>
<tr>
<?php
if ($loop <= $numberOfRowsInCol1){?>
<td class="leftCell">
<?php echo $arrayCol1[$loop-1];
}
else
{?>
<td  class="noborder">
<?php } ?>
</td>

<?php
if ($loop <= $numberOfRowsInCol2){?>
<td class="leftCell">
<?php echo $arrayCol2[$loop-1];
}
else
{?>
<td  class="noborder">
<?php } ?>
</td>
    .....
<?php
if ($loop <= $numberOfRowsInCol5)
{?>
<td class="leftCell">
<?php echo $arrayCol5[$loop-1];
}
else
{?>
<td  class="noborder">
<?php } ?>
</td>
</tr>
 <?php } ?>
</table>

The problem is where there is no text to the left of a cell that has text the side has no border.

enter image description here

Upvotes: 1

Views: 3000

Answers (1)

R3tep
R3tep

Reputation: 12864

Remove the css property border-collapse: collapse; on your table. And define your table like this :

<table cellspacing="0">

I had the same issue with the left border on my array. I suspect the left border doesn't works when you set border-collapse: collapse;. I found this workaround to fix that.

Upvotes: 1

Related Questions