Baptiste Arnaud Baptiste Arnaud - 8 months ago 118
PHP Question

Clean FPDF & FPDI Installation on a laravel project

I tried several things to install FPDF and FPDI on my laravel project but it just doesn't work and it's never clear.

Can you guys explain to me how i can do so ?

Answer Source

Have you tried the codedge/laravel-fpdf package?

Install it through Composer:

composer require codedge/laravel-fpdf

Publish the config file and edit it as needed:

php artisan vendor:publish --provider="Codedge\Fpdf\FpdfServiceProvider" --tag=config

Add package's service provider and alias to your config/app.php file:

return [

    'providers' => [
        // ...

    // ...

    'aliases' => [
         // ...
        'Fpdf' => Codedge\Fpdf\Facades\Fpdf::class,

Test it:

Route::get('/', function () {
    Fpdf::SetFont('Courier', 'B', 18);
    Fpdf::Cell(50, 25, 'Hello World!');

Hit your app root in browser and see if it generates a PDF file as expected.