Install FPDF on Laravel 4

旧城冷巷雨未停 提交于 2019-12-06 07:31:46

问题


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



来源:https://stackoverflow.com/questions/19319198/install-fpdf-on-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!