Coder Social home page Coder Social logo

laravel-fpdf's Introduction

Laravel package for Fpdf

Latest Stable Version Total Downloads StyleCI License

This repository implements a simple ServiceProvider that creates a singleton instance of the Fpdf PDF library - easily accessible via a Facade in Laravel.

See FPDF homepage for more information about the usage.

Installation using Composer

$ composer require codedge/laravel-fpdf

Usage

Laravel >= 5.5

Enjoy the auto discovery feature.

Laravel <5.5

To use the static interfaces (facades) you need to add the following lines to your config/app.php. The [1] is for registering the service provider, the [2] are for specifying the facades:

// config/app.php

return [

    //...
    
    'providers' => [
        // ...
        
        /*
         * Application Service Providers...
         */
        // ...
        Codedge\Fpdf\FpdfServiceProvider::class, // [1]
    ],
    
    // ...
    
    'aliases' => [
        // ...
        'Fpdf' => Codedge\Fpdf\Facades\Fpdf::class, // [2]
]

Now you can use the facades in your application.

Configuration (optional)

Run
php artisan vendor:publish --provider="Codedge\Fpdf\FpdfServiceProvider" --tag=config
to publish the configuration file to config/fpdf.php.

Open this file and enter the correct page settings, if you do not want the defaults.

Basic example

If you want to use the facade you can see a basic example here:

// app/Http/routes.php | app/routes/web.php

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

    Fpdf::AddPage();
    Fpdf::SetFont('Courier', 'B', 18);
    Fpdf::Cell(50, 25, 'Hello World!');
    Fpdf::Output();

});

Of course you can also inject the singleton instance via dependency injection. See an example here:

// app/Http/routes.php | app/routes/web.php

Route::get('/', function (Codedge\Fpdf\Fpdf\Fpdf $fpdf) {

    $fpdf->AddPage();
    $fpdf->SetFont('Courier', 'B', 18);
    $fpdf->Cell(50, 25, 'Hello World!');
    $fpdf->Output();

});

Use in Laravel Vapor

If you are wanting to use the Laravel Vapor platform to host your application, a special/specific header will need to be attached to each response that FPDF returns to your browser. To enable the use of this header, add the following environment variable to the Vapor environment file:

FPDF_VAPOR_HEADERS=true

laravel-fpdf's People

Contributors

codedge avatar dniccum avatar

Stargazers

Javier Quiroga Almeida avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.