knplabs/knp-snappy
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
psr/log | 3.0.0 | 6.77 kB | MIT | prod | |
symfony/process | v6.4.7 | - | MIT | prod |
KNPLabs' Snappy is a PHP library designed to facilitate the generation of thumbnails, snapshots, or PDFs from a URL or HTML page. The package operates as a wrapper around the powerful 'wkhtmltopdf' and 'wkhtmltoimage' utilities, renowned for their webkit-based conversion capabilities. To benefit from Snappy's functionalities, you'll need to have 'wkhtmltopdf' version '0.12.x' installed on your server. This is readily available to set up on various operating systems, such as OSX, Linux, and Windows.
The practical use of Snappy involves the following steps encapsulated in PHP code:
First, install it using composer with the command composer require knplabs/knp-snappy
.
Next, the package should be initialized in your script. Here's a snippet on how to do this:
<?php
require __DIR__ . '/vendor/autoload.php';
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
Various features of Knplabs' Snappy can then be exploited for different use-cases, such as displaying a PDF in a browser, downloading a PDF file directly from the browser, merging multiple URLs into one PDF, generating a local PDF file, or even customizing the options for your Snappy instance. Here's an example of generating a local PDF file from HTML:
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');
Remember to replace '/usr/local/bin/wkhtmltopdf'
with the actual path to your 'wkhtmltopdf' binary.
The Snappy documentation, inclusive of Frequently Asked Questions, is integrated into the project's readme as found at the GitHub URL 'https://github.com/KnpLabs/snappy.git'. The FAQ section specifically, is located in the 'doc/faq.md' directory. In addition to the main documentation, check out the provided integrations for other popular PHP frameworks like Symfony (knplabs/knp-snappy-bundle
), Laravel (barryvdh/laravel-snappy
), and Zend Framework (mvlabs/mvlabs-snappy
).