【问题标题】:FPDF function controlFPDF功能控制
【发布时间】:2016-10-11 21:32:40
【问题描述】:

我是编程新手,我正在使用 FPDF(A PHP 类)创建一个 pdf。在我的代码底部,您会注意到我创建了一个新页面并调用了函数 Header()。由于某种原因,页眉也适用于第一页。如何只将页眉应用到第二页?

这里是 pdf 实时版本的链接:http://fosterinnovationculture.com/experiments/fpdf/index-two.php

<?php
require('fpdf.php');

// classes
class PDF extends FPDF
{
    function Logo(){
        $this->Image('images/logo.png',1,5.5,3);
    }
    //change name of function
    function HeaderOne($xCor, $yCor, $text) 
    {
        $this->SetX($xCor);
        $this->SetY($yCor);
        $this->SetFont('Arial','B',18);
        $this->Cell(5,1,$text);
    }        
    //Add bottom border
    function BorderLine() 
    {
        $this->SetDrawColor(0,0,0);
        $this->SetFillColor(0,0,0);
        $this->Rect(1, 10, 6.5, .015, 'F');        
    }
    function Footer()
    {
        // Go to 1.5 cm from bottom
        $this->SetY(-5.7);
        // Select Arial italic 8
        $this->SetFont('Arial','I',8);
        // Print centered page number
        $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'R');
    }
    function Header(){
        // Subtitle
        $this->SetY(.25);
        $this->SetX(1);
        $this->SetFont('Arial','',12);
        $this->Cell(6,1,'INNOVATION READINESS ASSESSMENT');
        // Line
        $this->SetDrawColor(0,0,0);
        $this->SetFillColor(0,0,0);
        $this->Rect(1, .5, 6.5, .015, 'F');       
    }
}

//pdf document preferences
$pdf = new PDF('p', 'in', 'Letter');
$pdf->AddPage();
$pdf->SetMargins(1,1,1,1);

//Page 1
$pdf->SetDrawColor(238,170,40);
$pdf->SetFillColor(238,170,40);
$pdf->Rect(1, 1, 6.5, .25, 'F');
$pdf->Image('images/header.jpg',1,1.5,6.5,3.5,'JPG','');
$pdf->Logo();
$pdf->HeaderOne(1,9,'Innovation Readiness Assessment');
$pdf->BorderLine();

//Page 2        
$pdf->AddPage();
$pdf->Header();

// Close and output file to the browser
$pdf->Output();

?>

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    请参阅Header() 的官方文档和 AddPage().

    AddPage() 函数已在内部调用 Header()。 此处无需显式调用Header()

    【讨论】:

    • 谢谢!老实说,我什至没有意识到 FPDF 已经有一个名为 header 的类。我虽然我正在创建一个新课程。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-02-04
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多