Sun PDF is the pdf generating tools for the serious PHP developers.
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
$pdf = new Sun\PDF;
$pdf->download("<h1>Hello world</h1>");
$pdf = new Sun\PDF;
$pdf->stream("<h1>Hello world</h1>");
$pdf = new Sun\PDF;
$pdf->output("<h1>Hello world</h1>");
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.
$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']);
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,
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,
This package is licensed under the MIT License