导出pdf只有最后一行

时间:2014-02-27 06:27:47

标签: php html pdf-generation tcpdf

我正在尝试将html表导出为pdf,我能够成功生成pdf文件,但只有最后一行即将发布。我正在使用tcpdf来实现这一点 我使用以下代码:

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

结果如下:
enter image description here

如果我试图回应$tbl1我有两行

3 个答案:

答案 0 :(得分:1)

样式语法有错误,应该是:

<tr style="align: center;">

答案 1 :(得分:0)

<tr style="align="center">

应该是

<tr align="center">

答案 2 :(得分:0)

这对我有用:

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