?
Solved

Getting error calling function using FPDF to create PDF file with PHP

Posted on 2008-06-20
3
Medium Priority
?
1,945 Views
Last Modified: 2013-12-12
Hi all, I am trying to create a PDF file with FPDF and I get the following error when I call the function that is used to create the table in the file: Fatal error: Call to undefined function: fancytable(). I have a function called fancytable, and then a class called FPDF that calls it.


thanks,
bob
function FancyTable($header,$data) {
 
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
    //Header
    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',1);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=0;
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
        $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);
        $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);
        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');
}
 
 
$pdf=new FPDF();
//Column titles
$header=array('Day','Date','Job Code','Hours');
//Data loading
$data=$tarr;
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Weekly Timesheet');
$pdf->SetFont('Arial','',12);
$pdf->Cell(40,10, "Employee: " . $fname2 . " " . $lname2,1,0,'');
$pdf->Cell(40,10, "Week Ending: " . $wending,1,1,'');
$pdf->SetFont('Arial','',14);
$pdf->FancyTable($header,$data);
$pdf->Output();

Open in new window

0
Comment
Question by:ob1_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 1000 total points
ID: 21836645
Hi,

By having this function solely, it isn't added to the FPDF class. You can create a small class that extends FPDF class and add the function to it. Then instead of new FPDF use new FPDFExtended. I added an example to show you want I mean.

Kind regards

-r-

class FPDFExtended {
  function FancyTable($header,$data) {
 
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
    //Header
    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',1);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=0;
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
        $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);
        $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);
        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');
  }
}
 
 
$pdf=new FPDFExtended();
//Column titles
$header=array('Day','Date','Job Code','Hours');
//Data loading
$data=$tarr;
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Weekly Timesheet');
$pdf->SetFont('Arial','',12);
$pdf->Cell(40,10, "Employee: " . $fname2 . " " . $lname2,1,0,'');
$pdf->Cell(40,10, "Week Ending: " . $wending,1,1,'');
$pdf->SetFont('Arial','',14);
$pdf->FancyTable($header,$data);
$pdf->Output();

Open in new window

0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21836647
Line 1 should read:
class FPDFExtended extends FPDF {
0
 
LVL 6

Author Closing Comment

by:ob1_
ID: 31469387
thanks Roonaan!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question