Install FPDF on Laravel 4

2020-07-22 18:42发布

问题:

I didn't manage to install FPDF on laravel 4. Can you help me? Can you explain how to do it step by step?

I add on composer.json

"require": {
         "illuminate/support": "4.0.x"
    },
"require-dev": {
        "anouar/fpdf": "dev-master"
    },

after this, on shell, I use composer update. And now?

回答1:

To your composer.json file, add:

"require-dev": {
    "anouar/fpdf": "dev-master"
}

Then update your Laravel project,

composer update

If not already installed laravel framework use,

composer install

Then go to app/config/app.php and to the providers array add,

'Anouar\Fpdf\FpdfServiceProvider',

Now it's look like,

'providers' => array(
    // ...

    'Anouar\Fpdf\FpdfServiceProvider',
)

Finally, add the alias to app/config/app.php, within the aliases array.

'aliases' => array(
    // ...

    'Fpdf'    => 'Anouar\Fpdf\Facades\Fpdf',
)

Now you can use Fpdf anywhere like,

In app/routes.php

Route::get('pdf', function(){

        Fpdf::AddPage();
        Fpdf::SetFont('Arial','B',16);
        Fpdf::Cell(40,10,'Hello World!');
        Fpdf::Output();
        exit;

});

Then test it with your url like,

http://localhost/laravel/pdf

You can see the Packagist https://packagist.org/packages/anouar/fpdf

And the GitHub Repo here https://github.com/xroot/laravel-fpdf



回答2:

the fpdf is external component and you must create a workbench to integrating this to laravel. this is smiliar [tutorial]http://jasonlewis.me/article/laravel-4-develop-packages-using-the-workbench

or you can use other component. [dompdf]http://packalyst.com/packages/package/barryvdh/laravel-dompdf