Welcome! Log In Create A New Profile

Advanced

[PHP] FPDF passing values into header and footer?

Posted by Angus Mann 
Angus Mann
[PHP] FPDF passing values into header and footer?
April 26, 2010 06:50AM
Hi all. Whilst this question relates to fpdf (www.fpdf.org) I think it really is a PHP question, because it involves passing values into classes and functions.

Here's the problem .. I need to pass a PHP variable like $number into the header of a PDF.
I have extended the FPDF class as follows....

class PDF extends FPDF{
function Header(){
$this->SetFont('Arial','BU',12);
$this->Cell(0,5,'User notes for invoice number '.$number,0,'1','L');
}
}

The problem is, I can't figure out how to pass a value from the rest of the PHP script so it can be seen within the function above.

I'm sure the problem is one of the scope of the variable but this sort of thing is new to me and I can't figure out the syntax to make it work.

Before anybody suggests something like ...
function Header($number){}
Please recognize that the Header function is called automatically by FPDF and not by my code, so unless I totally hack the FPDF class I can't do this easily.

Any suggestions please?
Angus Mann
Re: [PHP] FPDF passing values into header and footer?
April 26, 2010 08:30AM
----- Original Message -----
From: "Angus Mann" <[email protected]>
To: "php-general" <[email protected]>
Sent: Monday, April 26, 2010 2:46 PM
Subject: [PHP] FPDF passing values into header and footer?


Hi all. Whilst this question relates to fpdf (www.fpdf.org) I think it
really is a PHP question, because it involves passing values into classes
and functions.

Here's the problem .. I need to pass a PHP variable like $number into the
header of a PDF.
I have extended the FPDF class as follows....

class PDF extends FPDF{
function Header(){
$this->SetFont('Arial','BU',12);
$this->Cell(0,5,'User notes for invoice number '.$number,0,'1','L');
}
}


I hate it when I ask a question prematurely, because I could have figured it
out myself. Getter and Setter functions are the answer.

function setNumber($number){
$this->number = $number;
}

$pdf->setNumber('12345');




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FPDF passing values into header and footer?
May 10, 2013 07:07AM
I am trying to do something similar but I cannot get it to work.

Can you explain where exactly you placed this code:

function setNumber($number){
$this->number = $number;
}

$pdf->setNumber('12345');

in relation to this code?

class PDF extends FPDF{
function Header(){


Thanks.
Sorry, only registered users may post in this forum.

Click here to login