如何使用tcpdf下载html表格


how to download html table using tcpdf

我有一个页面,需要使用tcpdf下载。下面是我写的代码,但它只显示了一个零。

这是我写的代码:

<?php
require_once('tcpdf.php');

include('simple_html_dom.php');
$filename = '10r6.php';
$ptemplate = file_get_contents($filename);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('AD');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}
$pdf->SetFont('times', 'BI', 20);
$pdf->AddPage();
$html = <<<EOD
$ptemplate
EOD;
$pdf->writeHTML(0, 0, '', '', $html, 0, 1, 0, true, '', true);
$pdf->Output('example_002.pdf', 'I');
?>

有人能帮我吗。

使用此命令将html代码输出到pdf文件。

$pdf->writeHTML($html, true, 0, true, true, '');

我注意到您使用了类似的内容,但似乎没有为$html变量分配任何内容。您需要将整个html代码放入该变量中,以便将其输出到pdf文件中。因此,如果(我假设)您的html代码是"simple_html_dom.php"(您将其包含在代码顶部),只需执行以下操作:

$html = include('simple_html_dom.php');
$pdf->writeHTML($html, true, 0, true, true, '');

我希望它能有所帮助,事实上,我昨天在TCPDF上也很艰难,但一整天之后,我设法把一切都做好了。

您的参数不正确。

$pdf->writeHTML($html, 0, '', '', false, 0, 1, 0, true, '', true);

从文档中,参数为;

TCPDF::writeHTML(
    $html,
    $ln = true,
    $fill = false,
    $reseth = false,
    $cell = false,
    $align = '' 
)