uthando-cms/uthando-dompdf

A Zend Framework 2 module for incorporating DOMPDF support.

2.6.0 2018-11-19 19:33 UTC

This package is auto-updated.

Last update: 2024-02-29 02:18:28 UTC


README

Build Status Test Coverage Code Climate Dependency Status Packagist

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

  1. cd my/project/directory

  2. create a composer.json file with following contents:

    {
        "require": {
            "uthando-cms/uthando-dompdf": "2.*"
        }
    }
  3. install PHP Composer via curl -s http://getcomposer.org/installer | php (on windows, download http://getcomposer.org/installer and execute it with PHP)

  4. run php composer.phar install

  5. open my/project/directory/config/application.config.php and add the following key to your modules:

    '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.