Srikanta
Srikanta

Reputation: 111

Only last row is coming with export pdf

I am trying to export a html table to pdf, I am able to generate the pdf file successfuly but only the last row is coming. I am using tcpdf to implement this.
I am using the following code:

$tbl1='<table cellpadding="3" cellspacing="1" width="100%" style="text-align:center;" border="1">
<tr style="font-weight:500;">
<td height="35">Deal Id</td>
<td>Deal Title</td>
<td>Deal Offer Id </td>
<td>No. Of Purchases</td>
<td>Quantity</td>
<td>Total Price</td>
<td>Date</td>
</tr>';
$tbl1.='<tr style="align="center">
    <td>sss</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    </tr><tr style="align="center">
    <td>2</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>1</td>
    </tr>';
$tbl1.='</table>';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->AddPage();
    $pdf->writeHTML($tbl1, true, 0, true, 0);
    $pdf->Output('Deal-wise-report.pdf', 'D');

Here is the result:
enter image description here

If I try to echo the $tbl1 I am getting two rows

Upvotes: 0

Views: 140

Answers (3)

hopsoo
hopsoo

Reputation: 305

This works for me:

   $tbl1='<table cellpadding="3" cellspacing="1" width="100%" style="text-align:center;" border="1">
<tr style="font-weight:500;">
<td>Deal Id</td>
<td>Deal Title</td>
<td>Deal Offer Id </td>
<td>No. Of Purchases</td>
<td>Quantity</td>
<td>Total Price</td>
<td>Date</td>
</tr>';
$tbl1.='<tr>
    <td>sss</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    </tr><tr>
    <td>2</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>12</td>
    <td>1</td>
    </tr>';
$tbl1.='</table>';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->AddPage();
    $pdf->writeHTML($tbl1, true, 0, true, 0);
    $pdf->Output('Deal-wise-report.pdf', 'D');

Upvotes: 0

Rohit Awasthi
Rohit Awasthi

Reputation: 686

<tr style="align="center">

Should be

<tr align="center">

Upvotes: 0

hopsoo
hopsoo

Reputation: 305

You have an error in style syntax, should be:

<tr style="align: center;">

Upvotes: 1

Related Questions