1. Go to this page and download the library: Download danny3b/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/ */
danny3b / cakepdf example snippets
Plugin::load('CakePdf', ['bootstrap' => true]);
Router::extensions(['pdf']);
Router::scope('/', function (\Cake\Routing\RouteBuilder $routes) {
$routes->addExtensions(['pdf']);
// ...
});
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',
// 'cwd' => 'C:\\Progra~1\\wkhtmltopdf\\bin',
'options' => [
'print-media-type' => false,
'outline' => true,
'dpi' => 96
],
],
]);
$CakePdf = new \CakePdf\Pdf\CakePdf();
$CakePdf->template('newsletter', 'default');
$CakePdf->viewVars($this->viewVars);
// Get the PDF string returned
$pdf = $CakePdf->output();
// Or write it to file directly
$pdf = $CakePdf->write(APP . 'files' . DS . 'newsletter.pdf');