I'm having some difficulty caused by the error.
“Fatal error: Call to a member function on a non-object in report_functions.inc on line 6”
I’m creating a pdf report and building it using simple function statements. Here’s a simplified version of my code:
report.php **********
<?php
include 'pdfClass/class.pdf.php';
include 'report_functions.inc';
$pdf = new Cpdf();
include page1.inc';
$pdf->newPage();
include 'page2.inc';
$report = $pdf->output();
?>
report_functions.inc
<?php
function head($mainTitle,$page,$totalpages,$color,$fontcolor)
{
global $pdf;
$pdf->setColor($fontcolor['r']/100,$fontcolor['g']/100,$fontcolor['b']/100);
$pdf->addText(10,775,8,"<i>".$mainTitle."</i>");
$pdf->addText(540,775,8,"<i>Page ".$page." of ".$totalpages."</i>");
$pdf->setStrokeColor($color['r']/100,$color['g']/100,$color['b']/100);
$pdf->setLineStyle(3);
$pdf->line(0,765,612,765);
} // function header()
function foot($copyright,$color,$fontcolor)
{
global $pdf;
$pdf->setStrokeColor($color['r']/100,$color['g']/100,$color['b']/100);
$pdf->setLineStyle(3);
$pdf->line(0,25,612,25);
$pdf->setColor($fontcolor['r']/100,$fontcolor['g']/100,$fontcolor['b']/100);
$pdf->addText(10,10,8,"<i>".$copyright."</i>");
$pdf->setStrokeColor($color['r']/100,$color['g']/100,$color['b']/100);
} // function foot()
?>
page2.inc ********
<?php
/ VARIABLES ***/
$mainTitle = "The Report";
$color = array('r'=>155/2.55,'g'=>28/2.55,'b'=>82/2.55);
$fontcolor = array('r'=>21/2.55,'g'=>56/2.55,'b'=>127/2.55);
$page = 2;
$totalpages = 11;
// Header
head($mainTitle,$page,$totalpages,$color,$fontcolor);
The error points to the line (in the head function):
“$pdf->setColor($fontcolor['r']/100,$fontcolor['g']/100,$fontcolor['b']/100);”
My tests show that as soon as I call $pdf in any function I get the error. If I populate “page2.inc” with no functions (just the code) everything works wonderfully (but is rather messy).
Can anyone see what I’m doing wrong?
Any help would be appreciated.