S M Jadhav
S M Jadhav

Reputation: 43

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

Output of the PDF file

I am generating PDF file using TCTDF. I am fetching data from table in TCPDF. I want to connect the table in flow but I am getting the output like attached image. I am trying but its not working. When I start $htmlcontent without closing the table tag for 2nd code it also showing error. Even CSS is not working for margin between two 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> [email protected]<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, '');

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

    
    }
}   

Upvotes: 1

Views: 1305

Answers (1)

Philip Weinke
Philip Weinke

Reputation: 1844

The second parameter to writeHTML controls whether a new line should be added. Setting it to false should do the trick:

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

Upvotes: 1

Related Questions