PHPackages                             calvibert/wkhtmltopdf - 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. calvibert/wkhtmltopdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

calvibert/wkhtmltopdf
=====================

WKHTMLTOPDF generator for CakePHP3

0222PHP

Since Jan 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Calvibert/wkhtmltopdf-cakephp3)[ Packagist](https://packagist.org/packages/calvibert/wkhtmltopdf)[ RSS](/packages/calvibert-wkhtmltopdf/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PDF generator for CakePHP3 (wkhtmltopdf)
========================================

[](#pdf-generator-for-cakephp3-wkhtmltopdf)

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

[](#installation)

Install wkhtmltopdf on your system! ().

Install by composer:
--------------------

[](#install-by-composer)

```
composer require grzegab/wkhtmltopdf

```

Override default config:
------------------------

[](#override-default-config)

In config/boostrap.php write configure:
Configure::write('wkhtmltopdf.enableXvfb', false);
Configure::write('wkhtmltopdf.encoding', 'UTF-8');

Available options are:

- 'enableXvfb' - boolean if xvfb should be used with wkhtmltopdf,
- 'xvfbRunBinary' - binary of xvfb - default 'xvfb-run',
- 'xvfbRunOptions' - options used in xvfb - default '-a -s "-screen 0 1024x678x16"',
- 'wkhtmltopdfBinary' - path to binary - default '/usr/local/bin/wkhtmltopdf',
- 'encoding' - name of encoding - default 'UTF-8',
- 'layout' - name of template (located in Template/Layout/)

Usage
-----

[](#usage)

Add namespace on each controller that will use pdf generator:
use Grzegab\\Wkhtmltopdf\\PdfGenerator;

Create new action with return of PDF object (e.g. invoicePdf): public function invoicePdf() {};

Build controller, setup view variables as you whis to page look like.

Init component:
$pdf = new PdfGenerator($this);

Must set template name and view file (even if default is used): $this-&gt;viewBuilder()-&gt;layout('pdf')-&gt;template('invoice');

Return PDF as response from controller:
return $pdf-&gt;save('pdfName')-&gt;wkhtmltopdf('-O landscape')-&gt;generatePDF();

Can also build PDF file from URL address:
return $pdf-&gt;generateFromUrl('[http://www.google.com')-&gt;generatePDF(](http://www.google.com')-%3EgeneratePDF());

If you wish only to save PDF file (without downloading it as response):
return $pdf-&gt;save('pdf\_name')-&gt;downloadDisabled()-&gt;generatePDF();
Response will be path of saved file.

#### Remember

[](#remember)

All assets (images, js etc.) *MUST* have absolute path for PDF generator. Name of pdf file should be without extension "pdf".

Examples of usage
-----------------

[](#examples-of-usage)

in src/Controller/InvoiceController.php:

use Grzegab\\Wkhtmltopdf\\PdfGenerator;

public function invoicePDF($id)
{
// ... find invoice by id and other logic
$pdf = new PDF($this); $this-&gt;viewBuilder()-&gt;layout('pdf')-&gt;template('invoice'); return $pdf-&gt;save('name0123', 'pdf/names')-&gt;wkhtmltopdf('-O landscape')-&gt;generatePDF();
}

When invoicePdf/{id} executed will have pdf file saved in webroot/pdf/names with name0123 and forced to download.

List of avilable commands
-------------------------

[](#list-of-avilable-commands)

#### Basic Commands

[](#basic-commands)

All commands are chainable $pdf-&gt;command1()-&gt;command2()-&gt;command3()-&gt;generatePDF();

Ending commands:

- $pdf-&gt;debugPDF(); will return current settings for PDF generator
- $pdf-&gt;generatePDF(); wll try to generate PDF file

Settings:

- $pdf-&gt;wkhtmltopdf(*string*); add wkhtmltopdf option
- $pdf-&gt;setEncoding(*string*); sets encoding for PDF (default UTF-8)
- $pdf-&gt;setTemplate(*string*); sets view file (the one that should be used to generate PDF)
- $pdf-&gt;setLayout(*string*); sets layout file
- $pdf-&gt;downloadDisabled(); do not force to download file
- $pdf-&gt;savePdf(*string1*, *string2* \[optional\]); save PDF file with name (string1 - without ".pdf") and path (string2 - path is in webroot/)
- $pdf-&gt;setWkhtmltopdfBinary(*string1*); path to binary - default '/usr/local/bin/wkhtmltopdf'
- $pdf-&gt;xvfb(*boolean*, *string1*, *string2*); first parameter to enable or disable xvfb, second is name of binary (default xvfb-run) and third is additional options for xvfb (default: -a -s "-screen 0 1024x678x16")
- $pdf-&gt;generateFromHtml(*string*); enter own html for PDF
- $pdf-&gt;generateFromUrl(*string*); enter url that PDF should be generated from

#### Wkhtmltopdf commands

[](#wkhtmltopdf-commands)

List of all commands avilalble for wkhtmltopdf ().
Usage: return $pdf-&gt;wkhtmltopdf('-O landscape')-&gt;wkhtmltopdf('-l')-&gt;generatePDF();

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/grzegab/wktohtmlpdf-cakephp3/blob/master/LICENSE) for more information.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/77723ea24397e49f35b17e4173778ddce87bef491a9df9b88ffb5c98a58b8ab0?d=identicon)[Calvibert](/maintainers/Calvibert)

---

Top Contributors

[![Calvibert](https://avatars.githubusercontent.com/u/11411336?v=4)](https://github.com/Calvibert "Calvibert (4 commits)")

### Embed Badge

![Health badge](/badges/calvibert-wkhtmltopdf/health.svg)

```
[![Health](https://phpackages.com/badges/calvibert-wkhtmltopdf/health.svg)](https://phpackages.com/packages/calvibert-wkhtmltopdf)
```

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.2k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M100](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M128](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

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