【发布时间】:2014-10-22 11:43:51
【问题描述】:
我正在使用自定义页脚并已使用 setY(); 设置其位置。然而,内容在我的页脚后面,这意味着我需要让我的分页符更高。当我有超过一页时,这导致我的页脚大小混乱。
我的页脚由内部带有图像的表格组成。出了问题的是,图像通过某种缩放变得奇怪的大小!我的 setAutoPageBreak() 越大,页脚就越乱。
我已经玩了好几个小时了。我希望有人可以帮助我解决这个问题。
我的页脚:
public function Footer() {
$footer = '<table>
<tr>
<td width="30" height="50"></td>
<td style="width: 570px; height: 55px;">
<img src="some_image" width="30" height="50" />
</td>
</tr>
</table>
';
$this->SetY(-60);
$this->writeHTML($footer, true, true, true, false, '');
}
TCPPDF 处理:
$pdf = new MyPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
set margins
$PDF_MARGIN_LEFT = 20;
$PDF_MARGIN_TOP = 40;
$PDF_MARGIN_RIGHT = 20;
$pdf->SetMargins($PDF_MARGIN_LEFT, $PDF_MARGIN_TOP, $PDF_MARGIN_RIGHT);
//LTRB
$PDF_MARGIN_HEADER = 5;
$PDF_MARGIN_FOOTER = 60;
$pdf->SetHeaderMargin($PDF_MARGIN_HEADER);
$pdf->SetFooterMargin($PDF_MARGIN_FOOTER);
// set auto page breaks, it also specifies margin-bottom. This scales the footer somehow...
$PDF_MARGIN_BOTTOM = 20;
$pdf->SetAutoPageBreak(true, $PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->AddPage();
// output the HTML content
$pdf->writeHTML($my_printed_html, true, false, true, false, '');
$pdf->Output('Test.pdf', 'I');
已编辑:
我注意到只有当我的页脚低于分页边距时才会出现问题。如果页脚在其上方,则图像正常,但内容从后面通过页脚。 有没有办法绕过这个?
【问题讨论】:
-
除了您的问题之外,我建议不要使用
px作为 PDF 文档中的单位。使用mm、cm或pt(取决于文档类型和您更熟悉的内容)。 -
啊,是的。我忘记了这一切。谢谢你提到这一点。
标签: php html html-table tcpdf image-scaling