Download the PHP package mikehaertl/pdfable without Composer
On this page you can find all versions of the php package mikehaertl/pdfable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mikehaertl/pdfable
More information about mikehaertl/pdfable
Files in mikehaertl/pdfable
Package pdfable
Short Description PDFable is a Yii extension to create PDFs from web pages with PHPWkHtmlToPdf(included)
License MIT
Homepage https://github.com/mikehaertl/pdfable
Informations about the package pdfable
PDFable
PDFable
is a Yii extension to create PDFs from web
pages with PHPWkHtmlToPdf (included).
Requirements
PDFable
requires the wkhtmltopdf binary to be
installed on your system.
Installation
Download the package file and unzip it to the extensions
directory. Note, that you
may want to rename the directory from pdfable-x.y.z
to pdfable
.
Example module
To try out the extension, you can configure the pdfable
example module in your main.php
:
The module should then be available from http://localhost/index.php?r=pdfable/demo or whatever you use as hostname. I recommend to have a look at this example module's code.
Basic configuration
PDFable
comes as a controller behavior which gets attached through behaviors
:
Basic use
To render single page PDFs from a view file you just call renderPdf()
instead
of render()
. This will convert the view file to a PDF and display it inline in
the browser:
Just as with render() you can of course also render more complex views with custom data. And if you want to open a download dialog, you can also pass the download filename as 4th argument:
The third parameter allows you to pass additional PDF page options to wkhtmltopdf
.
See advanced configuration below.
Advanced use
Multi-Page PDFs
PDFs with more than one page (=view) are also possible. Here you would
use the createPdf()
method. It returns a PdfFile
object.
Use from console commands
You can also create PDFs from console commands through the low-level PdfFile
class.
The following example is taken from the example module:
If you want to try the example command you can add it to the commandMap
in your console.php
:
You then can create an example PDF with ./yiic demopdf --filename=/tmp/demo.pdf
.
Advanced configuration
It's recommended to have a look at the PHPWkHtmlToPdf
documentation. All the options described there are also available with PDFable
.
Default page options
You can set default PDF options for the document and each page in the
behaviors()
method:
Override hardcoded page defaults
The behavior uses some hardcoded defaults for document and page options (see PdfFile). Your configuration above will always be merged with these defaults. If you don't like this and want complete freedom instead, then configure the behavior like this:
Custom page options
You can supply custom wkhtmltopdf
page options along as third parameter to
renderPdf()
. The format is the same as for addPage()
in PHPWkHtmlToPdf
.