我使用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);
发布于 2011-11-26 05:49:21
只需执行此操作$pdf->setPrintHeader(false);
,顶部的行就会消失
发布于 2010-08-06 20:07:32
水平线在默认标题()上定义。您可以像示例n. 3那样覆盖Header()方法,也可以像示例n. 2那样禁用头部。2.查看TCPDF网站http://www.tcpdf.org并咨询官方论坛以获取更多信息。
发布于 2012-11-02 00:35:43
如果这里的其他任何人都不能解决这个问题,而他们正在使用FPDI导入模板,请尝试查看从FPDI计算的页面高度和从TCPDF得到的页面高度。对于我来说,它们不匹配,为了去掉黑线,我必须在页面高度上加上8,并在setPrintHeader(false)的基础上从useTemplate函数的y纵坐标中减去7,如下所示:
$tplidx = $pdf->ImportPage($i);
$s = $pdf->getTemplateSize($tplidx);
// TCPDF STUFF, AddPage(), etc.
$pdf->useTemplate($tplidx,0,-7,$s['w'],$s['h']+8);
https://stackoverflow.com/questions/3422876
复制相似问题