knplabs/knp-snappy

A PHP library for generating PDFs, thumbnails, and snapshots from URLs or HTML pages.

Library
Composer
vv1.7.3
4,476stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity56
Maintenance40
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality82
Innovation64
Learning Curve82

Snappy is a PHP library that turns URLs or raw HTML into PDF documents and image snapshots. It is a thin, ergonomic wrapper around the webkit-based wkhtmltopdf and wkhtmltoimage binaries, handling process invocation, option passing, and output management so you can generate documents with a few method calls.

Because rendering is delegated to wkhtmltox, Snappy produces high-fidelity output that closely matches how a browser would render the page, including CSS and images. It integrates cleanly with Symfony, Laravel, and Laminas via community bundles, making it a common choice for invoice, report, and thumbnail generation in PHP applications.

What You Get

  • A Pdf generator that renders URLs or HTML into PDF documents
  • An Image generator for thumbnails and page snapshots
  • A clean option API mapping to wkhtmltopdf/wkhtmltoimage flags
  • Helpers to output to a file or return the binary content directly
  • Framework integrations for Symfony, Laravel, and Laminas via community bundles

Common Use Cases

  • Generating invoices, reports, and receipts as PDFs from HTML templates
  • Producing thumbnail images or snapshots of web pages
  • Rendering server-side HTML into downloadable documents in web apps
  • Batch-converting URLs into PDFs or images from PHP scripts

Under The Hood

Architecture - The library centers on an AbstractGenerator implementing a shared GeneratorInterface, with concrete Pdf and Image subclasses under src/Knp/Snappy. The abstract base assembles the command line from the binary path plus an options array, writes temporary input when given raw HTML, and runs the process, while dedicated exception classes handle error conditions like an existing output file.

Tech Stack - PHP 8.1+ depending on symfony/process to spawn and manage the external wkhtmltox binaries and psr/log for logging. The heavy lifting of rendering is done entirely by the external wkhtmltopdf/wkhtmltoimage executables, which must be installed separately.

Code Quality - The project is mature and actively maintained, using PHPUnit for tests, PHPStan for static analysis, and php-cs-fixer for style, with CI across GitHub Actions and AppVeyor. A clear interface/abstract-class/exception separation and a security-conscious README reflect a well-kept codebase.

API Design - The API is intentionally minimal: $pdf->generateFromHtml($html, $output) or $pdf->getOutputFromHtml($html) cover most needs, and options are passed as a plain array mirroring wkhtmltox flags. The main learning curve comes from understanding wkhtmltopdf’s own options and installing the binary, not from Snappy itself, keeping the wrapper approachable.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search