- wkhtmltopdf - executable binary to generate pdf file from html file
- phpwkhtmltopdf - php library to handle html file creation then execute wkhtmltopdf cli
- composer - dependency manager to install php dependencies
- Install wkhtmltopdf binary and ensure it's work well on your machine
- Add phpwkhtmltopdf dependency to your project.
- Add WKPDF.php to your libraries directory (
application/libraries/
) - Add phpwkhtmltopdf.php to your config directory (
application/config/
) - Update the configuration phpwkhtmltopdf.php file to align with your environment
Available configs are available at https://github.com/mikehaertl/phpwkhtmltopdf
Generate pdf in your controller:
$this->load->library('WKPDF');
// true in third params is to determine
// whether the pdf file should be downloaded
// otherwise it will be shown in your browser as preview
if (!$this->wkpdf->generate('<h1>Hello World!</h1>', 'hello.pdf', true)) {
echo $this->wkpdf->getError();
}