sun/pdf

Sun PDF is the pdf generating tools for the serious PHP developers.

v2.0 2019-08-14 04:41 UTC

This package is auto-updated.

Last update: 2024-10-14 15:59:44 UTC


README

Total Downloads Latest Stable Version Latest Unstable Version License

Sun PDF is the pdf generating tools for the serious PHP developers.

Installation Process

Just copy PDF folder somewhere into your project directory. Then include Sun PDF autoload file.

require_once('/path/to/PDF/autoload.php');

Sun PDF is also available via Composer/Packagist.

composer require sun/pdf

Basic Uses

Downloading PDF

$pdf = new Sun\PDF;
$pdf->download("<h1>Hello world</h1>");

Viewing PDF In The Browser

$pdf = new Sun\PDF;
$pdf->stream("<h1>Hello world</h1>");

Getting PDF Output

$pdf = new Sun\PDF;
$pdf->output("<h1>Hello world</h1>");

Changing Configuration

In the Sun PDF I used PhantomJS. You can change all the configuration of the PhantomJS. To change PhantomJS configuration, you need to pass your own configuration file into Sun PDF constructor.

$pdf = new Sun\PDF("/path/to/SunPdf.js");

Please, click This Link to know about all the configuration of the PhantomJS.

If you do not wish to pass HTML codes as plain string, you can pass your HTML/PHP file into all the method of the Sun PDF. To use default template engine features you need to setup everything before use. All you have to do for setup is -

$pdf = new Sun\PDF(null, "/path/to/views");

I used Twig template engine, click This Link to know about Twig template engine.

Generating PDF With Template Engine

$pdf = new Sun\PDF(null, "/path/to/views");

// download pdf 
$pdf->download("/path/to/views/test.php", ['name' => 'Iftekher Sunny']);

// viewing pdf in the browser
$pdf->stream("/path/to/views/test.php", ['name' => 'Iftekher Sunny']);

Integration In Laravel Framework

Add the ServiceProvider to the providers array in config/app.php

Sun\Provider\PDFServiceProvider::class,

Add the facade to the aliases array in config/app.php

'PDF'   =>  Sun\Facade\PDFFacade::class,

Integration In Planet Framework

Add the provider in the config/provider.php file.

Sun\Provider\PDFProvider::class,

Add the alien in the config/alien.php file.

'PDF'   =>  Sun\Alien\PDFAlien::class,

License

This package is licensed under the MIT License