[英]Unwanted lines in TCPDF class with custom header and footer
我正在使用TCPDF生成pdf报告。 我需要自定义的页眉和页脚,因此我扩展了原始类,以按照官方文档( https://tcpdf.org/examples/example_002.phps )中的建议覆盖Header和Footer方法。
这是代码:
class AppPdf extends \TCPDF {
CONST LOGO_PATH = '/../../../public_html/public/images/logo-big.png';
private $xLogo;
private $yLogo;
private $wLogo;
public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false, $xLogo = 8, $yLogo = 0, $wLogo = 50) {
parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);
$this->xLogo = $xLogo;
$this->yLogo = $yLogo;
$this->wLogo = $wLogo;
}
public function Header() {
$this->Image(__DIR__ . self::LOGO_PATH, $this->xLogo, $this->yLogo, $this->wLogo);
}
public function Footer() {
$this->SetXY(34,260);
$this->SetFont('Helvetica', 'I', 8);
$this->SetTextColor(0, 0, 0);
$this->MultiCell(130, 20, "footer text", 0, "C", false);
}
}
然后,我有一个用于所有生成的文档的基本模板:
class BasePdf {
CONST CREATOR = 'Creator';
CONST TITLE = 'Title';
CONST PDF_FONT_NAME_MAIN = 'Times';
CONST PDF_FONT_SIZE_MAIN = 11;
protected $pdf;
public function __construct($xLogo = 8, $yLogo = 0, $wLogo = 50)
{
$this->pdf = new AppPdf('P', 'mm', 'A4', true, 'UTF-8', false, false, $xLogo, $yLogo, $wLogo);
$this->pdf->SetCreator(self::CREATOR);
$this->pdf->SetAuthor(self::CREATOR);
$this->pdf->SetTitle(self::TITLE);
$this->pdf->SetFont(self::PDF_FONT_NAME_MAIN, "", self::PDF_FONT_SIZE_MAIN);
}
public function getPdf()
{
return $this->pdf;
}
}
基本模板的用法如下类所示:
use AppBundle\Entity\HPVExam;
class HPVReport extends BasePdf
{
public function __construct(HPVExam $HPVExam)
{
parent::__construct(8, 10, 75);
$this->pdf->AddPage();
}
}
问题在于,此代码生成的pdf的顶部带有一条烦人的水平线,而另一段位于页脚中,如下图所示 。
我已经尝试过此处提供的建议PHP / TCPDF:模板错误? 在这里更改或消除TCPDF中的页眉和页脚,但是没有运气。
我做错了什么? 似乎原始的Header和Footer方法没有正确覆盖...知道吗? 谢谢!
只需对不打印标题的TCPDF说或去修改源代码即可。...
$pdf->SetPrintHeader(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.