Baptiste Arnaud
Baptiste Arnaud

Reputation: 2760

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 ?

Upvotes: 1

Views: 2425

Answers (1)

sepehr
sepehr

Reputation: 18495

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' => [
        // ...
        Codedge\Fpdf\FpdfServiceProvider::class,
    ],

    // ...

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

Test it:

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

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

Upvotes: 2

Related Questions