【发布时间】:2011-03-26 06:31:15
【问题描述】:
我使用 TCPDF 已经有一段时间了。它使用简单,可输出小尺寸 PDF,并且正在积极开发中。 下面是一个页面的代码,它应该只有 Hello World 和一个显示页码的页脚。但是我在页面顶部得到了一条额外的水平线。这让我很烦。我该如何摆脱它?
<?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');
?>
解决方案:
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
【问题讨论】:
-
这并不完全是一个答案,但我已经浪费了很多时间来解决类似的问题。我只知道要告诉你的是阅读文档。我还通过阅读 TCPDF 源代码找出了我的大部分问题。和往常一样,不要放弃!
-
谢谢。但来源很长。我正在学习适应这条线。
-
而且你需要在 addPage 命令之前添加这些行,这让我卡住了..