从动态php文件生成PDF

bwntbbo3  于 12个月前  发布在  PHP
关注(0)|答案(2)|浏览(102)

我有一个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');
?>
o0lyfsai

o0lyfsai1#

`<?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 = "";
$sql = "SELECT * FROM TABLE_NAME";
while()
{
    $html .= "need to puplate this dynamic";
}
$html = $html;
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('example_021.pdf', 'I');
?>`

设置html变量conceit到你现有的循环。请找到上面的示例代码。

kt06eoxx

kt06eoxx2#

解决方案是用内容填充每个变量,然后在$pdf中连接它们。

相关问题