1. Go to this page and download the library: Download pieceofcake2/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/ */
class InvoicesController extends AppController {
//in your Invoices controller you could set additional configs, or override the global ones:
public function view($id = null) {
$this->Invoice->id = $id;
if (!$this->Invoice->exists()) {
throw new NotFoundException(__('Invalid invoice'));
}
$this->pdfConfig = [
'orientation' => 'portrait',
'filename' => 'Invoice_' . $id,
];
$this->set('invoice', $this->Invoice->read(null, $id));
}
}
$cakePdf = new 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');