PHP/TCPDF:模板错误?

abe*_*bel 19 php tcpdf

我一直在使用TCPDF.它使用简单,输出低尺寸PDF并正在积极开发中.以下是一个页面的代码,该页面应该只有Hello World和页脚显示页码.但是我在页面顶部有一个额外的水平线.http://yfrog.com/2tapdfj这让我烦恼.我怎么摆脱它?

<?php
require_once('config/lang/eng.php');
require_once('tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);

// set default header data

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);//if i comment this out the lower line disappears

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
//$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();


// define some HTML content with style
$html = <<<EOF
Hello World
EOF;

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');

?>
Run Code Online (Sandbox Code Playgroud)

解:

$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
Run Code Online (Sandbox Code Playgroud)

更改或删除TCPDF中的页眉和页脚

小智 35

只要这样做$pdf->setPrintHeader(false); ,顶部的线就会消失

  • 值得注意的是`setPrintHeader(false)`命令必须在`AddPage()`命令之前,否则黑线将继续显示. (12认同)