HTML and CSS to PDF for PHP and Laravel, without a browser
Fagus is a Composer package that turns HTML and CSS into PDF the way Chrome prints them. There is no Chrome, Puppeteer or Node to install, no Docker image and no system library: the rendering happens in a native engine written in Rust.
composer require nforst/fagususe Fagus\Fagus;
Fagus::html($html)->save('invoice.pdf');Status: early development. It renders real invoices and reports like Chrome prints them, but the CSS coverage is still growing, and releases before 1.0 may change the API.
Why Fagus
Simple
composer requireis all it takes, on Linux (x64 and arm64, glibc or musl, so Alpine too), macOS (Intel and Apple silicon) and Windows x64. Every platform prints the same PDF.Fast
A one-page invoice in about 2.5 ms once the worker runs, ten pages in about 17 ms, measured from PHP on an Apple M2 Pro (tagged PDF). The first document of a process takes about 9 ms. For one page that is 10 to 30 times faster than mPDF, Dompdf or a Chrome kept running.
Faithful
Modern CSS (flex, grid, Tailwind v4 included) renders the way it does in Chrome; page breaks, running headers, page counters and repeated table headers work the way print CSS specifies them.
Standards
PDF/A-3 with ZUGFeRD/Factur-X attachments and accessible PDF (PDF/UA) built in.
Safe
No network access, no files outside the directory you allow, no scripts; the engine has no
unsafecode of its own.
PHP and Laravel
The page size, margins, headers and footers come from @page rules in the document, the PDF's title from <title> and its language from <html lang>, as in a browser.
PHP
use Fagus\Conformance;
use Fagus\Fagus;
$pdf = Fagus::html($html)
->baseDirectory(__DIR__.'/resources/pdf') // relative URLs and the files they may read
->resource('logo.png', $logo) // data the document refers to
->pdfA(Conformance::PdfA3b)
->facturX($invoiceXml) // ZUGFeRD / Factur-X
->render();
$pdf->save('invoice.pdf');
$pdf->pages();
$pdf->diagnostics(); // CSS that was ignored, resources that are missing, with their position
Fagus::html($html)->accessible()->save('letter.pdf'); // PDF/UA-1Laravel, from a Blade view
use Fagus\Laravel\Facades\Fagus;
return Fagus::view('invoices.show', ['invoice' => $invoice])->name('invoice.pdf'); // inline
Fagus::view('invoices.show', $data)->download('invoice.pdf');
Fagus::view('invoices.show', $data)->pdfA('3b')->store('invoices/2026-0042.pdf', 's3');In Laravel 13 the same package registers itself (facade Fagus, Blade views, responses, disks).
Speed
Time per PDF of an invoice, the median of three runs in new processes on an Apple M2 Pro (macOS 27). First is the first PDF of a process, as in a PHP-FPM request (for Fagus it includes starting the worker, for Chrome kept running it does not include starting the browser); every other column is a further PDF in the same process, as in a queue worker or Octane. The invoice uses only CSS 2.1 (tables, no flex or grid) so that every engine lays it out.
| Engine | 1 page, first | 1 page | 10 pages | 40 pages |
|---|---|---|---|---|
| Fagus | 9 ms | 2.3 ms | 17 ms | 63 ms |
| Chrome 157, kept running (as in Gotenberg) | 103 ms | 75 ms | 122 ms | 217 ms |
| mPDF 8.3 | 63 ms | 25 ms | 233 ms¹ | 898 ms¹ |
| Dompdf 3.1 | 70 ms | 48 ms | 349 ms¹ | 2,550 ms¹ |
| WeasyPrint 66 | 158 ms | 105 ms | 668 ms | 2,596 ms |
| Browsershot 5.5 (a new Chrome per PDF) | 611 ms | 601 ms | 650 ms | 751 ms |
¹ Same content, other page breaks: Dompdf sets the 10 pages on 12 and the 40 on 44, mPDF (which ignores @font-face and uses its own font) on 8 and 31.
With modern CSS (the invoice of tools/gen.py: flex, grid, margin boxes with page numbers), which Dompdf and mPDF cannot lay out, Fagus takes 2.5 ms for one page and 17.5 ms for ten, Chrome 81 and 123 ms, WeasyPrint 134 and 715 ms. Chrome is measured from Node with Puppeteer; through Gotenberg an HTTP request comes on top. The scripts and documents are in bench/compare.
Compared with other renderers
Dompdf and mPDF stop at CSS 2 with some extensions, without flex or grid; Browsershot, Snappy and Gotenberg need a browser or a service. Fagus sits in between: a PHP package with the CSS of a browser.
| Feature | Fagus | Chrome (Browsershot, Gotenberg) | WeasyPrint | Dompdf | mPDF |
|---|---|---|---|---|---|
| Installs with | Composer (downloads one binary) | Node, Puppeteer and Chrome, or a service | Python and Pango | Composer | Composer |
| Licence | MIT or Apache-2.0 | MIT, BSD | BSD-3-Clause | LGPL-2.1 | GPL-2.0 |
| Flexbox, grid | yes | yes | yes² | no | no |
Headers and footers in @page margin boxes, "page 2 of 5" | yes | yes | yes | no³ | no³ |
HTML in headers and footers (position: running()), string-set | yes | no | yes | no | no |
Table of contents with page numbers (target-counter()) | yes | no | yes | no | no³ |
| Table headers repeated on every page | yes | yes | yes | yes | yes |
Hyphenation (hyphens: auto) | yes | yes | yes | no | yes |
Footnotes (float: footnote) | no | no | yes | no | no |
| JavaScript | no⁴ | yes | no | no | no |
| Bookmarks (PDF outline) | yes | with an option | yes | no | no³ |
| Tagged PDF, PDF/UA | yes | tagged only | with an option | no | no |
| PDF/A | 2b, 2u, 2a, 3b, 3u, 3a | no | yes | no | 1b, 3b |
| ZUGFeRD / Factur-X | built in | no | by hand | no | by hand |
| Same PDF on Linux, macOS and Windows | yes | depends on the fonts installed | depends on the fonts installed | yes | yes |
² WeasyPrint passes the simple cases tested here; its documentation calls flex layout partly supported. ³ mPDF has headers, footers, bookmarks and tables of contents through its own tags (<htmlpageheader>, <bookmark>, <tocpagebreak>), Dompdf page numbers through a PHP callback, not through CSS. ⁴ Fagus runs no scripts on purpose, so that a template cannot reach the network or the server; draw charts on the server instead, as inline SVG or images (with any PHP chart library).
The CSS rows are checked by rendering the documents in bench/compare/probes with every engine (bench/compare/run.sh); the other rows follow each project's documentation. Snappy and laravel-snappy use wkhtmltopdf, whose repository was archived in 2023 and whose WebKit dates from 2012; it is not measured.
Install
PHP 8.3 or newer. Composer asks whether to trust the plugin of nforst/fagus: it installs the fagus binary of the package's release after every composer install and composer update.
composer require nforst/fagus