PHPackages                             dmitrivereshchagin/yii-snappy - 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. dmitrivereshchagin/yii-snappy

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

dmitrivereshchagin/yii-snappy
=============================

Basic wrapper around Snappy implemented as Yii component

v1.0.0(10y ago)27.5k↓100%MITPHPPHP &gt;=5.3.0

Since Oct 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dmitrivereshchagin/yii-snappy)[ Packagist](https://packagist.org/packages/dmitrivereshchagin/yii-snappy)[ RSS](/packages/dmitrivereshchagin-yii-snappy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

yii-snappy
==========

[](#yii-snappy)

This is a basic wrapper around [Snappy](https://github.com/KnpLabs/snappy) implemented as [Yii](https://github.com/yiisoft/yii)application component. Snappy is a PHP library that uses [wkhtmltopdf and wkhtmltoimage](http://wkhtmltopdf.org) to render HTML into PDF and various image formats.

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

[](#installation)

Installation using [Composer](https://getcomposer.org) should be straightforward

```
% composer require dmitrivereshchagin/yii-snappy

```

To register components in your application add something like the following in configuration `components` section:

```
'pdf' => array(
    'class' => 'dmitrivereshchagin\\yii\\snappy\\PdfComponent',
    'binary' => '/usr/local/bin/wkhtmltopdf',
    'options' => array('orientation' => 'landscape'),
    'tempdir' => basename(__DIR__).'/runtime/pdf',
),
'image' => array(
    'class' => 'dmitrivereshchagin\\yii\\snappy\\ImageComponent',
    'binary' => '/usr/local/bin/wkhtmltoimage',
    'tempdir' => basename(__DIR__).'/runtime/image',
),
```

Specifying paths to binaries is mandatory. Optionally you can configure default command line arguments that can be overridden or adjusted later. It is also possible to set temporary directory for both components using `snappyTempdir` application parameter.

Usage
-----

[](#usage)

Use `Yii::app()->pdf` and `Yii::app()->image` to generate PDF documents and images respectively. These components provide access to methods declared by `\Knp\Snappy\GeneratorInterface`.

Here are some examples.

### Generate image from an URL

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

```
Yii::app()->image->generate('http://example.com', '/path/to/image.jpg');
```

### Generate PDF document from an URL

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

```
Yii::app()->pdf->generate('http://example.com', '/path/to/document.pdf');
```

### Generate PDF document from multiple URLs

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

```
Yii::app()->pdf->generate(
    array('http://example.com', 'http://example.org'),
    '/path/to/document.pdf'
);
```

### Generate PDF document from a view

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

```
Yii::app()->pdf->generateFromHtml(
    $this->render('view', array('name' => $value), $return = true),
    '/path/to/document.pdf'
);
```

### Generate PDF document as response from controller

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

```
$html = $this->render('view', array('name' => $value), $return = true);

Yii::app()->request->sendFile(
    'document.pdf',
    Yii::app()->pdf->getOutputFromHtml($html)
);
```

### Generate PDF document with relative URLs inside

[](#generate-pdf-document-with-relative-urls-inside)

```
$url = Yii::app()->createAbsoluteUrl('controller/action');

Yii::app()->request->sendFile(
    'document.pdf',
    Yii::app()->pdf->getOutput($url)
);
```

Credits
-------

[](#credits)

This code uses Snappy library. Snappy has been originally developed by [KnpLabs](http://knplabs.com) team.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~70 days

Total

3

Last Release

3716d ago

Major Versions

v0.2.0 → v1.0.02016-03-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b3882ea129b793a5f17988707c4cf3b9d92f43770266a73dae654838b150970?d=identicon)[dmitrivereshchagin](/maintainers/dmitrivereshchagin)

---

Top Contributors

[![dmitrivereshchagin](https://avatars.githubusercontent.com/u/14558877?v=4)](https://github.com/dmitrivereshchagin "dmitrivereshchagin (15 commits)")

---

Tags

pdfwkhtmltopdfsnappywkhtmltoimageyii

### Embed Badge

![Health badge](/badges/dmitrivereshchagin-yii-snappy/health.svg)

```
[![Health](https://phpackages.com/badges/dmitrivereshchagin-yii-snappy/health.svg)](https://phpackages.com/packages/dmitrivereshchagin-yii-snappy)
```

###  Alternatives

[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[mikehaertl/phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

1.6k20.0M44](/packages/mikehaertl-phpwkhtmltopdf)[knplabs/knp-snappy-bundle

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

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

MvlabsSnappy is a Zend Framework and Laminas module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

2453.6k](/packages/mvlabs-mvlabs-snappy)[luketowers/oc-snappypdf-plugin

SnappyPDF integration for OctoberCMS

121.1k](/packages/luketowers-oc-snappypdf-plugin)

PHPackages © 2026

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