Skip to content

Why we built a PDF 2.0 engine for modern PHP

PHP has had PDF libraries for twenty years. NextPDF combines PDF 2.0 output, tagged accessibility, and PAdES signatures in one in-process, strictly typed engine. It produces the requested result or returns a typed failure.

PHP has had PDF libraries for two decades. They render invoices and reports across the web. Why build another?

NextPDF is a single, in-process engine for PHP 8.4. It targets PDF 2.0 (ISO 32000-2), tagged structure for accessibility, and modern digital-signature profiles tied to regulation. Its named targets use the PDF 2.0 generation and current accessibility and signature profiles.

One rule shapes every line of the engine.

The one rule: typed output boundaries

A PDF is a precise, byte-level format. A reader either parses the output or rejects it. Wrong offsets and fabricated cross-reference positions can remain hidden until a validator or archival system reads the file months later.

NextPDF’s founding principle is the opposite:

Produce output against the active profile; raise a typed error at its boundary.

In practice that looks like ordinary, readable code on the happy path:

render.php
use NextPDF\Core\Document;

$doc = Document::createStandalone();
$doc->addPage();
$doc->writeHtml($invoiceHtml);
$doc->save('invoice.pdf');

When an unsupported construct, malformed asset, or active profile prevents conformant output, the engine raises a specific, catchable exception with structured context rather than emitting a corrupt file:

fail-closed.php
use NextPDF\Exception\NextPdfException;

try {
$doc->writeHtml($untrustedHtml);
$doc->save($path);
} catch (NextPdfException $e) {
  // Every failure is a typed domain exception carrying context
  // for your logs / APM. File creation completes after a
  // successful render.
  $logger->error($e->getMessage(), $e->getContext());
throw $e;
}

The documented 3.x exception model lists fourteen typed domain exceptions. Each carries a getContext(): array payload for logging and observability. When a render fails, the exception identifies the construct and reason at the type level in a catch block.

The engine fails closed on untrusted input by default. Local asset reads can be confined to an allowlist of roots, outbound transports must be pinnable, and unsafe paths raise a typed error.

The wedge: three standards, one engine

NextPDF targets three standards in the same engine. Some regulated workflows increasingly require all three outputs:

  • PDF 2.0 (ISO 32000-2)—the current generation of the format. Run the output through qpdf and veraPDF to validate it.
  • Tagged accessibility (targeting PDF/UA)—documents that carry their semantics alongside their rendered content. The EU Accessibility Act makes accessibility a legal requirement for covered documents.
  • PAdES digital signatures—from baseline signatures in Core to long-term, archival-grade validation in the higher editions. In the EU these underpin eIDAS electronic signatures.

NextPDF output targets and supports conformance with these standards. Published samples and validator commands provide file-level evidence. Tax-authority acceptance, qualified-signature status, and regulatory outcomes are determined by the document data, certificates, and process.

In-process PHP architecture

NextPDF runs inside your PHP process. Your application calls the native renderer directly in the same process. The PDF call stays in the application tier, with these production characteristics:

  • It is worker-safe: an immutable Config, process-lifetime font and image registries, and a DocumentFactory built for long-running workers (Laravel Octane, Swoole, RoadRunner). Warm the fonts once at boot; produce disposable documents per request.
  • It is deterministic: given the same inputs, you get the same bytes—which is what makes golden-file testing and reproducible archival possible.
  • It is auditable: the Core is Apache-2.0 and statically analysed at PHPStan Level 10. You can read exactly what runs in your process.

Verify with published samples and validator commands

Every standards claim includes a downloadable PDF you can run through your own validator. The showcase contains real engine output, and the engineering quality is a number you can reproduce.

If you build documents that have to clear a validator, hold up in an audit, or stay readable for years, that is exactly the audience NextPDF was built for.