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.

Why PHP needs this

PHP's classic libraries (TCPDF, FPDF) predate modern PDF and have no real PDF/A, no PAdES signatures and no AES-256, while the commercial alternatives are costly.

Generation is the free foundation. Draw shapes, place shaped and kerned Unicode text, lay out wrapping paragraphs, embed JPEG and PNG images, and add links and bookmarks. Output is deterministic (the same input yields the same bytes), which makes it auditable and testable.

  • 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 the package, then call the same idiomatic API every rust-pdf binding shares. The snippet below is real PHP code from the reference docs.

PHP
<?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');
Validated by: qpdfmutool

This is part of the free tier in PHP. No license required.

Full PHP reference in the 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.

Generate a PDF in PHP

One Rust core, the same output across every language. Prototype for free, license the corporate features when you ship.