Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
PHP
branch: refactoring

This branch is 1 commit ahead, 125 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test/Knp/Snappy/Tests
.gitignore
.travis.yml
LICENSE
README.markdown
composer.json
phpunit.xml.dist

README.markdown

Snappy

Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage available on OSX, linux, windows.

You will have to download wkhtmltopdf 0.10.0 >= rc2 in order to use Snappy.

Build Status

Installation using Composer

Add to your composer.json:

{
    "require" :  {
        "knplabs/knp-snappy": "*"
    }
}

Usage

<?php

use Knp\Snappy\Pdf;

$snappy = new Pdf();

// By default Snappy uses path to binary: `/usr/local/bin/wkhtmltopdf`
// but you can change it in two ways
$snappy = new Pdf('/path/to/bin/wkhtmltopdf');
// Or
$snappy = new Pdf();
$snappy->setBinary('/path/to/bin/wkhtmltopdf');

// Display the resulting image in the browser
// by setting the Content-type header to jpg
$snappy = new Pdf();
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://www.github.com');

// .. or simply save the PDF to a file
$snappy = new Pdf();
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');

// Pass options to snappy
// Type wkhtmltopdf -H to see the list of options
$snappy = new Pdf();
$snappy->setOption('disable-javascript', true);
$snappy->setOption('no-background', true);
$snappy->setOption('allow', array('/path1', '/path2'));
$snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));

Credits

Snappy has been originally developed by the KnpLabs team.

Something went wrong with that request. Please try again.