1. Go to this page and download the library: Download iamthom/cakepdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
// Mac OS X / Linux is usually like:
'binary' => '/usr/local/bin/wkhtmltopdf',
// On Windows environmnent you NEED to use the path like
// old fashioned MS-DOS Paths, otherwise you will keep getting:
// WKHTMLTOPDF didn't return any data
// 'binary' => 'C:\\Progra~1\\wkhtmltopdf\\bin\\wkhtmltopdf.exe',
'options' => [
'print-media-type' => false,
'outline' => true,
'dpi' => 96
],
],
]);
$CakePdf = new \CakePdf\Pdf\CakePdf();
$CakePdf->template('newsletter', 'default');
//get the pdf string returned
$pdf = $CakePdf->output();
//or write it to file directly
$pdf = $CakePdf->write(APP . 'files' . DS . 'newsletter.pdf');