- What is nitmedia/wkhtml2pdf and what does it do?
- nitmedia/wkhtml2pdf is a Laravel wrapper around the wkhtmltopdf binary for converting HTML and Blade views into PDF files. It provides a service provider, facade, and configuration for the binary path and wkhtmltopdf options. You can generate, stream, or download PDFs and control settings such as page size and orientation.
- How do I install and configure nitmedia/wkhtml2pdf in Laravel?
- Install it via Composer, publish its configuration, and set the wkhtmltopdf binary path plus any default options. The host must have a compatible wkhtmltopdf executable available to PHP. After configuration, call the package facade from your Laravel code to render HTML or Blade output.
- Which Laravel and PHP versions does nitmedia/wkhtml2pdf support?
- Treat support as legacy: the package's last release was in 2017, and newer Laravel or PHP stacks may hit dependency, facade, or PHP compatibility issues. Check the package's Composer constraints and test against your exact Laravel and PHP versions before committing. Do not assume current Laravel support without validation.
- Can I render Blade views to PDF with this package?
- Yes, the package is intended to convert HTML and Blade views into PDFs. You pass the rendered HTML from a Blade view into the renderer, and wkhtmltopdf produces the PDF. Because rendering relies on the binary, external assets, fonts, and CSS/JS support depend on the wkhtmltopdf runtime.
- How do I stream or download a generated PDF?
- The facade exposes simple methods for generating, streaming, or downloading PDFs. Use streaming when you want the browser to display or fetch the PDF inline, and download when you need a file attachment response. Verify response behavior and headers in your Laravel version during testing.
- Is nitmedia/wkhtml2pdf safe for production use?
- Use it only as a contained legacy adapter, because the package is abandoned, the wkhtmltopdf engine is legacy, and user-controlled HTML or options can create security exposure. Pin the Composer package version and the binary version, run rendering in a controlled image, and avoid exposing the facade throughout business code. Queue renders, set timeouts and memory limits, and restrict local-file and network access as much as possible. Plan migration to a maintained renderer for customer-facing or high-volume flows.
- Can I run nitmedia/wkhtml2pdf in Docker, serverless, or shared hosting?
- The package needs a wkhtmltopdf binary that PHP can execute, so a controlled Docker image can work if you install the binary, fonts, shared libraries, and correct permissions. Serverless platforms and locked-down shared hosting are poor fits unless exec or proc_open and native binaries are explicitly validated. Test the deployment target before adoption.
- How does nitmedia/wkhtml2pdf perform at scale?
- Throughput is constrained by CPU and memory use per render plus the cost of spawning a process for each PDF. You should queue PDF generation, limit worker concurrency, set timeouts, and account for temp disk and font caches. It will not scale like pure PHP code and needs capacity planning.
- What are good alternatives to nitmedia/wkhtml2pdf for Laravel PDF generation?
- Maintained options include headless Chrome or Browsershot, Gotenberg, and hosted PDF APIs, depending on your rendering fidelity and operational needs. For Laravel, wrap any replacement behind an internal PdfRenderer interface so callers do not depend on the package facade. Compare modern CSS/JS support, accessibility or PDF/A needs, and hosting constraints before choosing.
- How should I migrate away from nitmedia/wkhtml2pdf?
- Start by inventorying every PDF flow, template, option, and binary dependency. Pin the package and wkhtmltopdf binary in a controlled image, introduce an internal renderer interface, and add golden-PDF or visual regression tests. Migrate low-risk flows first, then replace customer-facing or high-volume flows with a maintained option such as headless Chrome, Browsershot, Gotenberg, or a hosted API. Remove the old package and binary from the runtime when migration is complete.