-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Dragon edited this page Jun 12, 2026
·
12 revisions
Modern PHP 8.4 library for PDF generation. Pure PHP, no external runtime dependencies beyond the standard mbstring, openssl, and zlib extensions.
Status: stable 1.x. The public API follows semantic versioning; breaking changes are reserved for the next major version.
- Documents - 19 standard page formats (ISO A0-A7, B4 / B5, C-series envelopes, Letter, Legal, Tabloid, Executive, Half-Letter) plus custom sizes, portrait or landscape, multi-page, metadata, password protection (AES-256, PDF 2.0), and viewer hints (initial zoom, page layout, bookmarks panel).
-
Coordinates - Millimetres by default, origin at top-left (Y axis pointing down). Switch to PDF points with
Unit::PT. - Graphics - Lines, rectangles, circles, paths, fill/stroke, dashed lines, line caps and joins, transforms (translate, rotate, scale), save/restore graphics state.
- Text - The 12 standard PDF fonts (Helvetica, Times, Courier in regular/bold/italic/bold-italic), multi-line text, configurable leading, Western Latin including accents and typographic characters.
-
Custom TrueType / OpenType fonts - Register
.ttfor.otffiles, full Unicode reach (Latin Extended, Greek, Cyrillic, CJK, etc.), copy-paste support, automatic glyph subsetting. - Cells - Rectangles with text, per-side borders (width, color, solid/dashed/dotted), fill color, padding, text alignment, width-fit modes, automatic word-wrap and force-break.
-
Text measurement -
$page->stringWidth(...)returns the exact width of any string in the current font. - Images - JPEG and PNG (RGB, Gray, Palette, with or without alpha) with transparency support; same image embedded once regardless of how many times it is placed.
-
SVG vector images - Inline
<svg>or.svgfile, fully vector. Full shape/path/transform support, gradients (linear, radial, per-stop alpha, spreadMethod),<pattern>tiling,<clipPath>,<mask>,<symbol>/<marker>, CSS<style>, raster<image>data URIs, and<text>/<tspan>/<textPath>as real selectable text.<filter>rendered via hybrid pure-PHP raster (8 primitives, resolution tunable). - Barcodes & QR codes - EAN-13, EAN-8, Code 128, UPC-A, Code 39, Code 93, ITF, QR Code, Aztec Code, DataMatrix, PDF417. Pure-PHP encoders, vector rendering, configurable color, optional human-readable text, optional vertical rendering for 1D codes.
- Bookmarks & hyperlinks - Nested bookmark tree and clickable link annotations (URL or in-document jump). Declarative API.
- Interactive forms - Text fields, checkboxes, radio buttons, dropdowns, listboxes, push buttons (reset, URL, submit in FDF/HTML/XFDF/PDF), and signature fields (placeholder or real PKCS#7/CMS signature). Per-field styling, visibility flags, tab order, field linking, and JavaScript actions (calculation, formatting, validation).
-
Digital signatures -
Document::sign()with a PKCS#12 credential; optional RFC 3161 timestamp (Tsa); multiple approval signatures viaaddSignature(); whole-document timestamp viaaddDocumentTimestamp(); PAdES-B-B / B-T / B-LT / B-LTA profiles; ETSI.CAdES.detached subfilter. Sign an existing PDF withPdfEditor::open()->sign()(full API parity, stacked incremental revisions, covers all prior edits). -
Markdown - CommonMark core subset rendered via
Page::markdown()(flowing, with automatic page breaks) orcell(markdown: true)(auto-sized cell). Configurable throughMarkdownStyle. -
Tables -
Page::table(): fixed orfillcolumn widths, automatic page-break with repeated header row, zebra striping, configurable borders, per-column alignment and padding, conditional per-cell style callback, text or image cells, column spanning (colSpan), and grouped headers. -
Right-to-left text - Unicode bidirectional reordering (UAX #9) for Hebrew, Arabic, and other RTL scripts on cells, tables, and Markdown. Set a base direction with
setBaseDirection(), override per cell (direction:), per table cell (Cell::direction()), or per Markdown block. Arabic cursive shaping is included: letters are joined using correct contextual forms and the four mandatory lam-alef ligatures. Markdown RTL right-aligns blocks and mirrors list markers and blockquote bars to the right side. -
Multi-column layout - Flow
cell()andmarkdown()across equal-width columns with$page->columns(...), filling each column before the next and continuing onto new pages. -
PDF/A archival conformance - ISO 19005-1 (PDF/A-1b, PDF/A-1a, PDF 1.4-based, transparency forbidden), ISO 19005-2 (PDF/A-2b, PDF/A-2u, PDF/A-2a), ISO 19005-3 (PDF/A-3b, PDF/A-3u, PDF/A-3a), and the PDF 2.0-based ISO 19005-4 (PDF/A-4, PDF/A-4f) with one call (
$doc->enablePdfA(PdfALevel::A1B)). Level A (PdfALevel::A1A/A2A/A3A) auto-enables tagging and requires a catalog language. Attach associated files (e.g. Factur-X XML) for PDF/A-3 or PDF/A-4f. PDF/A-4 emits a%PDF-2.0header and omits the/Infodictionary. CombiningenablePdfA(PdfALevel::A2A, 'en-US')withenablePdfUA('en-US')produces a single file that is both PDF/A-2a and PDF/UA-1. Validated against veraPDF. -
Tagged PDF & PDF/UA-1 accessibility - opt-in structure tagging via
enableTagging(): cells, images, tables, and Markdown are auto-tagged into a logical structure tree.enablePdfUA()produces output validated as PDF/UA-1 (veraPDFisCompliant): artifacts, figure alt text (image(alt: ...)), table header scope,DisplayDocTitle, XMPpdfuaid. Text hyperlinks (cell(link: ...)), Markdown inline links, and image hyperlinks are all tagged as accessible<Link>elements. -
Reading existing PDFs -
PdfReaderparses any PDF, including encrypted ones (RC4 40/128-bit, AES-128, AES-256); supply an optional password or omit it for permissions-only encryption. Exposes the object graph and page tree. See Reading Existing PDFs. -
Template import -
Document::importPdf()/importPdfBytes()parse an existing PDF (encrypted or not, with optional password);Page::template($tpl, $x, $y, $w, $h)draws any of its pages as an opaque background or stamp (letterheads, overlays, watermarking). Works with tagging and signatures. -
Modifying existing PDFs -
PdfEditor::open($path)(orPdfEditor::fromBytes()) opens an existing PDF (encrypted or not; optional password) and writes changes as an appended incremental revision: update metadata (setTitle/setAuthor/setSubject/setKeywords/setCreator), append new pages with the full page API (appendPage()), and fill AcroForm fields (formFields()/setField()). When the source is encrypted the revision is re-encrypted with the source scheme (RC4 / AES-128 / AES-256); signing an encrypted source is not yet supported. See Modifying Existing PDFs.
composer require dragonofmercy/phppdfuse DragonOfMercy\PhpPdf\Document;
$pdf = new Document();
$pdf->addPage();
$pdf->save('out.pdf');$pdf->output() returns the PDF bytes as a string instead of writing to disk - useful for streaming a response from a web controller.
Use the sidebar to navigate the full documentation. New users should start with Getting Started, which covers page setup, units, fonts, and the cell layout model.
MIT licensed. Source on GitHub - if phppdf helps you, you can buy me a coffee.