2017 © Pedro PelĂĄez
 

cakephp-plugin cakephp-dompdf

Dompdf plugin for CakePHP

image

daoandco/cakephp-dompdf

Dompdf plugin for CakePHP

  • Sunday, May 28, 2017
  • by ozee31
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2,090 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 4 Open issues
  • 7 Versions
  • 10 % Grown

The README.md

Dompdf plugin for CakePHP

Requirements

  • PHP version 5.4.16 or higher
  • CakePhp 3.0 or higher
  • Dompdf 0.7

Installation

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require daoandco/cakephp-dompdf

After installation, generate symlink for CSS (http://book.cakephp.org/3.0/en/deployment.html#symlink-assets), (*3)

// In a shell
bin/cake plugin assets symlink

Quick Start

Loading the Plugin, (*4)

  // In config/bootstrap.php
  Plugin::load('Dompdf');

Activate pdf extension (http://book.cakephp.org/3.0/en/development/routing.html#routing-file-extensions), (*5)

  // In config/routes.php
  Router::scope('/', function ($routes) {

    $routes->extensions(['pdf']);
    ...
  }

Loading component RequestHandler, (*6)

  // In src/controller/AppController.php
  public function initialize() {
    parent::initialize();

    $this->loadComponent('RequestHandler');
  }

In a controller, (*7)

class YopController extends AppController {

    public function view($filename) {

        $this->viewBuilder()
            ->className('Dompdf.Pdf')
            ->layout('Dompdf.default')
            ->options(['config' => [
                'filename' => $filename,
                'render' => 'browser',
            ]]);
    }
}

Create a view (pdf content), (*8)


start('header'); ?>
    <p>Header.</p>
end(); ?>

start('footer'); ?>
    <p>Footer.</p>
end(); ?>




My title

Banana, (*9)

Boom !!!, (*10)

Show the pdf in your browser : http://dev.local/myproject/yop/view/test.pdf, (*11)

Configuration

Use $this->viewBuilder() with :, (*12)

  • ->className() : set the view classname http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_className Use the plugin view by default className('Dompdf.Pdf'), (*13)

  • ->layout() : set the name of the layout file to render the view http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_layout Use the plugin layout by default layout('Dompdf.default'), (*14)

  • ->options() : Set additional options for the view http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_options Use array with key config and value array with dompdf config, (*15)

    • filename : pdf name
    • upload_filename : path with filename for upload render
    • render : (see render )
    • browser : show in browser
    • download : download the pdf by browser
    • upload : save file on the server
    • stream : return a stream resource for sending file without save
    • size : paper size : default A4
    • orientation : paper orientation (portait OR landscape) : default portrait
    • dpi : Image DPI setting : default 192
    • isRemoteEnabled : Enable remote file access : default true
    • paginate: activate pagination (array) : default false (see paginate )
    • More options : see dompdf documention https://github.com/dompdf/dompdf/wiki

View

with default layout and dompdf.css, (*16)

$this->start('header');
    echo '<p>I'm a header</p>';
$this->end();

with default layout and dompdf.css, (*17)

$this->start('footer');
    echo '<p>I'm a footer</p>';
$this->end();

Image

use Helper, (*18)

/**
  * 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) {
  ...
}

Exemple :, (*19)

echo $this->Dompdf->image('test.png', ['class' => 'imgclass']);

CSS stylesheets

use Helper, (*20)

/**
  * 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) {
  ...
}

Exemple :, (*21)

echo $this->Dompdf->css('mycss');

Page break

with dompdf.css, (*22)



Page 1, (*23)

= $this->Dompdf->page_break(); ?>

Page 2, (*24)

Render

Display on browser

``` PHP $this->viewBuilder() ->className('Dompdf.Pdf') ->layout('Dompdf.default') ->options(['config' => [ 'render' => 'browser', ]]);, (*25)


### Force download on browser ``` PHP $this->viewBuilder() ->className('Dompdf.Pdf') ->layout('Dompdf.default') ->options(['config' => [ 'filename' => 'mydocument', 'render' => 'download', ]]);

Upload on server

``` PHP $this->viewBuilder() ->className('Dompdf.Pdf') ->layout('Dompdf.default') ->options(['config' => [ 'upload_filename' => WWW_ROOT.'pdf/mydocument.pdf', 'render' => 'upload', ]]);, (*26)


### Stream ``` PHP use Cake\View\ViewBuilder; $builder = new ViewBuilder(); $builder->className('Dompdf.Pdf') ->layout('Dompdf.pdf/default') ->template('Pdf/pdf/view') ->options(['config' => [ 'render' => 'stream', ]]); $view = $builder->build(); $stream = $view->render();

Paginate

With helper

You can show page number but not number of pages, (*27)

<!-- In a view -->
<?php $this->start('footer'); ?>
    <p><?= $this->Dompdf->page_number(); ?></p>
<?php $this->end(); ?>

With PdfView

You can show page number and number of pages Use paginate key in view config, (*28)

$this->viewBuilder()
    ->className('Dompdf.Pdf')
    ->layout('Dompdf.default')
    ->options(['config' => [
        'filename' => $filename,
        'render' => 'browser',
        'paginate' => [
            'x' => 550,
            'y' => 5,
        ],
    ]]);

Paginate options : - x : left position : default 0 - y : top position : default 0 - font : font family : default null - size : font size : default 12 - text : default "{PAGE_NUM} / {PAGE_COUNT}" - color : rgb (array) : default [0,0,0] = black, (*29)

The Versions

28/05 2017

dev-master

9999999-dev https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

28/05 2017

v1.2.0

1.2.0.0 https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

28/05 2017

dev-Tresmollo-master

dev-Tresmollo-master https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

12/05 2016

v1.1.0

1.1.0.0 https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

08/02 2016

V1.0.2

1.0.2.0 https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

08/02 2016

V1.0.1

1.0.1.0 https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf

05/02 2016

v1.0.0

1.0.0.0 https://github.com/DaoAndCo/cakephp-dompdf

Dompdf plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

css cakephp html pdf dompdf