繁体   English   中英

FPDI / TCPDF中的页眉和页脚行

[英]header and footer line in FPDI/TCPDF

我正在使用FPDI和TCPDF函数标记PDF文档,并且试图弄清楚如何在页眉中的文本下方和页脚中的文本上添加一行。 这是我的代码:

<?php

require_once('lib/tcpdf/tcpdf.php');
require_once('fpdi.php');


$fullPathToFile = "TestClanek6.pdf";  

class PDF extends FPDI {

    var $_tplIdx;

    function Header() {

        global $fullPathToFile;  //global 
        if(is_null($this->_tplIdx)) {
            // number of pages
            $this->numPages = $this->setSourceFile($fullPathToFile);
            $this->_tplIdx = $this->importPage(1);
        } 
        if($this->page > 0) {
            //$this->SetPrintHeader(true);
            $this->SetFont('times', 'I', 11); 
            $this->SetTextColor(0);
            $this->Write(15, "Vol. 1, No. 15, Year: 2015, duff");
            $this->Image('logo.png', 100, 2, 75,7);            
        } //end of IF
        $this->useTemplate($this->_tplIdx, 0, 0,200);
    }           //end of HEADER

    function Footer() {
        if($this->page > 0) {
            $this->SetY(-20);
            $this->SetFont('times', 'I', 11); 
            $this->SetTextColor(0,0,0);
            $this->Write(0, "Page", '', 0, 'C');
        }  //end of if
    } // end of footer
}        //end of CLASS

// new PDF file
$pdf = new PDF();
$pdf->addPage(); 
if($pdf->numPages>0) {
    for($i=1;$i<=$pdf->numPages;$i++) {
        $pdf->endPage();
        $pdf->_tplIdx = $pdf->importPage($i);
        $pdf->AddPage();
        //$pdf->SetPrintHeader(false);
        //$pdf->SetPrintFooter(false); 
    }
}
$file_time = time();

$pdf->Output("$file_time.pdf", "F");//, "I"); 
echo "Link: '<a href=$file_time.pdf>Stamped article</a>'"; 
?>

我已经尝试了很多诸如setPrintHeader()之类的方法,但是没有发现对我有用。 我可以请人帮忙吗?

谢谢。

达芙

您可以使用Line方法在FPDF中绘制一条线。 如果要水平直线,只需确保直线起点和终点的坐标(y值)相同即可。 例如:

$pdf->Ln(15,$pdf->y,200,$pdf->y);

您将修改这些值以适合您的需要,并将其插入到适用于您的应用程序的HeaderFooter的重写方法中。

最好将两个方法( HeaderFooter )留空。 这样,您将覆盖超类的图形。

像这样:

class EmptyFPDI extends FPDI
{
    public function Header()
    {
    }

    public function Footer()
    {
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM