5

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?

4

2 に答える 2

17

まず、常に end table タグを含めていることを確認してください。TCPDF の html パーサーは、開始タグと終了タグを持つことにうるさい場合があります。(質問にないので、これだけを言います。)正しく機能するには、正しいマークアップに依存しています。

座標を見ただけではわかりませんが、テーブルは画像と重なっていますか? その場合、境界線を画像の上に描画したい場合は、画像setPageMarkを描画した後に呼び出す必要があります。そうしないと、Image 呼び出しと writeHTML 呼び出しの順序に関係なく、境界線が画像の下に描画されます。

<?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(...);

上記のいずれの方法でも境界線が表示されない場合は、画像を配置した後に描画色を設定してみてください。それが何かをするかどうかはわかりませんが、試してみる価値はあります。

もちろん、TCPDF の最新バージョンを使用していることを確認してください。バージョンによっては、境界線のレンダリングが修正されている場合があります。

于 2013-02-27T06:59:18.170 に答える