dongliangkeng1056 2011-02-10 22:44
浏览 90
已采纳

TCPDF - 页脚的奇怪问题

Check out the source code here:

http://www.savvissl.com/demo1/showcode.php

check out the script here

http://www.savvissl.com/demo1/testPDF.php

Here is the issue... the footer prints fine on every page except for the last page. The last page never has a footer. If there is only one page in the document the footer will not print at all.

  • 写回答

2条回答 默认 最新

  • dongxing8766 2011-02-11 15:33
    关注

    OK I couldn't figure it out, but i was able to copy a co-workers example that worked. If anyone wants the source code here it is:

    <?php
    
    require_once('tcpdf/config/lang/eng.php');
    require_once('tcpdf/tcpdf.php');
    
    
    define('PDF_FOOTER_TEXT','800 Vinial St. Pittsburgh, PA 15212 | phone: 412.321.7006 | fax: 412.321.7005 | www.savvior.com');
    $PDF_LINE_COLOR=array(255,255,0);
    define('PDF_FOOTER_TEXT_COLOR',170);
    
    
    class MYPDF extends TCPDF
    {
        //Page header
        public function Header()
        {
            global $PDF_LINE_COLOR;
            $image_file = K_PATH_IMAGES.'image.jpg';
            $this->Image($image_file, 160, 0, 30, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
            $this->SetFont('helvetica', 'B', 20);
            $this->Cell(0, 15, '', 0, false, 'C', 0, '', 0, false, 'M', 'M');
            $this->line(10,27,200,27,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'solid' => 4, 'color' => $PDF_LINE_COLOR));
        }
        public function Footer()
        {
            global $PDF_LINE_COLOR;
            $cur_y = $this->GetY();
            $ormargins = $this->getOriginalMargins();
            $this->SetTextColor(PDF_FOOTER_TEXT_COLOR, PDF_FOOTER_TEXT_COLOR, PDF_FOOTER_TEXT_COLOR);
            $this->SetY($cur_y);
            $this->line(10,400,200,400,array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'solid' => 4, 'color' => $PDF_LINE_COLOR));
            $this->Cell(0,11,"Page ". $this->getAliasNumPage().'/'.$this->getAliasNbPages(),'T',0,'L');
            $this->Cell(0,11,PDF_FOOTER_TEXT,'T',0,'R');
        }
    
    }
    
    ob_start();
        ?><h1>Content Is Needed For This Page...</h1>
        ...
        <?
    
        $html=ob_get_clean();
    
    function makePDFFile($fileName,$html)
    {
        $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        // set document information
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Savvior Project Manager');
        $pdf->SetTitle('Auto Generated PDF');
        $pdf->SetSubject('Auto Generated PDF');
        $pdf->SetKeywords('TCPDF');
        // set default header data
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
        // 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+5, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        //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', '', 12);
        // add a page
        $pdf->AddPage();
        $pdf->writeHTML($html, true, false, true, false, '');
        $doc=$pdf->Output(dirname(__FILE__)."/cache/{$fileName}", 'F');
        return $fileName;
    }
    
    $file=makePDFFile('poo-poo-platter.pdf',$html);
    
    header("location: cache/{$file}");
    ?>
    

    Comparing this new code to my old reveals no insight into why this works... in fact the example in the TCPDF examples folder exhibits the same issue, however if you run it from their website the footer is displayed correctly. Well anyway hope this helps someone

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路