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

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

xeurun/knp-snappy-bundle
========================

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

v1.2(12y ago)094MITPHPPHP &gt;=5.3.2

Since Jan 16Pushed 10y agoCompare

[ Source](https://github.com/XeuRun/KnpSnappyBundle)[ Packagist](https://packagist.org/packages/xeurun/knp-snappy-bundle)[ Docs](http://github.com/KnpLabs/KnpSnappyBundle)[ RSS](/packages/xeurun-knp-snappy-bundle/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

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

[](#knpsnappybundle)

[Snappy](https://github.com/KnpLabs/snappy) is a PHP (5.3+) 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.

[![Build Status](https://camo.githubusercontent.com/9a729549bcf7b09370366e1caed0092a4cb2ee2bfa6b8bf3cddace8267e78d61/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f4b6e704c6162732f4b6e70536e6170707942756e646c652e706e67)](http://travis-ci.org/KnpLabs/KnpSnappyBundle)

[![knpbundles.com](https://camo.githubusercontent.com/24093054843a17c57fb00b2ec9e79706777d4f3376729f8f3cec24d6dfdfe0fc/687474703a2f2f6b6e7062756e646c65732e636f6d2f4b6e704c6162732f4b6e70536e6170707942756e646c652f62616467652d73686f7274)](http://knpbundles.com/KnpLabs/KnpSnappyBundle)

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

[](#installation)

With [composer](http://packagist.org), add:

```
{
    "require": {
        "xeurun/knp-snappy-bundle": "dev-master"
    }
}
```

Then enable it in your kernel:

```
// 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
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
knp_snappy:
    temporary_folder: %kernel.cache_dir%/snappy
```

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 an URL

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

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

### Generate a pdf document from an URL

[](#generate-a-pdf-document-from-an-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)

```
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
    'some'  => $vars
));

return new Response(
    $this->get('knp_snappy.image')->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'image/jpg',
        'Content-Disposition'   => 'filename="image.jpg"'
    )
);
```

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

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

```
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
    'some'  => $vars
));

return new Response(
    $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="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)

```
$pageUrl = $this->generateUrl('homepage', array(), true); // use absolute path!

return new Response(
    $this->get('knp_snappy.pdf')->getOutput($pageUrl),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )
);
```

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

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity63

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

Total

3

Last Release

4559d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b516baec3013d6ef22bd9f06c59f4d7a49dbd6562693878d7f6f051e7259272?d=identicon)[XeuRun](/maintainers/XeuRun)

---

Top Contributors

[![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)")[![akovalyov](https://avatars.githubusercontent.com/u/2339101?v=4)](https://github.com/akovalyov "akovalyov (6 commits)")[![seangofus](https://avatars.githubusercontent.com/u/1251177?v=4)](https://github.com/seangofus "seangofus (4 commits)")[![docteurklein](https://avatars.githubusercontent.com/u/109846?v=4)](https://github.com/docteurklein "docteurklein (3 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (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)")[![R2c](https://avatars.githubusercontent.com/u/2004449?v=4)](https://github.com/R2c "R2c (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)")[![devster](https://avatars.githubusercontent.com/u/1135083?v=4)](https://github.com/devster "devster (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![craue](https://avatars.githubusercontent.com/u/800119?v=4)](https://github.com/craue "craue (1 commits)")[![piotrantosik](https://avatars.githubusercontent.com/u/154553?v=4)](https://github.com/piotrantosik "piotrantosik (1 commits)")[![umpirsky](https://avatars.githubusercontent.com/u/208957?v=4)](https://github.com/umpirsky "umpirsky (1 commits)")[![andrewtch](https://avatars.githubusercontent.com/u/925330?v=4)](https://github.com/andrewtch "andrewtch (1 commits)")[![sstok](https://avatars.githubusercontent.com/u/904790?v=4)](https://github.com/sstok "sstok (1 commits)")[![xeurun](https://avatars.githubusercontent.com/u/1073935?v=4)](https://github.com/xeurun "xeurun (1 commits)")

---

Tags

bundleknpknplabspdfsnappy

### Embed Badge

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

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

###  Alternatives

[knplabs/knp-snappy-bundle

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

1.2k32.7M53](/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.5k71.0M59](/packages/knplabs-knp-snappy)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k26.0M51](/packages/barryvdh-laravel-snappy)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

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

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

51522.1k](/packages/spraed-pdf-generator-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)

PHPackages © 2026

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