PHPackages                             dragonofmercy/phppdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. dragonofmercy/phppdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

dragonofmercy/phppdf
====================

Modern PHP library for PDF generation.

v1.0.0(1w ago)027↓100%MITPHPPHP ^8.4CI passing

Since May 29Pushed 6d agoCompare

[ Source](https://github.com/dragonofmercy/php-pdf)[ Packagist](https://packagist.org/packages/dragonofmercy/phppdf)[ RSS](/packages/dragonofmercy-phppdf/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (5)Dependencies (3)Versions (2)Used By (0)

phppdf
======

[](#phppdf)

[![CI](https://camo.githubusercontent.com/7bd0dbe2a38e49ca526cbc637a32398e28c2ce72532dd7b33a816e1359e71a0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f647261676f6e6f666d657263792f7068702d7064662f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/dragonofmercy/php-pdf/actions/workflows/ci.yml)[![Latest Version](https://camo.githubusercontent.com/573bc5b8343787ccd4328ce501eb278828ad0e484618b1f7d7d628bd70ab4cfe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f647261676f6e6f666d657263792f7068707064662e737667)](https://packagist.org/packages/dragonofmercy/phppdf)[![Total Downloads](https://camo.githubusercontent.com/9c6761720587c9c69427005a307ff38ead2efc38fd6e402b22220496be445e6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647261676f6e6f666d657263792f7068707064662e737667)](https://packagist.org/packages/dragonofmercy/phppdf)[![PHP Version](https://camo.githubusercontent.com/ead6e783713d95a275cde3e708d87a69b9ccdb76ab421413532416765e8b1f19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f647261676f6e6f666d657263792f7068707064662e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/2ce0724dd9924f3d6c827a90de356a86c3fab7aab8793a72f152a4f8e8b89320/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f647261676f6e6f666d657263792f7068707064662e737667)](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](https://semver.org/); breaking changes are reserved for the next major version. See [CHANGELOG.md](CHANGELOG.md).

What works today
----------------

[](#what-works-today)

- **Documents** - A4 / Letter / Legal and many other standard formats, custom dimensions for labels, portrait or landscape, multi-page, metadata (title, author, dates), password protection (AES-256, PDF 2.0), and the usual viewer hints (initial zoom, page layout, bookmarks panel open on launch).
- **Coordinates** - millimetres by default, with the origin at the top-left of the page (Y axis pointing down). Switch to PDF points with `Unit::PT` if you prefer.
- **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 with `\n`, configurable leading. Western Latin scripts including accents and the typographic characters `EUR`, `oe`, `OE`, `%.` etc.
- **Custom TrueType / OpenType fonts** - register `.ttf` or `.otf` files for the document (regular / bold / italic / boldItalic variants) and use them like the built-in fonts. Full Unicode reach: Latin Extended, Greek, Cyrillic, CJK, etc. Copy-paste from the rendered PDF works correctly. Fonts are automatically subsetted to the glyphs used, so even multi-megabyte CJK families produce small PDFs.
- **Cells** - rectangles with text, borders (per-side, configurable width / color / style: solid / dashed / dotted), fill color, padding, text alignment (left / center / right \* top / middle / bottom), three width-fit modes (none / condense / shrink), automatic word-wrap, automatic force-break for words wider than the cell.
- **Text measurement** - `$page->stringWidth(...)` returns the exact width of any string in the current font.
- **Images** - JPEG and PNG (RGB / Gray / Palette / RGB+Alpha / Gray+Alpha) with transparency support. Auto-format detection. Same image used N times = one embed, N placements (per-document caching). Cursor flow via `NextPosition` (RIGHT / NEWLINE / BELOW / NONE) for sequential placement.
- **SVG vector images** - inline `` or `.svg` file, fully vector (infinite zoom). Shapes, paths (all commands including arcs), transforms, groups, `` references, `viewBox` + `preserveAspectRatio`, solid fills and strokes with opacity, dash patterns, 147 named CSS colors, linear and radial gradients (per-stop alpha and spreadMethod pad / reflect / repeat), `` tiling, `` clipping, `` luminance soft masks, `` / ``, `` CSS (with cascade), embedded raster `` (PNG / JPEG data URI), and `` / `` / `` rendered as real selectable text with the standard fonts or any registered custom TTF / OTF family (matched by `font-family`, with automatic glyph subsetting). `` is rendered via a hybrid pure-PHP raster (feGaussianBlur, feOffset, feFlood, feMerge, feBlend, feComposite, feColorMatrix, feDropShadow; resolution tunable via `Document::setSvgFilterResolution()`), with text in the filtered subtree kept sharp on top. Heavier filter primitives (feTurbulence, feDisplacementMap, lighting, etc.), scripts, and animations are skipped silently.
- **Barcodes &amp; QR codes** - EAN-13, EAN-8, Code 128 (auto A/B/C set switching), UPC-A, Code 39, Code 93, ITF (Interleaved 2 of 5), QR Code (V1-V40 full ISO 18004 range, all four error-correction levels), Aztec Code (ISO/IEC 24778, Compact 1-4 layers and Full Range 1-32 layers, four EC presets, auto UTF-8 ECI), DataMatrix (ISO/IEC 16022 ECC200 squares 10x10 to 144x144, auto UTF-8 ECI), PDF417 (ISO/IEC 15438 standard variant, auto UTF-8 ECI). Pure-PHP encoders, vector rendering, configurable color, optional human-readable text under 1D codes, and optional vertical rendering of any 1D code via `->vertical()`.
- **Bookmarks &amp; hyperlinks** - build a sidebar table of contents with nested sections (what PDF viewers show in their left panel) and place clickable areas anywhere on a page that open a URL or jump to another page in the same document. Declarative API.
- **Interactive forms** - the reader can type into the PDF before saving or printing it: text fields (single or multi-line, including password fields), checkboxes, radio buttons (grouped), dropdowns, listboxes, push buttons (resetForm, openUrl, and submit field data to a URL in FDF / HTML / XFDF / PDF format), and signature fields (visible or invisible) that can be left as placeholders or signed programmatically with a real PKCS#7 / CMS signature via `Document::sign()` and a PKCS#12 credential. Signatures can carry an RFC 3161 signature timestamp by passing a `Tsa` to `sign()` (`timestamp: Tsa::http('https://tsa.example/tsr')`), which embeds the Time Stamping Authority token as an unsigned attribute in the CMS for a trusted signing time independent of the signer's clock. (The default container is `adbe.pkcs7.detached`; pass `format: SignatureFormat::EtsiCadesDetached` to `sign()` / `addSignature()` for the strict PAdES profile - `/SubFilter /ETSI.CAdES.detached` with a CMS carrying the `signingCertificateV2` signed attribute, i.e. PAdES-B-B, or B-T with a `Tsa`. RSA keys.) A whole-document timestamp can be added as an incremental revision with `$doc->addDocumentTimestamp(Tsa::http($url))` (a `/DocTimeStamp`, `ETSI.RFC3161`), standalone or layered over a signature to attest the signed bytes; this is the building block toward PAdES-B-LT (LTV is a later phase). Several signers can each approve the same document: `$doc->addSignature($cred, reason: 'Reviewed')` adds an approval signature in its own incremental revision (so each signature covers all prior ones); chain `sign()` + N x `addSignature()` + an optional `addDocumentTimestamp()` for a fully layered file. Each field can be styled with border color and width, background color, text color, font, size, and alignment - plus per-field visibility flags (`hidden`, `noExport`) and advanced border styles (SOLID / DASHED / BEVELED / INSET / UNDERLINE via `FieldBorderStyle`). Text fields, comboboxes, listboxes, and checkboxes accept a `defaultValue` decoupled from their display `value`, restored by a ResetForm button. Page tab order is settable via `Page::setTabOrder(TabOrder::ROW | COLUMN | STRUCTURE)`. Text fields, comboboxes, and listboxes can carry JavaScript actions for auto-calculation (sum, product, average, min, max), display formatting (number, currency, percent, date, time), and input validation (range checks) - executed by Adobe Reader / Acrobat only. Document-level scripts run on open via `addDocumentScript`. Several fields sharing the same name are automatically linked - they emit as one logical field and stay synchronized in the reader (field linking).
- **Markdown** - render a CommonMark core subset (headings, paragraphs, bold / italic / inline code, links, images, ordered + unordered nested lists, fenced / indented code blocks, block quotes, thematic breaks) either flowing from the cursor with automatic page breaks via `Page::markdown()` or inside an auto-sized cell via `cell(markdown: true)`. Styling is configurable through `MarkdownStyle`.
- **Tables** - render data tables with `Page::table()`: fixed or `fill` column widths, automatic page-break with the header row repeated on each page (toggle via `TableStyle::withRepeatHeader()`), zebra striping, configurable borders (grid / horizontal rules / header underline / none), per-column alignment and padding, a conditional per-cell style callback, and cells holding either text or an image (e.g. avatars). Built on the existing cell/image pipeline.
- **PDF/A archival conformance** - emit ISO 19005-2 conformant files (PDF/A-2b and PDF/A-2u) with one call: `$doc->enablePdfA(PdfALevel::A2B)`. This embeds an sRGB output intent, stamps the XMP packet with the PDF/A identification schema, and always writes the document metadata and `/ID`. Every font must be embedded - register one with `registerFontFamily()`; using a non-embedded standard font (or encryption, or document JavaScript) throws. Validated against veraPDF, the ISO reference validator. PDF/A-3b and PDF/A-3u are also supported: call `$doc->attachFile($xmlBytes, 'factur-x.xml', AFRelationship::Data, 'text/xml')` to embed an associated file (e.g. a Factur-X / ZUGFeRD e-invoice XML). Attachments are rejected at PDF/A-2 (use A-3).

Installation
------------

[](#installation)

```
composer require dragonofmercy/phppdf
```

Quick start
-----------

[](#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
-------------

[](#documentation)

Full usage documentation lives in the [wiki](https://github.com/dragonofmercy/php-pdf/wiki):

- [Getting Started](https://github.com/dragonofmercy/php-pdf/wiki/Getting-Started)
- [Text and Fonts](https://github.com/dragonofmercy/php-pdf/wiki/Text-and-Fonts), [Cells](https://github.com/dragonofmercy/php-pdf/wiki/Cells), [Tables](https://github.com/dragonofmercy/php-pdf/wiki/Tables), [Graphics](https://github.com/dragonofmercy/php-pdf/wiki/Graphics), [Images](https://github.com/dragonofmercy/php-pdf/wiki/Images)
- [Barcodes and QR Codes](https://github.com/dragonofmercy/php-pdf/wiki/Barcodes-and-QR-Codes), [SVG Support](https://github.com/dragonofmercy/php-pdf/wiki/SVG-Support)
- [Markdown](https://github.com/dragonofmercy/php-pdf/wiki/Markdown), [Bookmarks and Hyperlinks](https://github.com/dragonofmercy/php-pdf/wiki/Bookmarks-and-Hyperlinks), [Viewer Preferences](https://github.com/dragonofmercy/php-pdf/wiki/Viewer-Preferences), [Metadata and Encryption](https://github.com/dragonofmercy/php-pdf/wiki/Metadata-and-Encryption)
- [Interactive Forms](https://github.com/dragonofmercy/php-pdf/wiki/Interactive-Forms), [Digital Signatures](https://github.com/dragonofmercy/php-pdf/wiki/Digital-Signatures), [PDF/A Conformance](https://github.com/dragonofmercy/php-pdf/wiki/PDF-A-Conformance)
- Internals and contributing: [Architecture](https://github.com/dragonofmercy/php-pdf/wiki/Internals-Architecture), [Contributing](https://github.com/dragonofmercy/php-pdf/wiki/Contributing)

Development
-----------

[](#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](https://github.com/dragonofmercy/php-pdf/wiki/Contributing) wiki page for coding conventions, golden fixture workflow, and how to add new features.

License
-------

[](#license)

MIT - see [LICENSE](LICENSE).

Support
-------

[](#support)

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

[![Donate](https://camo.githubusercontent.com/2df914a0101385fd5196ed05218772a0e5f8211fd309ee00367069b730a06b7d/68747470733a2f2f63646e2e6b6f2d66692e636f6d2f63646e2f6b6f6669322e706e673f763d33)](https://ko-fi.com/dragonofmercy)

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance98

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

11d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/196e1196b041461d3992389e5b7d2d6aa2d06fc7c3acaab9a2007b642d08fa2d?d=identicon)[dragonofmercy](/maintainers/dragonofmercy)

---

Top Contributors

[![dragonofmercy](https://avatars.githubusercontent.com/u/140013?v=4)](https://github.com/dragonofmercy "dragonofmercy (830 commits)")

---

Tags

lib-pdfpdfpdf-generatorphp-pdfpdfpdf-writerpdf-generation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dragonofmercy-phppdf/health.svg)

```
[![Health](https://phpackages.com/badges/dragonofmercy-phppdf/health.svg)](https://phpackages.com/packages/dragonofmercy-phppdf)
```

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k95.2M356](/packages/barryvdh-laravel-dompdf)[tecnickcom/tcpdf

Deprecated legacy PDF engine for PHP. For new projects use tecnickcom/tc-lib-pdf.

4.5k107.0M545](/packages/tecnickcom-tcpdf)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k81.2M538](/packages/mpdf-mpdf)[knplabs/knp-snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.

4.5k71.0M59](/packages/knplabs-knp-snappy)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.3k35.1M142](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k38.3M252](/packages/smalot-pdfparser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
