简体   繁体   English

在创建 PDF 文件时,行之间的表 alignment 在 TCPDF 中不起作用

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

Output of the PDF file PDF 文件的 Output

I am generating PDF file using TCTDF.我正在使用 TCTDF 生成 PDF 文件。 I am fetching data from table in TCPDF.我正在从 TCPDF 中的表中获取数据。 I want to connect the table in flow but I am getting the output like attached image.我想在流程中连接表,但我得到了 output ,如附图。 I am trying but its not working.我正在尝试,但它不起作用。 When I start $htmlcontent without closing the table tag for 2nd code it also showing error.当我在没有关闭第二个代码的表格标记的情况下启动$htmlcontent时,它也会显示错误。 Even CSS is not working for margin between two tables甚至 CSS 也不能用于两个表之间的边距

 $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, '');

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

    
    }
}   

The second parameter to writeHTML controls whether a new line should be added. writeHTML的第二个参数控制是否应添加新行。 Setting it to false should do the trick:将其设置为 false 应该可以解决问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM