guenbakku / cakepdf
CakePHP plugin for converting HTML to PDF
Installs: 3 167
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.2
- h4cc/wkhtmltopdf-amd64: ^0.12.4
- h4cc/wkhtmltopdf-i386: ^0.12.4
- knplabs/knp-snappy: 1.4.x
Requires (Dev)
- phpunit/phpunit: ^8.5.38
README
Easily generate PDFs from your HTML content.
This versatile tool can be used as:
- A CakePHP plugin: Seamlessly integrate PDF generation into your CakePHP 2.x and above applications.
- A standalone library: Use it independently outside of CakePHP for maximum flexibility.
Powered by Snappy (https://github.com/KnpLabs/snappy)
I want to give a big thanks to the creators of the fantastic Snappy library, which makes this functionality possible.
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');