uthando-cms / uthando-dompdf
A Zend Framework 2 module for incorporating DOMPDF support.
Requires
- php: >=7.0
- dompdf/dompdf: 0.*
- neilime/zf2-twb-bundle: 2.*@stable
- uthando-cms/uthando-common: 2.*
- zendframework/zend-config: 2.*
- zendframework/zend-eventmanager: 2.*
- zendframework/zend-http: 2.*
- zendframework/zend-loader: 2.*
- zendframework/zend-modulemanager: 2.*
- zendframework/zend-mvc: 2.*
- zendframework/zend-servicemanager: 2.*
- zendframework/zend-stdlib: 2.*
- zendframework/zend-view: 2.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
Suggests
- uthando-cms/uthando-admin: Admin operations
- uthando-cms/uthando-navigation: Navigation management.
- uthando-cms/uthando-user: User management
README
This project is based on https://github.com/raykolbe/DOMPDFModule. I have adapted it for Uthando CMS but it can be used independently. The UthandoDomPdf module integrates the DOMPDF library with Zend Framework 2 with minimal effort on the consumer's end.
Requirements
Installation
Installation of UthandoDomPdf uses PHP Composer. For more information about PHP Composer, please visit the official PHP Composer site.
Installation steps
-
cd my/project/directory
-
create a
composer.json
file with following contents:{ "require": { "uthando-cms/uthando-dompdf": "2.*" } }
-
install PHP Composer via
curl -s http://getcomposer.org/installer | php
(on windows, download http://getcomposer.org/installer and execute it with PHP) -
run
php composer.phar install
-
open
my/project/directory/config/application.config.php
and add the following key to yourmodules
:'UthandoDomPdf',
Configuration options
You can override options via the uthando_dompdf
key in your local or global config files. See UthandoDomPdf/config/module.config.php.dist for config options.
Usage
<?php namespace Application\Controller; use Zend\Mvc\Controller\AbstractActionController; use UthandoDomPdf\View\Model\PdfModel; class ReportController extends AbstractActionController { public function monthlyReportPdfAction() { $pdf = $this->getServiceLocator()->get('PdfModel'); $pdf->getPdfOptions()->setFilename('monthly-report'); // Triggers PDF download, automatically appends ".pdf" $pdf->getPdfOptions()->setPaperSize('a4'); // Defaults to "8x11" $pdf->getPdfOptions()->setPaperOrientation('landscape'); // Defaults to "portrait" // set footer/header on every page, this is an array of arrays. Each array represents one line of text // to set header lines use the setHeaderLines() method $pdf->getPdfOptions()->setFooterLines([ [ 'text' => 'top line', // text to print 'position' => 'center', // alignment of text can be center, left or right 'font' => [ 'family' => 'Helvetica', // font family 'weight' => 'normal', // font weight can be normal, bold, italic or bold_italic 'size' => 8, // size of font in pt ], ], ]); // example showing how to set header lines $pdf->getPdfOptions()->setHeaderLines([ [ 'text' => 'top line', // text to print 'position' => 'center', // alignment of text can be center, left or right 'font' => [ 'family' => 'Helvetica', // font family 'weight' => 'normal', // font weight can be normal, bold, italic or bold_italic 'size' => 8, // size of font in pt ], ], ]); // To set view variables $pdf->setVariables(array( 'message' => 'Hello' )); return $pdf; } }
Admin Settings and Configuration
There is an admin setting page. It's not enabled by default. If you are using UthandoAdmin you can enable the routes, navigation and acl rules by adding
'load_uthando_configs' => true,
to you global config in config/autoload/global.php
and add
{ "require": { "uthando-cms/uthando-admin": "1.*" } }
to your composer.json file then do and php composer.phar update
to update your dependencies.
If you are not using the UthandoAdmin module you can still use the settings page but must configure the routes, navigation and acl rules manually, please not that if you do not have any authentication checks then the settings page will be available to the public. You can use the files in config folder as a basis to set up the admin page.
The Admin settings page also requires that you have Twitter Bootstrap 3 and JQuery enabled in your layout template.
You can also manually setup the options by copying config/module.config.php.dist
to your config\autoload
folder and renaming it to uthando-dompdf.local.php
.
Contributing
If you like to help improve this module please clone the repository and send me a pull request, please also include unit tests for the changes/additions you make.
To-do
- Add command line support.