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

ActiveSymfony-bundle[PDF &amp; Document Generation](/categories/documents)

eckinox/pdf-bundle
==================

A Symfony bundle to generate PDFs from Twig templates.

v5.0.0(2y ago)94.5k↓80%1[1 issues](https://github.com/eckinox/pdf-bundle/issues)[1 PRs](https://github.com/eckinox/pdf-bundle/pulls)PHPPHP &gt;=8.1.10

Since Apr 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/eckinox/pdf-bundle)[ Packagist](https://packagist.org/packages/eckinox/pdf-bundle)[ RSS](/packages/eckinox-pdf-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (6)Versions (16)Used By (0)

Generate PDFs from Twig templates in Symfony
============================================

[](#generate-pdfs-from-twig-templates-in-symfony)

Generating PDFs in Symfony should be simple.
And now, it is!

With this bundle, you can just render your PDFs like you render your Twig templates.

Getting started
---------------

[](#getting-started)

### 1. Install Puppeteer

[](#1-install-puppeteer)

Before you proceed, make sure you have `node` and `npm` installed.

To install Puppeteer and its dependencies, we recommend you take a look at [Puppeteer's official installation guide](https://developers.google.com/web/tools/puppeteer/get-started)as well as their [official troubleshooting guide](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md).

Here is a snippet for Ubuntu (tested on 20.04) that works well at the time of writing:

```
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libappindicator3-1 libatk-bridge2.0-0 libgbm1
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /root/.cache/puppeteer/chrome
```

### 2. Install this package via Composer

[](#2-install-this-package-via-composer)

```
composer require eckinox/pdf-bundle
```

### 3. Configure the request context globally

[](#3-configure-the-request-context-globally)

The bundle needs to know the URL of your app to do some nifty stuff under the hood.
You must therefore define the request context for your app in your parameters.

To learn more about these parameters, check out [Symfony's console documentation](https://symfony.com/doc/4.1/console/request_context.html#configuring-the-request-context-globally).

```
# config/services.yaml
parameters:
    router.request_context.host: 'myapp.com'
    router.request_context.scheme: 'https'
    router.request_context.base_url: '/'
```

### 4. Start generating PDFs!

[](#4-start-generating-pdfs)

Here's a basic example to get you started.
For more complete examples and information, check out the documentation below.

```
