簡體   English   中英

帶有頂部和底部邊框的自定義PHP tcpdf頁腳

[英]custom PHP tcpdf footer with top and bottom border

第一次使用TCPDF,很棒的庫。

我嘗試創建一個自定義頁腳,但是我想創建一個自定義頁腳,其中包括帶有頂部和底部邊框的div中的頁碼和日期! 有什么幫助嗎?

非常感謝

卡雷爾是對的。

但是,如果它給您帶來動態方面的麻煩,則可以忽略Footer()函數。 在我看來,您想在頁腳中添加一個div。

為此,您必須先擺脫默認頁腳:

$this->setPrintFooter(false);

然后創建自己的頁腳功能。

public function _footer($input) {
    $html = $input;

    $this->setY(-15); // so the footer is an actual footer.

    $this->writeHTMLCell(
        $width = 0, // width of the cell, not the input
        $height = 0, // height of the cell..
        $x,
        $y,
        $html = '', // your input.
        $border = 0,
        $ln = 0,
        $fill = false,
        $reseth = true,
        $align = '',
        $autopadding = true 
    );
}

上面函數的值是默認值。 因此您可能需要對其進行編輯。

像這樣的電話:

$div = '<div id="footer">wow this is a nice footer</div>'>
$pdf->_footer($div);

您可以使用$ div輸入創建HTML單元格。

要獲取頁碼和類似內容,只需簽出TCPDF文檔頁面即可: http ://www.tcpdf.org/doc/code/classTCPDF.html

希望這對理解它有所幫助。 這僅僅是一個例子。 您可以根據需要對其進行編輯,然后嘗試一些方法來使PDF文檔正常運行。

您可以擴展TCPDF類並添加自定義Footer函數。 這是我使用的示例,請查看它是否適合並根據您的需要進行修改。 它不使用<div>來顯示頁腳,這在我寫這篇文章時是不可能的(盡管現在,TCPDF正在迅速發展)。

class MyPDF extends TCPDF {
    public function Footer() {
        $this->SetY(-15);
        $this->SetFont('helvetica', 'I', 8);
        $this->Cell(0, 10,
                    'Page ' . $this->getAliasNumPage() . ' of total ' .
                    $this->getAliasNbPages(), 0, false, 'C', 0, '',
                    0, false, 'T', 'M');
    }
    public function Header() {
        // add custom header stuff here
    }
}

$pdf = new MyPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
                 true, 'UTF-8', false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM