我有一个php页面,它动态填充了数据,现在当我按下下载按钮时,我希望能够下载带有特定数据的页面,作为PDF。
我找到了一个名为tcpdf的库,它可以为我工作,但我不知道如何用我的动态代码填充$html
变量,因为该变量附带了一个字符串。我附上了下面的代码:
<?php
require_once('tcpdf/tcpdf.php');
$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);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();
$html = "need to puplate this dynamic";
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('example_021.pdf', 'I');
?>
2条答案
按热度按时间o0lyfsai1#
设置html变量conceit到你现有的循环。请找到上面的示例代码。
kt06eoxx2#
解决方案是用内容填充每个变量,然后在
$pdf
中连接它们。