1. Go to this page and download the library: Download daoandco/cakephp-dompdf 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/ */
daoandco / cakephp-dompdf example snippets
// In config/bootstrap.php
Plugin::load('Dompdf');
// In config/routes.php
Router::scope('/', function ($routes) {
$routes->extensions(['pdf']);
...
}
// In src/controller/AppController.php
public function initialize() {
parent::initialize();
$this->loadComponent('RequestHandler');
}
class YopController extends AppController {
public function view($filename) {
$this->viewBuilder()
->className('Dompdf.Pdf')
->layout('Dompdf.default')
->options(['config' => [
'filename' => $filename,
'render' => 'browser',
]]);
}
}
$this->start('header');
echo '<p>I'm a header</p>';
$this->end();
$this->start('footer');
echo '<p>I'm a footer</p>';
$this->end();
/**
* Générate an image
* @param string $path : Path to the image file, relative to the app/webroot/img/ directory
* @param array $options : Array of HTML attributes
* @return string <img>
*/
public function image($path, $options = false) {
...
}
/**
* Creates a link element for CSS stylesheets
* @param string $path : The name of a CSS style sheet
* @param bool $plugin : (true) add a plugin css file || (false) add a file in webroot/css /// default : false
* @return string <link>
*/
public function css($path, $plugin) {
...
}