- Can I install pontedilana/weasyprint-bundle in a Laravel app?
- No. It is a Symfony bundle that ships a DependencyInjection extension, a Configuration tree, and autowired services meant to be registered in a Symfony kernel, so Laravel will not discover or boot it. In a Laravel codebase you would write a DIY adapter, not install the package. Treat the repo as a reference implementation rather than a Composer dependency.
- How do I install and configure WeasyPrintBundle in Symfony?
- Run composer require pontedilana/weasyprint-bundle, register the bundle in config/bundles.php, and configure the WeasyPrint binary path and options under the bundle's config key. The host must already have Python 3, WeasyPrint, and native libraries such as Pango, HarfBuzz, fontconfig, and GDK-Pixbuf installed. Inject the bundle's PDF service and pass rendered HTML or a Twig template to it. In tests, fake the process layer and assert on returned bytes instead of invoking WeasyPrint.
- What does WeasyPrintBundle actually do under the hood?
- It is a thin wrapper over the WeasyPrint Python CLI invoked through symfony/process. The typical flow is render a Twig template to HTML, write it to a temp file, shell out to the weasyprint binary, and return the PDF bytes. The real rendering capability lives in Python; the PHP layer is only wiring and configuration glue.
- What are the system requirements for WeasyPrint in a PHP project?
- You need Python 3, the weasyprint package, and native libraries including Pango, HarfBuzz, fontconfig, GDK-Pixbuf, and cffi/pydyf. These are OS-level and container-image concerns, not Composer concerns. Plan to own a Python base image, font packages, and CVE patching if you self-host.
- Does WeasyPrint execute JavaScript or render client-side charts?
- No, WeasyPrint has no JavaScript engine, so client-side-rendered charts, map tiles, and JS pagination libraries will not work. Generate charts server-side as SVG or images and embed them in the HTML. If you need pixel-faithful web-page capture, use a Chromium-based tool like spatie/browsershot or a hosted API instead.
- Is WeasyPrint good for invoices, reports, and PDF/A documents?
- Yes. WeasyPrint is built around CSS Paged Media, so @page rules, running headers and footers, page counters, and PDF/A or PDF/UA tagging are first-class. It is excellent for document-centric output such as invoices, statements, and compliance reports. It is weaker than Chromium for modern flexbox and grid-heavy layouts and web fonts fetched at runtime.
- How do I generate PDFs from HTML in Laravel without this bundle?
- Render a Blade view to an HTML string, write it to a temp file, and invoke the weasyprint CLI through symfony/process, which Laravel already depends on transitively. Return the process output as PDF bytes or store it and stream it later. Push long renders onto a queue and consider a managed PDF API at high volume.
- How does WeasyPrint compare to spatie/browsershot or wkhtmltopdf?
- Browsershot drives headless Chromium, so you get full JavaScript, modern CSS, and pixel-faithful web-page capture, at the cost of a heavy browser runtime. WeasyPrint is Python-based and Paged Media-first, with no JavaScript but strong print pagination and PDF/A support. wkhtmltopdf is legacy and generally not recommended for new projects.
- Is it safe to render user-controlled HTML with WeasyPrint?
- Not by default. WeasyPrint resolves external url() references in HTML and CSS, which creates SSRF and remote-fetch stall risks when templates include user content. Run renders with egress disabled or a restricted URL fetcher, sanitize or template user data, and do not let users supply raw CSS with external imports.
- Is pontedilana/weasyprint-bundle actively maintained and production-ready?
- It has around 40 stars, zero dependents, and a single maintainer, so it is effectively bus-factor-one glue code. That is acceptable as a reference implementation but risky as a critical-path dependency. Pin the bundle and the WeasyPrint binary together, because CLI flags and CSS support change across WeasyPrint majors, and consider a managed API or your own thin wrapper for production.