Заголовок таблицы TCPDF автоматически перемещается вправо - PullRequest
0 голосов
/ 12 апреля 2019

Я создал таблицу с TCPDF. Заголовок с черным фоном расположен немного вправо, как будто с левой стороны есть отступы. Я не могу заставить его правильно выстроиться.

Screenshot of table with the issue

Код ниже - это HTML-код, который я написал для формирования таблицы.

$tbl ='<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>

<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
        <th width="1px"></th>
        <th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;">     <strong>Product or Service</strong></th>
        <th width="1px"></th>
        <th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
        <th width="1px"></th>
        <th width="84px"><strong>Total</strong></th>
    </tr>
    
    <tr>
        <td height="267px">';
            while($i <= $a) {
                $tbl .= '<table height="267px" width="60px"><tr><td>' . $productsArray['product_quantity'][$i] . '</td></tr></table>';
                $i++;
            }
            $tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
            while($j <= $a) {
                $tbl .= '<table height="267px" width="388px"><tr><td class="tal">     ' . $productsArray['product_name'][$j] . '</td></tr></table>';
                $j++;
            }
            $tbl .= '</td><td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
            while($k <= $a) {
                $tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_price'][$k] . '</td></tr></table>';
                $k++;
            }
            $tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
            while($l <= $a) {
                $tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_sub'][$l] . '</td></tr></table>';
                $l++;
            }
$tbl .= '</td>
    </tr>
</table>';
}

Ниже приведен код PHP, который я использовал для отображения таблицы на странице.

$pdf->writeHTMLCell(175, 80, 20, 100, $tbl, 1, 1, 0, true, 'C', true);

1 Ответ

0 голосов
/ 12 апреля 2019

Использование таблиц в ячейках другой таблицы, как правило, является очень плохой идеей и, вероятно, усугубляет проблему, с которой вы столкнулись. Поскольку, похоже, у вашего productsArray уже есть все необходимые данные, я просто перебрал бы его, выводя каждую строку по ходу работы.

Стоит также отметить, что пустые строки заголовка, которые определены с шириной 1px, конфликтуют с вашими фактическими строками данных, которые определены с шириной 0.5px.

<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>

<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
        <th width="1px"></th>
        <th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;">     <strong>Product or Service</strong></th>
        <th width="1px"></th>
        <th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
        <th width="1px"></th>
        <th width="84px"><strong>Total</strong></th>
    </tr>

<?php
while($i <= $a) {
?>
<tr>
    <td height="267px"><?php echo $productsArray['product_quantity'][$i]; ?></td>
    <td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
    <td height="267px"><?php echo $productsArray['product_name'][$i]; ?></td>
    <td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
    <td height="267px"><?php echo $productsArray['product_price'][$i]; ?></td>
    <td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
    <td height="267px"><?php echo $productsArray['product_sub'][$l]; ?></td>
</tr>
<?php
    $i++;
}
?>
</table>
...