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

ActiveSymfony-bundle

orkestra/pdf-bundle
===================

Provides integration between Symfony and PDF generation libraries

0.9.2(12y ago)21.5k2[1 PRs](https://github.com/orkestra/OrkestraPdfBundle/pulls)1MITPHPPHP &gt;=5.3.0

Since Nov 7Pushed 8y ago4 watchersCompare

[ Source](https://github.com/orkestra/OrkestraPdfBundle)[ Packagist](https://packagist.org/packages/orkestra/pdf-bundle)[ RSS](/packages/orkestra-pdf-bundle/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (1)

OrkestraPdfBundle
=================

[](#orkestrapdfbundle)

[![Build Status](https://camo.githubusercontent.com/b7c44cefc2e4eeb8a2377eed6918fc6469ce6ce2b7d573ed1cfb8e2e24a9f025/68747470733a2f2f7472617669732d63692e6f72672f6f726b65737472612f4f726b657374726150646642756e646c652e706e673f6272616e63683d646576656c6f70)](https://travis-ci.org/orkestra/OrkestraPdfBundle)

Abstracts different PDF generation libraries. Currently supports TCPDF, Zend PDF and wkhtmltopdf.

This bundle is under active development and is prone to backwards compatibility breaks.

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

[](#installation)

Using composer, in your project's root directory:

```
composer require "orkestra/pdf-bundle 1.0.x-dev"

```

Update AppKernel.

```
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Orkestra\Bundle\PdfBundle\OrkestraPdfBundle(),
        // ...
    );
}

```

In addition, you should add [TCPDF](http://www.tcpdf.org/docs.php) or [Zend PDF](https://github.com/zendframework/ZendPdf) to your project, as necessary.

If planning to use [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/), ensure it is installed on your system.

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

[](#configuration)

No configuration is necessary, unless you want to change default settings.

Configuration defaults reference:

```
# config.yml
orkestra_pdf:

  # Main cache directory
  cache_dir:  %kernel.cache_dir%/orkestra_pdf

  tcpdf:
    # Path to the tcpdf installation
    root_dir:   %kernel.root_dir%/../vendor/tecnick.com/tcpdf

    # Path to tcpdf fonts
    fonts_dir:  %kernel.root_dir%/../vendor/tecnick.com/tcpdf/fonts

    # Path to tcpdf images
    image_dir:  %kernel.root_dir%/../vendor/tecnick.com/tcpdf/images

  wkhtmltopdf:
    # Path to the wkhtmltopdf binary
    binary_path:  wkhtmltopdf
```

Usage
-----

[](#usage)

This bundle's aim is to provide a uniform API for generating PDFs using different generation tools.

Currently supported: TCPDF, Zend PDF, and wkhtmltopdf.

### Generators

[](#generators)

The basis of this bundle revolves around services called "Generators". Generators know how to take some input, such as entities and other data, and return a PDF ready to be used. Generators encapsulate library-specific logic, returning a subtype of `Orkestra\Bundle\PdfBundle\Pdf\PdfInterface` which can then be used to send the generated PDF to the browser, save it to the filesystem, etc.

All Generators should implement `PdfGeneratorInterface`. Additionally, a base class called `AbstractPdfGenerator` is included. This document details how to extend `AbstractPdfGenerator`

#### Creating an Invoice Generator

[](#creating-an-invoice-generator)

The two main methods to implement are: `doGenerate` and `setDefaultParameters`.

##### Implementing the `doGenerate` method

[](#implementing-the--dogenerate-method)

This method actually performs the PDF generation. It takes two parameters, `$parameters` and `$options`.

- `$parameters` is an array of data to be sent to the templating engine.
- `$options` is an array of options to pass to the underlying PDF library.

##### Implementing the `setDefaultParameters` method

[](#implementing-the-setdefaultparameters-method)

This method configures an `OptionsResolver` and allows specification of required and available parameters that the Generator supports.

NOTE: There's also a `setDefaultOptions` method available. Parameters are intended to be passed to the templating engine, things like entities and collections. Options are intended to allow configuration of the generator at runtime.

##### Example implementation: InvoiceGenerator

[](#example-implementation-invoicegenerator)

In this example, we use the WkPdf adapter and the built in templating engine to render a PDF.

```
