guenbakku / cakepdf
CakePHP plugin for converting HTML to PDF
Installs: 3 150
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.6
- h4cc/wkhtmltopdf-amd64: ^0.12.3
- h4cc/wkhtmltopdf-i386: ^0.12.3
- knplabs/knp-snappy: ^0.5.0
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0
This package is auto-updated.
Last update: 2024-03-23 16:41:11 UTC
README
CakePHP plugin for converting HTML to PDF.
This plugin is compatible with CakePHP 2.x and CakePHP 3.x.
This plugin could not be made without awesome library Snappy.
Thankful to the authors of library Snappy.
Installation
You can install this library using composer.
composer require guenbakku/cakepdf
Usage
<?php use Guenbakku\Cakepdf\Pdf; // Instance object. // Different with original Snappy, this libary comes with // wkhtmltopdf binary which is installed as composer dependencies. // So following setup also automatically set wkhtmltopdf binary's path // corresponding to current processor's structure (32 or 64 bit). $Pdf = new Pdf(); // Add html to render to pdf. // Break page will be inserted automatically by wkhtmltopdf. $html = '<p>Long html for long pdf</p>'; $Pdf->add($html); // Add each html as a seperated pdf page. $page = '<p>Page</p>'; $Pdf->addPage($page) ->addPage($page); // Render output to display in browser. header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="file.pdf"'); $result = $Pdf->render(); echo $result; // Or render output to pdf file. $output = '/tmp/cakepdf.pdf'; $Pdf->render($output); // Set options for wkhtmltopdf. // Basically same with Snappy's interface. $Pdf = new Pdf(); $Pdf->setOption('page-size', 'A4') ->setOption('orientation', 'Landscape');