xAockd / laravel-tcpdf by xAoc
forked from maxxscho/laravel-tcpdf

A simple Laravel 5 service provider with some basic configuration for including the TCPDF library
15,569
3
2
Package Data
Maintainer Username: xAoc
Maintainer Contact: dmitriy.galievskiy@outlook.com (Dmitriy Galievskiy)
Package Create Date: 2015-03-12
Package Last Update: 2018-01-29
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-25 03:02:19
Package Statistics
Total Downloads: 15,569
Monthly Downloads: 9
Daily Downloads: 1
Total Stars: 3
Total Watchers: 2
Total Forks: 3
Total Open Issues: 0

Laravel TCPDF

Build Status

A simple Laravel 5 service provider with some basic configuration for including the TCPDF library

Installation

The Laravel TCPDF service provider can be installed via composer by requiring the xaoc/laravel-tcpdf package in your project's composer.json. (The installation may take a while, because the package requires TCPDF. Sadly its .git folder is very heavy)

{
    "require": {
        "xaoc/laravel-tcpdf": "dev-master"
    }
}

Next, add the service provider to app/config/app.php.

'providers' => [
    //..
    'Xaoc\LaravelTcpdf\LaravelTcpdfServiceProvider',
]

That's it! You're good to go.

Here is a little example:

PDF::SetTitle('Hello World');

PDF::AddPage();

PDF::Write(0, 'Hello World');

PDF::Output('hello_world.pdf');

For a list of all available function take a look at the TCPDF Documentation

Configuration

Laravel-TCPDF comes with some basic configuration. If you want to override the defaults, you can publish the config, like so:

php artisan vendor:publish

Now access app/config/laravel-tcpdf.phpto customize.

Extend/Overwrite

Extending or overwriting Laravel TCPDF is easy. Simply extend \Xaoc\LaravelTcpdf\LaravelTcpdf with your own class.

Custom Fonts

To add custom fonts set the fonts_directory in the config, relative to the public path. For example 'fonts/'.

To use a custom font you have to convert a font for TCPDF. Copy your custom font(s) to your fonts path, in our case public/fonts/. In your terminal do this:

vendor/xaoc/laravel-tcpdf/vendor/tecnick.com/tcpdf/tools/tcpdf_addfont.php -i public/fonts/yourfont.ttf -o public/fonts

This uses a little tool provided by TCPDF to convert fonts for TCPDF. The -i flag is for the input fonts (comma-separated list) and the -o flag is for the output directory. Read here all about TCPDF fonts and how to convert them the new way.