Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Knp Snappy Laravel Package

knplabs/knp-snappy

PHP wrapper for wkhtmltopdf/wkhtmltoimage to generate PDFs and images (thumbnails, snapshots) from URLs or HTML. Simple API, configurable binaries and options, with integrations available for Symfony and Laravel.

View on GitHub
Deep Wiki
Context7

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Frequently asked questions about Knp Snappy
How do I install knp-snappy in a Laravel project?
Run `composer require knplabs/knp-snappy` for the core library, then install `barryvdh/laravel-snappy` for Laravel-specific integrations like Blade directives and Service Providers. Ensure wkhtmltopdf (v0.12.x) is installed system-wide or via Docker.
Which Laravel versions does knp-snappy support?
The package works with Laravel 5.5+ and 6.x/7.x/8.x/9.x via barryvdh/laravel-snappy. Check the [Laravel Snappy Bundle](https://github.com/barryvdh/laravel-snappy) for version-specific docs. Core knp-snappy supports PHP 7.4+.
Can I generate PDFs asynchronously in Laravel?
Yes. Use Laravel’s queue system with `barryvdh/laravel-snappy` to offload PDF generation to background jobs (e.g., `SnappyJob`). Pair with Laravel Horizon or database queues for scalability. Avoid blocking HTTP requests.
How do I configure wkhtmltopdf binary paths across environments?
Set the binary path in `config/snappy.php` (via `barryvdh/laravel-snappy`) or dynamically via `Pdf::setBinary()`. Use environment variables (e.g., `.env`) for flexibility. For Docker, mount the binary or use `h4cc/wkhtmltopdf-amd64` as a Composer dependency.
What security risks does wkhtmltopdf pose, and how do I mitigate them?
The `--enable-local-file-access` flag is a critical RCE risk. Disable it by default in your `snappy.php` config. Sanitize all user-provided HTML/URLs (e.g., with HTML Purifier) and use sandboxing (AppArmor/SELinux). For untrusted content, consider WeasyPrint or Puppeteer.
How do I handle failures if wkhtmltopdf crashes or times out?
Implement retry logic in your job or middleware. Use Laravel’s `try-catch` blocks to log failures via Monolog. For critical apps, add fallback mechanisms like cached HTML snapshots or alternative renderers (e.g., Dompdf for simple cases).
Can I generate thumbnails or snapshots from URLs in Laravel Blade?
Yes. With `barryvdh/laravel-snappy`, use Blade directives like `@image('https://example.com', 'thumbnail.jpg')` or `@pdf('https://example.com', 'invoice.pdf')`. Customize dimensions/options via the `snappy` config array.
What are the performance implications of wkhtmltopdf in production?
PDF generation is CPU/IO-intensive. Offload to queues to avoid timeouts. Monitor resource usage (e.g., memory limits) and set timeouts in `snappy.php`. For high-volume apps, consider pre-rendering static content or using serverless functions.
Are there alternatives to wkhtmltopdf for Laravel PDF generation?
Yes. For simpler PDFs, use Dompdf or Barryvdh’s Laravel Dompdf. For advanced CSS/JS rendering, consider Puppeteer (via `spatie/pdf-to-image`) or WeasyPrint. wkhtmltopdf excels for dynamic webkit-based outputs but requires binary management.
How do I test knp-snappy in Laravel CI/CD pipelines?
Mock wkhtmltopdf responses using `symfony/process` stubs or Docker containers with pre-installed binaries. Test Blade directives via `collect()` or `obStart()`. Use Laravel’s `HttpClient` to mock external URLs. Validate outputs with assertions (e.g., file existence, PDF metadata).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views