PHPackages                             a5sys/pdf-bundle - 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. a5sys/pdf-bundle

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

a5sys/pdf-bundle
================

Generates PDF

31.7k↓87.5%2[1 PRs](https://github.com/A5sys/PdfBundle/pulls)PHP

Since Aug 31Pushed 3y ago6 watchersCompare

[ Source](https://github.com/A5sys/PdfBundle)[ Packagist](https://packagist.org/packages/a5sys/pdf-bundle)[ RSS](/packages/a5sys-pdf-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

PdfBundle
=========

[](#pdfbundle)

#### Goal

[](#goal)

This bundle allows generation of pdf docs by using the wrapper **phpwkhtmltopdf**, which uses himself the tool **wkhtmltopdf**.

The advantage of **wkhtmltopdf** is that it's Webkit processing html code, with JS and CSS functionnal, as if the code were ran in a browser.

\####Why this bundle, KnpSnappyBundle already exist ?

KnpSnappyBundle does not work in all cases, particularly on Windows when generated HTML has external files (CSS, JS, images). We hit some network access, because of the PHP proc\_open function, which seems buggy.

After a successful try with phpwkhtmltopdf, this bundle was created to integrate with Symfony 2.

#### dependencies

[](#dependencies)

Requires **phpwkhtmltopdf** and **wkhtmltopdf**.

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

[](#installation)

First install **wkhtmltopdf** ()

Add dependencies in `composer.json` :

```
"a5sys/pdf-bundle": "dev-master",
"mikehaertl/phpwkhtmltopdf": "~2.0"
```

Declare bundle in `AppKernel.php` :

```
new A5sys\PdfBundle\A5sysPdfBundle(),
```

Note: the wrapper **phpwkhtmltopdf** is a library, not a bundle.

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

[](#configuration)

- Install wkhtmltopdf. Be sure not to have spaces in the path.
- Configure A5sys ProjectBundle

In **config.yml**, add :

```
a5sys_pdf:
    binary: "C:/wkhtmltopdf/bin/wkhtmltopdf.exe"
    # temp_dir: "D:/tmp"
    # encoding: "UTF-8"
    # command_options:
    #    use_exec: true
    #    escape_args: false
    #    proc_options:
    #        bypass_shell: true
    #        suppress_errors: false
```

- binary: mandatory
- temp\_dir: optional, default system temp dir (C:/windows/temp).
- encoding: optional, default UTF-8
- command\_options: optional, by default the array is created with the default children values -- use\_exec: optional, default true, does the system use exec function instead of proc\_open ? -- escape\_args: optional, default false, does the system escape parameters before integrating it to the command ? -- proc\_options: optional, default NULL, used when use\_exec = false ---- bypass\_shell: optional, default true, adviced when on Windows ---- suppress\_errors: default false. Adviced to TRUE when on Windows. Generation can be done ,even if error occired. NO GUARRANTY pdf is correctly generated.

Usage
-----

[](#usage)

Example given in a profession service.

$this-&gt;templating is injected twig service. $this-&gt;pdfService is pdf service to be injected.

*utf8\_decode* for header et footer. Necessary to get accents.

```
use A5sys\PdfBundle\Service\PdfService;

class MyService
{
    /**
     * @var $data array
     */
    public function savePdf($data)
    {
        // HTML of pdf
        $html = $this->templating->render('MyAppBundle:Folder:my_pdf.pdf.twig', $data);

        // Header in HTML
        $htmlHeader = $this->templating->render('MyAppBundle:Folder:my_header.pdf.twig');

        // Footer in HTML
        $htmlFooter = $this->templating->render('MyAppBundle:Folder:my_footer.pdf.twig');

        // name and path to PDF file
        $fileName = uniqid() . ".pdf";
        $filePath = $this->constants['my_pdf_path'] . "/" . $fileName;

        // note : throws ServiceException
        // Generation and saving of the PDF

        $options = array(
           //'no-outline',
            'orientation' => 'Landscape',
            'header-html' => utf8_decode($htmlHeader),
            'header-spacing' => '2', // space between header and content in mm
            'footer-html' => utf8_decode($htmlFooter),
        );

        $this->pdfService->saveAs(
            $filePath,
            $html,
            $options
        );
    }
}
```

To the 2015-02-10, only saveAs is implemented for the wrapper phpwkhtmltopdf.

Options
-------

[](#options)

Variable \*\*$options \*\* allows to specify options to use for the generation. At the begining, informations from configuration will b integrated to this array. If you want to override the value of the conf, simply add the key of the wrapper **phpwkhtmltopdf** to the array.

Specific **phpwkhtmltopdf** wrapper are here:

Still in **$options**, at the same level than specific wrapper options, you can add all options you want to give to **wkhtmltopdf**, as for example orientation , header-spacing, header-html or footer-html like shown in the example.

All wkhtmltopdf options here :

Page break
----------

[](#page-break)

In the example, $html varaible contains all HTML to render in PDF. It is possible to tell explicitly where to page break, simply using CSS:

``

Page numbers
------------

[](#page-numbers)

In the footer-html of the example, no param is given, but wkhtmltopdf do it for us ! We can get the current page number and even more, for example with this code :

```
>

        function subst() {
          var vars={};
          var x=document.location.search.substring(1).split('&');
          for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
          var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
          for (var i in x) {
            var y = document.getElementsByClassName(x[i]);
            for (var j=0; j

            {{ 'now'|date('d/m/Y') }}
            {{ 'pdf.archival.title'|trans|raw('html') }}

              {{ 'page'|trans }}  {{ 'pageOn'|trans }}

```

JS works ? Yes it's Webkit that process the page, even for header-html and footer-html

**Note** : Don't forget the doctype in footer and header, it won't work otherwise !

This HTML code displays the date to the left, a translated text in the center, and the text "page x sur y" to the right

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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/c429f46d826a96644aa39a86ad00a6834bfa6b9190b7a62b8c42c53baf66b4b1?d=identicon)[jonag](/maintainers/jonag)

![](https://www.gravatar.com/avatar/3a644d41501105bc7aded710d1682ac2a3abdceaf9c02e97d1cb1d6e2607c9d9?d=identicon)[ttx-a5](/maintainers/ttx-a5)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/a5sys-pdf-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/a5sys-pdf-bundle/health.svg)](https://phpackages.com/packages/a5sys-pdf-bundle)
```

###  Alternatives

[tarfin-labs/easy-pdf

Makes pdf processing easy.

1719.9k](/packages/tarfin-labs-easy-pdf)

PHPackages © 2026

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