Home > database >  FPDF with Laravel
FPDF with Laravel

Time:11-10

I am attempting to use the FPDF (http://www.fpdf.org/) PHP addon for my website that uses Laravel. I want to be able to dynamically create a PDF.

I have stored the libraries' files in the folder: '/public/vendor'. This is what I have so far:

require $_SERVER['DOCUMENT_ROOT'] . '/vendor/fpdf/fpdf.php';

which works fine. However when I try to use the FPDF class using:

  $pdf = new FPDF('P', 'pt', array(500,233));

I get the error: Class "'App\Console\Commands\FPDF' not found"

How can I fix this to use the library. I do not have access to command line so I have to manually import any folders or files.

Any help is greatly appreciated.

CodePudding user response:

Ideally if using Laravel, you should load it via composer the get it to work correctly.

If you do not have access to composer on the server, you could download the project, make sure you are running the same version of PHP as the server and run composer install fpdf/fpdf. Re-upload the composer.json, composer.lock and vendor folder.

https://packagist.org/packages/fpdf/fpdf

CodePudding user response:

Try following code:

 $pdf = new \Fpdf\Fpdf('P', 'pt', array(500,233));

FPDF is in the root namespace and you are within another namespace.

  • Related