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条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等