1

I am trying to test implementation of FPDF. Below is the code I'm testing with, but it keeps giving me the error: "Fatal error: Class 'FPDF' not found in /home4/fwall/public_html/create-press-release.php on line 5". That is the URL to the page I am calling the below code on.

I have verified that the php file for FPDF is being required from the right spot, and it's still happening. Can anyone figure out what's going on?

require(__DIR__.'/fpdf.php'); //The fpdf folder is in my root directory.

//create a FPDF object
$pdf=new FPDF();

//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');

//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');

//insert an image and make it a link
//$pdf->Image('logo.png',10,20,33,0,' ','http://www.fpdf.org/');

//display the title with a border around it
$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Congratulations! You have generated a PDF.');

//Output the document
$pdf->Output('example1.pdf','I'); 
Eckstein
  • 785
  • 9
  • 27

1 Answers1

1

This line:

require('http://siteurlredacted.com/fpdf/fpdf.php');

probably won't do what you expect. The request will make the remote server "execute" fpdf.php, returning a blank page, and your script will include an empty file. That is why it doesn't find any class to load.

You should download FPDF and put the file on your filesystem, where it is accesible to your script with no HTTP requests. You can try putting fpdf.php inside your project.

Hope this helps.

Mariano D'Ascanio
  • 1,202
  • 2
  • 16
  • 17
  • Thank you. I assume you mean just call it as a relative file instead? I've tried that as well with no luck. I've updated the question with what I have now. – Eckstein Jul 09 '14 at 04:00
  • @Eckstein I tried your code, after downloading fpdf under a directory inside the project. Got it working just by changing the absolute path on the require to `require('./fpdf/fpdf.php')` – Mariano D'Ascanio Jul 09 '14 at 04:55
  • Never mind, you were right. I was not requiring the relative path correctly. Once I figured it out, it worked. Working solution above. – Eckstein Jul 09 '14 at 04:57
  • Great! Good luck with your project. – Mariano D'Ascanio Jul 09 '14 at 05:00