PHPackages                             mbamarante/cakephp-dompdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. mbamarante/cakephp-dompdf

ActiveCakephp-plugin[PDF &amp; Document Generation](/categories/documents)

mbamarante/cakephp-dompdf
=========================

Dompdf plugin for CakePHP

2.0.1(4y ago)0938MITPHPPHP &gt;=7.2

Since Feb 5Pushed 4y agoCompare

[ Source](https://github.com/mbamarante/cakephp-dompdf)[ Packagist](https://packagist.org/packages/mbamarante/cakephp-dompdf)[ Docs](https://github.com/DaoAndCo/cakephp-dompdf)[ RSS](/packages/mbamarante-cakephp-dompdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (10)Used By (0)

Dompdf plugin for CakePHP
=========================

[](#dompdf-plugin-for-cakephp)

Requirements
------------

[](#requirements)

- PHP version 7.2 or higher
- CakePhp 4.0 or higher
- Dompdf 0.8.6

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require mbamarante/cakephp-dompdf

```

After installation, generate symlink for CSS ()

```
// In a shell
bin/cake plugin assets symlink

```

Quick Start
-----------

[](#quick-start)

Loading the Plugin

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

Activate pdf extension ()

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

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

Loading component RequestHandler

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

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

In a controller

```
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)

```

start('header'); ?>
    Header.
end(); ?>

start('footer'); ?>
    Footer.
end(); ?>

My title

Banana

Boom !!!
```

Show the pdf in your browser :

Configuration
-------------

[](#configuration)

Use `$this->viewBuilder()` with :

- -&gt;className() : set the view classname [http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#\_className](http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_className)Use the plugin view by default `className('Dompdf.Pdf')`
- -&gt;layout() : set the name of the layout file to render the view [http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#\_layout](http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_layout)Use the plugin layout by default `layout('Dompdf.default')`
- -&gt;options() : Set additional options for the view [http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#\_options](http://api.cakephp.org/3.1/class-Cake.View.ViewBuilder.html#_options)Use array with key `config` and value `array` with dompdf config

    - filename : pdf name
    - upload\_filename : path with filename for upload render
    - render : (see [render](#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](#paginate) )
    - More options : see dompdf documention

View
----

[](#view)

### Header

[](#header)

*with default layout and `dompdf.css`*

```
$this->start('header');
    echo 'I'm a header';
$this->end();
```

### Footer

[](#footer)

*with default layout and `dompdf.css`*

```
$this->start('footer');
    echo 'I'm a footer';
$this->end();
```

### Image

[](#image)

**use Helper**

```
/**
  * 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
  */
public function image($path, $options = false) {
  ...
}
```

Exemple :

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

### CSS stylesheets

[](#css-stylesheets)

**use Helper**

```
/**
  * 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
  */
public function css($path, $plugin) {
  ...
}
```

Exemple :

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

### Page break

[](#page-break)

*with `dompdf.css`*

```
Page 1

Dompdf->page_break(); ?>

Page 2
```

Render
------

[](#render)

### Display on browser

[](#display-on-browser)

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

### Force download on browser

[](#force-download-on-browser)

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

### Upload on server

[](#upload-on-server)

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

### Stream

[](#stream)

```
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
--------

[](#paginate)

### With helper

[](#with-helper)

You can show page number but not number of pages

```

start('footer'); ?>
    Dompdf->page_number(); ?>
end(); ?>
```

### With PdfView

[](#with-pdfview)

You can show page number and number of pages Use paginate key in view config

```
$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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~312 days

Recently: every ~523 days

Total

8

Last Release

1566d ago

Major Versions

v1.2.1 → 2.0.02020-12-30

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.16

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/92f4b245f383cdb65063ab8bfa8948b9060959adb2f0022623ebb40c3b3b0a98?d=identicon)[maicon.amarante](/maintainers/maicon.amarante)

---

Top Contributors

[![mbamarante](https://avatars.githubusercontent.com/u/409833?v=4)](https://github.com/mbamarante "mbamarante (11 commits)")[![ozee31](https://avatars.githubusercontent.com/u/5025797?v=4)](https://github.com/ozee31 "ozee31 (11 commits)")

---

Tags

pdfcsshtmlcakephpdompdf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mbamarante-cakephp-dompdf/health.svg)

```
[![Health](https://phpackages.com/badges/mbamarante-cakephp-dompdf/health.svg)](https://phpackages.com/packages/mbamarante-cakephp-dompdf)
```

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

54882.8k1](/packages/nucleos-dompdf-bundle)[dino/dompdf-module

A Zend Framework 2 module for incorporating DOMPDF support.

61465.1k8](/packages/dino-dompdf-module)[phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

158.9k](/packages/phpnt-yii2-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
