php - FPDF with Laravel
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.
Update:: I do not have any access to the console so i cannot use composer. Any way to still do this?
Answer
Solution:
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
Answer
Solution:
Try following code:
$pdf = new \Fpdf\Fpdf('P', 'pt', array(500,233));
FPDF is in the root namespace and you are within another namespace.
Answer
Solution:
Highly recommend using https://github.com/mccarlosen/laravel-mpdf which can be installed via composer
It supports blade views and you can pass variables to it just like in view()
Source