-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Dragon edited this page Jun 8, 2026
·
5 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 - Standard page formats (A4, Letter, Legal, custom), 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. -
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. -
Right-to-left text - Unicode bidirectional reordering (UAX #9) for Hebrew and other RTL scripts on cells and tables. Set a document base direction with
setBaseDirection(), override per cell withdirection:, or per table cell withCell::direction();Direction::AUTOdetects the base from the text. An RTL base right-aligns by default. No page-coordinate flip - layout, images, and tables are unaffected. -
PDF/A archival conformance - ISO 19005-2 (PDF/A-2b, PDF/A-2u) and ISO 19005-3 (PDF/A-3b, PDF/A-3u) with one call (
$doc->enablePdfA(PdfALevel::A2B)). Attach associated files (e.g. Factur-X XML) for PDF/A-3. Validated against veraPDF. -
Tagged PDF (accessibility) - opt-in structure tagging with
$doc->enableTagging(). Cells, images, tables, and Markdown are tagged automatically into a logical structure tree (StructTreeRoot,MarkInfo, ParentTree, marked content), with an optional document language. Phase 1 toward PDF/UA; alternate text and full conformance come later.
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.