PHPackages                             prolix/knp-snappy-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. prolix/knp-snappy-bundle

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

prolix/knp-snappy-bundle
========================

Easily create PDF and images in Symfony2 by converting Twig/HTML templates.

v1.6.1(6y ago)0453MITPHPPHP &gt;=7.1

Since Jan 16Pushed 6y agoCompare

[ Source](https://github.com/prolixtechnikos/KnpSnappyBundle)[ Packagist](https://packagist.org/packages/prolix/knp-snappy-bundle)[ Docs](http://github.com/KnpLabs/KnpSnappyBundle)[ RSS](/packages/prolix-knp-snappy-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (10)Versions (14)Used By (0)

KnpSnappyBundle
===============

[](#knpsnappybundle)

[![Build Status](https://camo.githubusercontent.com/188371a3924255073f6086e3d6f289cc94f1607838dab12a137ec284bfafb148/68747470733a2f2f7472617669732d63692e6f72672f4b6e704c6162732f4b6e70536e6170707942756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/KnpLabs/KnpSnappyBundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/727acc2fc5ed600784fd34fef975531c36cfcce1ea21013a9da06259afa375d7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4b6e704c6162732f4b6e70536e6170707942756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/KnpLabs/KnpSnappyBundle/?branch=master)[![StyleCI](https://camo.githubusercontent.com/1ad9998b35da3edaadfbbc0f45e07eb2d043fe3f321d417c0214622389867ee6/68747470733a2f2f7374796c6563692e696f2f7265706f732f3734333231382f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/743218)[![knpbundles.com](https://camo.githubusercontent.com/24093054843a17c57fb00b2ec9e79706777d4f3376729f8f3cec24d6dfdfe0fc/687474703a2f2f6b6e7062756e646c65732e636f6d2f4b6e704c6162732f4b6e70536e6170707942756e646c652f62616467652d73686f7274)](http://knpbundles.com/KnpLabs/KnpSnappyBundle)

[Snappy](https://github.com/KnpLabs/snappy) is a PHP (5.6+) wrapper for the [wkhtmltopdf](http://wkhtmltopdf.org) conversion utility. It allows you to generate either pdf or image files from your html documents, using the webkit engine.

The KnpSnappyBundle provides a simple integration for your Symfony project.

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

[](#installation)

With [composer](https://getcomposer.org), require:

`composer require knplabs/knp-snappy-bundle`

Then enable it in your kernel (optional if you are using the Flex recipe with Symfony4) :

```
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        //...
        new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
        //...
```

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

[](#configuration)

If you need to change the binaries, change the instance options or even disable one or both services, you can do it through the configuration.

```
# app/config/config.yml (or config/packages/knp_snappy.yaml if using Symfony4 and the Flex recipe)
knp_snappy:
    pdf:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltopdf #"\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\"" for Windows users
        options:    []
    image:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltoimage #"\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe\"" for Windows users
        options:    []
```

If you want to change temporary folder which is `sys_get_temp_dir()` by default, you can use

```
# app/config/config.yml (or config/packages/knp_snappy.yaml if using Symfony4 and the Flex recipe)
knp_snappy:
    temporary_folder: "%kernel.cache_dir%/snappy"
```

You can also configure the timeout used by the generators with `process_timeout`:

```
# app/config/config.yml (or config/packages/knp_snappy.yaml if using Symfony4 and the Flex recipe)
knp_snappy:
    process_timeout: 20 # In seconds
```

Usage
-----

[](#usage)

The bundle registers two services:

- the `knp_snappy.image` service allows you to generate images;
- the `knp_snappy.pdf` service allows you to generate pdf files.

### Generate an image from a URL

[](#generate-an-image-from-a-url)

```
$container->get('knp_snappy.image')->generate('http://www.google.fr', '/path/to/the/image.jpg');
```

### Generate a pdf document from a URL

[](#generate-a-pdf-document-from-a-url)

```
$container->get('knp_snappy.pdf')->generate('http://www.google.fr', '/path/to/the/file.pdf');
```

### Generate a pdf document from multiple URLs

[](#generate-a-pdf-document-from-multiple-urls)

```
$container->get('knp_snappy.pdf')->generate(array('http://www.google.fr', 'http://www.knplabs.com', 'http://www.google.com'), '/path/to/the/file.pdf');
```

### Generate a pdf document from a twig view

[](#generate-a-pdf-document-from-a-twig-view)

```
$this->get('knp_snappy.pdf')->generateFromHtml(
    $this->renderView(
        'MyBundle:Foo:bar.html.twig',
        array(
            'some'  => $vars
        )
    ),
    '/path/to/the/file.pdf'
);
```

### Render an image as response from a controller

[](#render-an-image-as-response-from-a-controller)

```
use Knp\Bundle\SnappyBundle\Snappy\Response\JpegResponse;

class SomeController
{
    public function imageAction()
    {
        $html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
            'some'  => $vars
        ));

        return new JpegResponse(
            $this->get('knp_snappy.image')->getOutputFromHtml($html),
            'image.jpg'
        );
    }
}
```

### Render a pdf document as response from a controller

[](#render-a-pdf-document-as-response-from-a-controller)

```
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;

class SomeController extends Controller
{
    public function pdfAction()
    {
        $html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
            'some'  => $vars
        ));

        return new PdfResponse(
            $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
            'file.pdf'
        );
    }
}
```

### Render a pdf document with a relative url inside like css files

[](#render-a-pdf-document-with-a-relative-url-inside-like-css-files)

```
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;

class SomeController extends Controller
{
    public function pdfAction()
    {
        $pageUrl = $this->generateUrl('homepage', array(), true); // use absolute path!

        return new PdfResponse(
            $this->get('knp_snappy.pdf')->getOutput($pageUrl),
            'file.pdf'
        );
    }
}
```

Maintainers
-----------

[](#maintainers)

KNPLabs is looking for maintainers ([see why](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance)).

If you are interested, feel free to open a PR to ask to be added as a maintainer.

We’ll be glad to hear from you :)

Credits
-------

[](#credits)

SnappyBundle and [Snappy](https://github.com/KnpLabs/snappy) are based on the awesome [wkhtmltopdf](http://wkhtmltopdf.org). SnappyBundle has been developed by [KnpLabs](http://www.knplabs.com).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor4

4 contributors hold 50%+ of commits

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 ~288 days

Recently: every ~204 days

Total

10

Last Release

2340d ago

PHP version history (3 changes)v1.0PHP &gt;=5.3.2

v1.5PHP &gt;=5.6

v1.6.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f7ebbb7fd8d5bed650ff90bfa01d5c9962199a26d76f25439702a1ab92e4caf?d=identicon)[kuldippujara](/maintainers/kuldippujara)

---

Top Contributors

[![akovalyov](https://avatars.githubusercontent.com/u/2339101?v=4)](https://github.com/akovalyov "akovalyov (21 commits)")[![pilot](https://avatars.githubusercontent.com/u/28564?v=4)](https://github.com/pilot "pilot (14 commits)")[![mbontemps](https://avatars.githubusercontent.com/u/231249?v=4)](https://github.com/mbontemps "mbontemps (12 commits)")[![Herzult](https://avatars.githubusercontent.com/u/177588?v=4)](https://github.com/Herzult "Herzult (7 commits)")[![wouterj](https://avatars.githubusercontent.com/u/749025?v=4)](https://github.com/wouterj "wouterj (6 commits)")[![akerouanton](https://avatars.githubusercontent.com/u/557933?v=4)](https://github.com/akerouanton "akerouanton (6 commits)")[![seangofus](https://avatars.githubusercontent.com/u/1251177?v=4)](https://github.com/seangofus "seangofus (4 commits)")[![jzawadzki](https://avatars.githubusercontent.com/u/1220891?v=4)](https://github.com/jzawadzki "jzawadzki (3 commits)")[![docteurklein](https://avatars.githubusercontent.com/u/109846?v=4)](https://github.com/docteurklein "docteurklein (3 commits)")[![flug](https://avatars.githubusercontent.com/u/1810304?v=4)](https://github.com/flug "flug (2 commits)")[![jvasseur](https://avatars.githubusercontent.com/u/849295?v=4)](https://github.com/jvasseur "jvasseur (2 commits)")[![l3pp4rd](https://avatars.githubusercontent.com/u/132389?v=4)](https://github.com/l3pp4rd "l3pp4rd (2 commits)")[![lwagner](https://avatars.githubusercontent.com/u/231428?v=4)](https://github.com/lwagner "lwagner (2 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (2 commits)")[![alexpozzi](https://avatars.githubusercontent.com/u/8307861?v=4)](https://github.com/alexpozzi "alexpozzi (2 commits)")[![R2c](https://avatars.githubusercontent.com/u/2004449?v=4)](https://github.com/R2c "R2c (2 commits)")[![soullivaneuh](https://avatars.githubusercontent.com/u/1698357?v=4)](https://github.com/soullivaneuh "soullivaneuh (2 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (2 commits)")[![emelendez89](https://avatars.githubusercontent.com/u/1562673?v=4)](https://github.com/emelendez89 "emelendez89 (1 commits)")[![piotrantosik](https://avatars.githubusercontent.com/u/154553?v=4)](https://github.com/piotrantosik "piotrantosik (1 commits)")

---

Tags

bundleknpknplabspdfsnappy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/prolix-knp-snappy-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/prolix-knp-snappy-bundle/health.svg)](https://phpackages.com/packages/prolix-knp-snappy-bundle)
```

###  Alternatives

[knplabs/knp-snappy-bundle

Easily create PDF and images in Symfony by converting Twig/HTML templates.

1.2k31.8M49](/packages/knplabs-knp-snappy-bundle)[knplabs/knp-snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.

4.5k68.3M56](/packages/knplabs-knp-snappy)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

54882.8k1](/packages/nucleos-dompdf-bundle)[spraed/pdf-generator-bundle

This bundle creates (multiple) PDFs in Symfony from Twig/HTML templates.

52516.3k](/packages/spraed-pdf-generator-bundle)

PHPackages © 2026

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