Charlie Walker
Charlie Walker

Reputation: 273

table borders disappearing in tcpdf

I'm setting up tcpdf to generate invoices on the fly for customers, but when I add an image, the borders are disappearing from my table. Here's the code:

/*
if ($status == "Paid") {
    $pdf->Image("/wp-content/themes/Feather/images/Paid.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
} elseif ($status == "Overdue") {
     $pdf->Image("/wp-content/themes/Feather/images/Overdue.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
} elseif ($status == "Cancelled") {
     $pdf->Image("/wp-content/themes/Feather/images/Void.jpg", 10, 60, 190, '', '', '', 'T', false, "300", '', false, false, 0, false, false, false);
}
*/
$pdf->SetXY($x=20, $y=30);
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();

Here's the HTML I'm using:

$html = $html . '
<br/><br/><br/>
<table width="600px" cellspacing="1" cellpadding="4" border="1">
<tr>
    <th width="200px">Product</th>
    <th width="65px">Code</th>
    <th width="65px">Quantity</th>
    <th width="65px">Unit Price</th>
    <th width="65">VAT Rate</th>
    <th width="65">VAT Amount</th>
    <th width="65">Line Total</th>
</tr>';
foreach ($inv_lines as $inv_line) {
$html = $html .
        '<tr>
        <td>' . $inv_line['item_desc'] . '</td>
        <td>' . $inv_line['item_no'] . '</td>
        <td>' . $inv_line['quantity'] . '</td>
        <td>' . $inv_line['unit_price'] . '</td>
        <td>' . $inv_line['vat_rate'] . '</td>
        <td>' . ($inv_line['quantity'] * $inv_line['vat_rate'] * $inv_line['unit_price'] * 0.01) . '</td>
        <td>' . $inv_line['line_total'] . '</td>
    </tr>';

The table appears fine with the code as above, but as soon as I uncomment the image bits, the image appears, but the table borders disappear. I've tried adding inline borders to individual cells, but that doesn't make any impact.

Does anyone have any ideas?

Upvotes: 5

Views: 16495

Answers (2)

Ajmal Tk
Ajmal Tk

Reputation: 163

Always use "1" (double quotes)not single quotes border='1' as table border value.

Upvotes: 4

EPB
EPB

Reputation: 4029

First off, make absolutely certain you're always including the end table tag. TCPDF's html parser can be picky about having opening and closing tags. (I only say this because it's missing in the question.) It relies on correct markup to function properly.

Now I'm not sure just by looking at your coordinates, but does the table overlap the image? If it does and you want the borders to be drawn on top of the image, you'll need to call setPageMark after you draw the image. If you don't, the borders will be drawn below the image no matter what order you have the Image and writeHTML calls in.

<?php
//In my test PDF I had to do something like this as some of my borders
//were disappearing underneath my test image.
$pdf->Image(...);
$pdf->setPageMark();
$pdf->setXY(...)
$pdf->writeHTML(...);

If the border is still not there, that is neither of the above help, you might wanna try setting the draw color after placing the image. I'm not sure if that would do anything, but it's worth a shot.

Of course, make sure you're on an updated version of TCPDF, depending on your version there may be border rendering fixes.

Upvotes: 18

Related Questions