Generating a PDF
There comes a time when you'll want to create a PDF document in many applications. In this recipe, we'll look at how to output some content in a PDF document.
Getting ready
For this recipe, we'll use a plugin called CakePdf
, which can be found at https://github.com/ceeram/CakePdf.
The contents of this plugin should be added to app/Plugin/CakePdf/
and loaded by the application. To do so, add the following code to your bootstrap.php
file located in app/Config/
:
CakePlugin::load('CakePdf', array( 'bootstrap' => true, 'routes' => true ));
Then, we need a controller to generate a PDF document. Create a file named ReportsController.php
in app/Controller/
, and introduce the following content:
<?php App::uses('AppController', 'Controller'); class ReportsController extends AppController { }
Then, we'll set up some configuration options for the plugin. The most important of all is the PDF engine we want to use, as the plugin provides a few. For this example, we'll use dompdf...