Modern PHP library for PDF generation.

Maintainers

Package info

github.com/dragonofmercy/php-pdf

pkg:composer/dragonofmercy/phppdf

Statistics

Installs: 36

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.10.0 2026-06-12 10:05 UTC

This package is auto-updated.

Last update: 2026-06-12 14:23:40 UTC


README

phppdf - modern PHP 8.4 library for PDF generation

phppdf

CI Latest Version Total Downloads PHP Version License

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.0). The public API follows semantic versioning; breaking changes are reserved for the next major version. See CHANGELOG.md.

What works today

A quick tour - each feature has a full guide in the wiki.

Create

  • ๐Ÿ“„ Documents - 19 standard sizes (ISO A0-A7, B4 / B5, C-series envelopes, Letter / Legal / Tabloid / Executive / Half-Letter) plus custom sizes, portrait or landscape, multi-page, metadata, AES-256 password protection, viewer hints.
  • ๐Ÿ“ Coordinates - millimetres by default (origin top-left), or PDF points via Unit::PT.
  • โœ๏ธ Graphics - lines, rectangles, circles, paths, fill / stroke, dashes, caps / joins, transforms.
  • ๐Ÿ”ค Text - the 12 standard fonts, multi-line, configurable leading, full Western Latin, exact width measurement.
  • ๐Ÿ”ก Custom fonts - register TrueType / OpenType families with full Unicode (Latin / Greek / Cyrillic / CJK), selectable text, automatic glyph subsetting.
  • ๐Ÿ“ฆ Cells - text boxes with borders, fill, padding, alignment (left / center / right / justify), word-wrap, three width-fit modes.
  • ๐Ÿ–ผ๏ธ Images - JPEG and PNG (all color types, transparency), embedded once and placed anywhere.
  • ๐ŸŽจ SVG - fully vector: shapes, paths, gradients, patterns, clipping, masks, CSS styling, selectable <text> / <textPath>, pure-PHP <filter>.
  • ๐Ÿ”ข Barcodes & QR - 1D (EAN-13 / 8, Code 128 / 39 / 93, UPC-A, ITF) and 2D (QR, Aztec, DataMatrix, PDF417), pure-PHP and vector.
  • ๐Ÿ“ Markdown - a CommonMark core subset, flowing with automatic page breaks or inside an auto-sized cell, styleable via MarkdownStyle.
  • ๐Ÿ“Š Tables - data grids via Page::table(): fixed or fill columns, repeated headers, zebra striping, borders, per-cell styling, column spanning, grouped headers.
  • ๐Ÿงฑ Multi-column layout - flow cell() and markdown() across equal-width columns with $page->columns(...).
  • ๐Ÿ”– Bookmarks & hyperlinks - a nested table-of-contents sidebar and clickable URL / page areas.
  • ๐Ÿงพ Interactive forms - text fields, checkboxes, radios, dropdowns, listboxes, buttons, with per-field styling, JavaScript actions, and field linking.
  • โœ๏ธ Digital signatures - real PKCS#7 / CMS via Document::sign(), RFC 3161 timestamps, multiple signers, PAdES B-B / B-T, and LTV building blocks.

Right-to-left & accessibility

  • ๐Ÿ” Right-to-left text - Unicode bidi reordering (UAX #9) plus Arabic cursive shaping (contextual forms + lam-alef ligatures) on cells, tables, and Markdown; per-document, per-cell, or per-block direction.
  • ๐Ÿ—„๏ธ PDF/A archival - PDF/A-1 (PDF 1.4-based, levels 1b / 1a, transparency rejected), PDF/A-2, PDF/A-3 (levels b / u / a), and PDF 2.0-based PDF/A-4 (+ A-4f) with one enablePdfA() call, veraPDF-validated; A-3 / A-4f embed Factur-X / ZUGFeRD e-invoices.
  • โ™ฟ Tagged PDF & PDF/UA-1 - opt-in tagging via enableTagging(); enablePdfUA() produces veraPDF-validated PDF/UA-1 with artifacts, figure alt text, table header scopes, and tagged hyperlinks.

Read & modify existing PDFs

  • ๐Ÿ“– Reading - PdfReader parses PDFs including encrypted ones (RC4 40/128-bit, AES-128, AES-256); pass an optional password or omit it for permissions-only encryption. Classic xref tables, cross-reference streams, incremental revisions, object streams, and common filters.
  • ๐Ÿงฉ Template import (FPDI-style) - Document::importPdf() + Page::template() stamp any source page as a background or overlay: letterheads, watermarks, scanned-form fills. Encrypted source PDFs are supported (optional password).
  • ๐Ÿ”ง Modifying - PdfEditor::open() writes appended incremental revisions (metadata, new pages, signatures, timestamps, LTV), leaving the original bytes - and their signatures - byte-for-byte intact. Editing encrypted PDFs is supported: pass an optional password to open() / fromBytes() and the appended revision is re-encrypted with the source scheme (RC4 / AES-128 / AES-256); signing an encrypted PDF is not yet supported.
  • ๐Ÿ–‹๏ธ Filling AcroForm fields - inspect and setField() text / checkbox / radio / combobox / listbox values; each filled field gets a generated appearance stream (/AP). flattenFields() then freezes filled forms into static page content (all fields or a named subset); signature and push-button fields are preserved, and encrypted sources are supported.

Installation

composer require dragonofmercy/phppdf

Quick start

use 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.

Documentation

Full usage documentation lives in the wiki:

Development

The library source lives under build/. To get started:

git clone https://github.com/dragonofmercy/php-pdf.git
cd php-pdf/build
composer install
composer check   # PHPStan (level max) + PHPUnit

See the Contributing wiki page for coding conventions, golden fixture workflow, and how to add new features.

License

MIT - see LICENSE.

Support

If this project helps to increase your productivity, you can give me a cup of coffee :)

Donate