创建 PDF 文件时,Table 行之间的对齐方式在 TCPDF 中不起作用

While creating PDF file,Table alignment between rows not working in TCPDF

Output of the PDF file

我正在使用 TCTDF 生成 PDF 文件。我在 TCPDF 中从 table 获取数据。 我想在流程中连接 table 但我得到的输出就像附加的图像一样。我正在尝试,但它不起作用。当我开始 $htmlcontent 而不关闭第二个代码的 table 标签时,它也显示错误。即使 CSS 也不能用于两个 tables

之间的边距
 $htmlcontent ='
<html>
<head>
<meta http-equiv="Content-Language" content="hi">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
td{
height: 8px;
}

</style>
</head>
<body>

<!-- ============================== Logo and address ================================= -->

<table class="table table-hover" border="0" cellpadding="8" cellspacing="0">
    <tr>
        <td>
            <center>
                <img src="../assests/images/order_logo.gif" height="75" width="150"/>
            </center>
        </td>
        <td style="text-align:right;">
            <p><strong style="font-size: 12px; color:#245580;">SCS Technology</strong><br/>
            The Address, Koregaon Park, <br/>
            Pune, Maharashtra 411001<br/>
            <strong>Mobile: </strong> +91 9988776655<br/>
            <strong>Email: </strong> company@domain.com<br/>
            </p>
        </td>
    </tr>
</table>

<p style="border-top: 2px solid #eb8b8b;"></p>

<!-- ============================== Customer name and address ================================= -->

<table class="table table-hover" border="0" cellpadding="8" cellspacing="0">
    <tr>
        <td style="text-align:left;">
            <p><strong style="font-size: 12px; color:#245580;">INVOICE TO:</strong><br/><br/>
            <strong style="font-size: 12px;">'.$clientName.'</strong><br/>
            <strong>Mobile: </strong> '.$clientContact.'<br/>
            </p>
        </td>
        
        <td>
            <table class="table table-hover" border="0" cellpadding="5" cellspacing="0">
                <tr colspan="2">
                    <th> </th>
                    <th>Order No : '.$clientName.'</th>
                </tr>
                <tr colspan="2">
                    <th> </th>
                    <th>Invoice Date : '.$orderDate.'</th>
                </tr>
                <tr colspan="2">
                    <th> </th>
                    <th>GST No : APSG6656SRT</th>
                </tr>
                
            </table>
        </td>
    </tr>
</table>

<p style="border-top: 2px solid #eb8b8b;"></p>

<br /><br />
<!-- ============================== Order Information ================================= -->
<table class="table table-hover" border="1" cellpadding="8" cellspacing="0">
    <tr>
        <th colspan="5" style="text-align:center; background-color:#eb8b8b; font-weight:bold;">Order Details</th>
    </tr>
    <tr style="text-align:center; background-color:#d9edf7; font-weight:bold;">
        <th width="10%">No</th>
        <th width="45%">Description</th>
        <th width="15%">Price</th>
        <th width="15%">Quantity</th>
        <th width="15%">Total Price</th>
    </tr>   
</table>
';
$pdf->writeHTML($htmlcontent, true, false, false, false, '');


$orderItemSql = "SELECT order_item.product_id, order_item.rate, order_item.quantity, order_item.total,
product.product_name FROM order_item
   INNER JOIN product ON order_item.product_id = product.product_id 
 WHERE order_item.order_id = $orderId";
    //$orderItemResult = $connect->query($orderItemSql);
    $order = mysqli_query($con, $orderItemSql);
    $i=0;
    while ($orderData1 = mysqli_fetch_array($order)) {
        $product_name = $orderData1['product_name'];
        $order_quantity = $orderData1['quantity'];
        $order_rate = $orderData1['rate'];
        $order_total = $orderData1['total'];
    
    $i++;

$htmlcontent ='
<table class="table table-hover" border="1" cellpadding="8" cellspacing="0" style="margin-top:-20px !important;">   
    <tr>
        <td width="10%">'.$i.'</td>
        <td width="45%">'.$product_name.'</td>
        <td width="15%">'.$order_quantity.'</td>
        <td width="15%">'.$order_rate.'</td>
        <td width="15%">'.$order_total.'</td>
    </tr>
</table>    
';
$pdf->writeHTML($htmlcontent, true, false, false, false, '');
}
$htmlcontent =' 
<table class="table table-hover" border="1" cellpadding="8" cellspacing="0" style="margin-top:-20px !important;">   
    <tr>
        <td width="85%" style="text-align:right; font-weight:bold;">Sub Total</td>
        <td width="15%">'.$subTotal.'</td>
    </tr>
    <tr>
        <td width="85%" style="text-align:right; font-weight:bold;">Discount</td>
        <td width="15%">'.$discount.'</td>
    </tr>
    <tr>
        <td width="85%" style="text-align:right; font-weight:bold;">GST 18%</td>
        <td width="15%">'.$gstn.'</td>
    </tr>
    
    <tr>
        <td width="85%" style="text-align:right; font-weight:bold;">Total</td>
        <td width="15%">'.$grandTotal.'</td>
    </tr>
    
</table>
<br /><br />


</body>
</html>
<p style="border-top: 2px solid #eb8b8b;"></p>
';

$pdf->writeHTML($htmlcontent, true, false, false, false, '');

//------------------------------------------------------

    
    }
}   

writeHTML 的第二个参数控制是否应添加新行。将其设置为 false 应该可以解决问题:

$pdf->writeHTML($htmlcontent, false, false, false, false, '');
                              ^^^^^