我在PHP中使用 HTML to PDF方法来处理PDF格式。我成功地从数据库中检索了数据。我在行之间得到更多空格为什么? 请建议我。 这是我的代码......
require('WriteHTML.php');
include('connection.php');
$result = pg_query($db,"SELECT dvn_cd, allotment_date,allotment_no,quantity FROM ddhs_receipt_entry ");
$pdf=new PDF_HTML();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(true, 15);
$pdf->AddPage();
$pdf->Image('logo.png',18,13,33);
$pdf->SetFont('Arial','B',14);
$pdf->WriteHTML('<para><h1>Title</h1><br>');
$pdf->SetFont('Arial','B',7);
$htmlTable='<TABLE>
<TR>
<TD>Name</TD>
<TD>Email</TD>
<TD>URl</TD>
<TD>Comment</TD>
</TR>
</TABLE>';
$pdf->WriteHTML2("$htmlTable");
while($value = pg_fetch_array($result)) {
$htmlTable2='<TABLE>
<TR>
<TD>'.$value['dvn_cd'].'</TD>
<TD>'.$value['allotment_date'].'</TD>
<TD>'.$value['allotment_no'].'</TD>
<TD>'.$value['quantity'].'</TD>
</TR>
</TABLE>';
$pdf->WriteHTML2("$htmlTable2");
$pdf->SetFont('Arial','B',6);
}
$pdf->Output();
答案 0 :(得分:0)
您正在做的事实上是输出大量单独的表,而您只需要一个表。尝试在<TABLE>
循环之外移动while
:
$htmlTable = '<TABLE>
<TR>
<TD>Name</TD>
<TD>Email</TD>
<TD>URl</TD>
<TD>Comment</TD>
</TR>'; // The table is opened at the start of this block, and headers are output
while($value = pg_fetch_array($result)) {
$htmlTable .= '<TR>
<TD>'.$value['dvn_cd'].'</TD>
<TD>'.$value['allotment_date'].'</TD>
<TD>'.$value['allotment_no'].'</TD>
<TD>'.$value['quantity'].'</TD>
</TR>'; // Each row of your table is added to the string here
}
$htmlTable .= '</TABLE>'; // The table is closed here
$pdf->WriteHTML2("$htmlTable"); // The table is written here
$pdf->Output();
答案 1 :(得分:0)
试试这个:
while($value = pg_fetch_array($result)) {
$htmlTable2='<TR>
<TD>'.$value['dvn_cd'].'</TD>
<TD>'.$value['allotment_date'].'</TD>
<TD>'.$value['allotment_no'].'</TD>
<TD>'.$value['quantity'].'</TD>
</TR>';
$pdf->WriteHTML2("$htmlTable2");
$pdf->SetFont('Arial','B',6);
}
$htmlTable='</TABLE>';