FPDF标题图像未显示在页面上

时间:2016-11-21 13:25:31

标签: php fpdf

我正在尝试从FPDF.org复制演示(http://www.fpdf.org/en/tutorial/tuto2.htm)并复制了以下代码:

class PDF extends FPDF {
    function Header() {
        $this->Image('http://domain.co.uk/img/quote-header.png', 10, 6, 30);
        $this->SetFont('Arial', 'B', 15);
        $this->Cell(80);
        $this->Cell(30, 10, 'Title', 1, 0, 'C');
        $this->Ln(20);
    }
}

生成了一个很棒的PDF文件 - 但是Header图像没有显示?出了什么问题?

完整代码:

<?php
    $fullname = $_POST['fullname'];
    $jobtitle = $_POST['jobtitle'];
    $organisation = $_POST['organisation'];
    $department = $_POST['department'];
    $addressline1 = $_POST['addressline1'];
    $addressline2 = $_POST['addressline2'];
    $addressline3 = $_POST['addressline3'];
    $towncity = $_POST['towncity'];
    $county = $_POST['county'];
    $postcode = $_POST['postcode'];
    $email = $_POST['email'];
    $telephone = $_POST['telephone'];

    require('fpdf181/fpdf.php');

    class PDF extends FPDF {
        function Header() {
            $this->Image('http://domain.co.uk/img/quote-header.png', 10, 6, 30);
            $this->SetFont('Arial', 'B', 15);
            $this->Cell(80);
            $this->Cell(30, 10, 'Title', 1, 0, 'C');
            $this->Ln(20);
        }
    }

    $pdf = new FPDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Arial', '', 10);

    $pdf->Cell(40, 10, ''. $fullname .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $jobtitle .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $organisation .' ('. $department .')');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $addressline1 .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $addressline2 .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $addressline3 .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $towncity .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $county .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $postcode .'');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, ''. $email .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, ''. $telephone .'');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, ''. date("d-m-Y") .'');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, 'Quotation Ref; WQ'. rand() .'');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, 'Dear '. $fullname .',');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, 'As requested, please see your quotation below:');
    $pdf->Ln(8);

    for($i = 1; $i <= 5; $i++)
    $pdf->Cell(0, 10, 'Printing line number ' . $i, 0, 1);

    $pdf->Cell(40, 10, 'This quotation will be valid for the remainder of 2016 subject to our terms and conditions.');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, 'Pricing submitted is strictly confidential between Business Ltd. and '. $organisation .'.');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, 'Please do come back to us if you have any queries whatsoever relating to the above quotation or if you would like');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, 'to discuss further options.');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, 'We look forward to hearing from you in the near future.');
    $pdf->Ln(8);
    $pdf->Cell(40, 10, 'With best wishes,');
    $pdf->Ln(4);
    $pdf->Cell(40, 10, 'Business Ltd.');

    $pdf->Output();
    $content = $pdf->Output('('. date("m") .'-'. date("Y") .') WQ'. rand() .'.pdf', 'F');
?>

1 个答案:

答案 0 :(得分:2)

您正在定义FPDF的子类,名为PDF,但您没有使用它。将$pdf = new FPDF()更改为$pdf = new PDF()

相关问题