Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with object

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
I am hoping someone could point me in the right direction

using FPDF sucessfully but I want a subroutine to write header information.

Code:
// start the adobe page
require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();

// this line does not work
$pdf->invoiceheader($pdf,$name,$address, $date, $invno);

$pdf->Output();

invoiceheader is within a file called functions.php
and the line include_once ('functions.php') is higher up the code and other functions work OK

This is the function invoiceheader

Code:
function invoiceheader($pdf,$name,$address, $date, $invno)
	{
		$pdf->SetFont('Arial','BU',14);


		$pdf->Image('images/letterhead.jpg',1,1,210);
	
	
		// Dummy invoice Header
		$pdf->setXY(13,30);
		$pdf->Cell(40,10,'Dummy Invoice');

		$pdf->SetFont('Arial','B',10);
	
		// name&address
		$pdf->setXY(13,40);
		$pdf->Cell(40,10,$name);
		$pdf->setXY(13,47);
		$pdf->MultiCell(60,4.5,$address);

		// date

		$pdf->setxy(160,78);
		$pdf->Cell(40,10,'Date');

		$pdf->setXY(170,78);
		$pdf->Cell(40,10,$date);

		// invoice no
		$pdf->setXY(160,72);
		$pdf->Cell(40,10,'Invoice No');
		$pdf->setXY(180,72);
		$pdf->Cell(40,10,$invno);
	
		$x = 13;
		$y = 140;
		// job data on the 
	
		$pdf->SetFont('Arial','BU',10);

		//Header
		$pdf->setXY($x,$y - 10);
		$pdf->Write(10,'Job Date');

		//jobno
		$pdf->setXY($x + 29,$y - 10);
		$pdf->Write(10,'Job No');

		// description
		$pdf->setXY($x + 55,$y -10 );
		$pdf->Write(10,'Description');

		// value

		$pdf->setXY($x + 153,$y - 10);
		$pdf->cell(20,10,'Value',0,1,'R');
		$pdf->SetFont('Arial','B',10);
		
		return($pdf);
	}
 
The function invoiceheader() is not part of the FPDF class so you should not have '$pdf->' before the call. Just call the function...

Also you may want to add references to your function declaration. In PHP4 the function should look like this:
Code:
//notice the ampersands in front of the function name and $pdf argument 
function [COLOR=red]&[/color]invoiceheader([COLOR=red]&[/color]$pdf,$name,$address, $date, $invno)
{
    ....
}
You will want to read up on references for the PHP version you are using.
 
It works -- brilliant

why does this bit still work when all the work has been done in a child procedure

$pdf->Output();

something I have found difficult in PHP is the passing of varaiables from one procedure to another.


Richard
 
There is a whole lot of technical 'stuff' that goes along with it, but in general...

Normally when you pass a variable to a function, the function works on a copy of the variable, not the variable itself. But when you pass a variable by reference, PHP does not create a copy of the variable it works with the actual variable.

Check out the references section in the manual, that will give you the real nuts and bolts of it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top