Authoring · PHP
Generate a PDF in PHP
Create PDFs programmatically from PHP: pages, vector graphics, embedded and subset fonts with full Unicode shaping, justified paragraphs, tables and images. rust-pdf gives PHP a fast, memory-safe core with deterministic output.
Last updated: 2026-06-29
Why PHP needs this
Most server-side PDF in PHP is built by gluing TCPDF or FPDF to a templating layer, or by shelling out to wkhtmltopdf, each with its own gaps in Unicode shaping, font embedding and reproducibility.
rust-pdf gives PHP a single memory-safe core for authoring: vector graphics, JPEG and PNG images, embedded and subset fonts with HarfBuzz-quality shaping and kerning, wrapping and justified paragraphs, tables, links and bookmarks. Identical input yields identical bytes, which makes the output auditable and testable.
Generation is the free tier: composer require rust-pdf/rustpdf, enable ffi in php.ini, and call the API from a controller, a Symfony command or an Artisan job. There is no separate rendering service to deploy and scale. The only constraint is shared hosting that forbids the FFI extension.
- Vector graphics, embedded and subset fonts, HarfBuzz-quality Unicode shaping and kerning.
- Wrapping and justified paragraphs, tables, images (JPEG, PNG, alpha, 16-bit).
- Deterministic output: identical bytes for identical input, ideal for audits and tests.
Generate a PDF in PHP with rust-pdf
Install via Composer, then call the same idiomatic API every rust-pdf binding shares. The authoring snippet below is real PHP from the reference docs.
composer require rust-pdf/rustpdf
<?php
require 'vendor/autoload.php';
use RustPdf\Document;
$doc = new Document(); // A4 by default
$doc->addPage()
->setFillRgb(0.86, 0.20, 0.18)
->rect(72, 640, 200, 120) // x, y, width, height (points)
->fill()
->save('out.pdf');
Authoring is part of the free PHP tier. No license token required.
The complete authoring API is in the PHP documentation.
Generation in PHP: FAQ
Is generating PDFs free in PHP?
Yes. All basic generation (pages, graphics, fonts, text, paragraphs, images, links, bookmarks, watermarks) is free forever. You only license corporate features such as PDF/A, signatures and encryption when you ship them.
Does it support Unicode and custom fonts?
Yes. Fonts are embedded and subset with HarfBuzz-quality shaping and kerning, using Type0 fonts with ToUnicode, so non-Latin scripts render and extract correctly.
Why a Rust core for PHP?
One memory-safe, high-performance Rust core is exposed to PHP through a thin idiomatic binding. You get the same engine, the same features and deterministic output, without a heavy runtime.
Do I need the FFI extension, and does this run on shared hosting?
rust-pdf bridges to its Rust core through PHP's ext-ffi, so you set ffi.enable=true in php.ini and ship the platform cdylib next to your app. That works on any VPS, container or Laravel Forge server you control; the exception is most shared-hosting plans, which forbid the FFI extension outright.
Start building documents in your PHP app today
One Rust core, deterministic output in every language. Authoring is free forever; you license only the corporate features such as PDF/A, signing and encryption.