dragonofmercy/phppdf
最新稳定版本:v1.7.0
Composer 安装命令:
composer require dragonofmercy/phppdf
包简介
Modern PHP library for PDF generation.
README 文档
README
phppdf
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.
- Documents - standard formats (A4 / Letter / Legal and more) and custom sizes, portrait or landscape, multi-page, metadata, AES-256 password protection, and viewer hints.
- Coordinates - millimetres by default (origin top-left, Y pointing down), or PDF points via
Unit::PT. - Graphics - lines, rectangles, circles, paths, fill / stroke, dashes, line caps / joins, and transforms.
- Text - the 12 standard PDF fonts, multi-line text, configurable leading, and full Western Latin (accents and typographic characters).
- Custom TrueType / OpenType fonts - register your own families and use them like the built-ins: full Unicode reach (Latin / Greek / Cyrillic / CJK), selectable text, and automatic glyph subsetting for small files.
- Cells - text boxes with borders, fill, padding, alignment (left / center / right / justify), automatic word-wrap, and three width-fit modes.
- Text measurement -
$page->stringWidth(...)returns the exact width of a string in the current font. - Images - JPEG and PNG (all color types, with transparency), auto-detected, embedded once and placed as many times as you like.
- SVG vector images - inline or from a file, fully vector: shapes, paths, gradients, patterns, clipping, masks, CSS styling, embedded rasters, real selectable
<text>/<textPath>, and a pure-PHP<filter>raster. - Barcodes & QR codes - 1D (EAN-13 / 8, Code 128 / 39 / 93, UPC-A, ITF) and 2D (QR, Aztec, DataMatrix, PDF417), all pure-PHP and vector, with optional human-readable text and vertical 1D rendering.
- Bookmarks & hyperlinks - a nested table-of-contents sidebar and clickable areas that open a URL or jump to another page.
- Interactive forms - fillable text fields, checkboxes, radio buttons, dropdowns, listboxes, and push buttons, with per-field styling, JavaScript actions (calculation / formatting / validation), and automatic field linking.
- Digital signatures - sign with a real PKCS#7 / CMS signature via
Document::sign()and a PKCS#12 credential, with RFC 3161 timestamps, multiple signers, the strict PAdES profiles (B-B / B-T), and long-term-validation (LTV) building blocks. - Markdown - render a CommonMark core subset, either flowing with automatic page breaks (
Page::markdown()) or inside an auto-sized cell; styleable viaMarkdownStyle. - Tables - data grids via
Page::table(): fixed orfillcolumns, headers repeated across pages, zebra striping, borders, a 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 document base direction with
setBaseDirection(), override per cell withdirection:, per table cell withCell::direction(), or per Markdown block with thedirection:argument onPage::markdown()/cell(markdown: true);Direction::AUTOdetects the base from the text. An RTL base right-aligns by default. No page-coordinate flip - layout, images, and tables are unaffected. Arabic cursive shaping is included: letters are joined using the correct contextual presentation forms (isolated / initial / medial / final) and the four mandatory lam-alef ligatures are formed automatically; the font's cmap must contain the Arabic presentation forms (e.g. GNU FreeSerif, DejaVu Sans, Tahoma - modern GSUB-only fonts that omit the legacy presentation-form block are not supported). Markdown RTL: bidi reordering and Arabic shaping apply to each Markdown block, RTL blocks are right-aligned, and list markers / blockquote bars are mirrored to the right side; inline code and fenced code blocks stay LTR. - 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 - emit PDF/A-2 and PDF/A-3 (levels b, u, and a) with one
enablePdfA()call, validated against veraPDF; A-3 embeds associated files such as a Factur-X / ZUGFeRD e-invoice. Level A (PdfALevel::A2A/A3A) auto-enables tagging and requires the catalog language, e.g.enablePdfA(PdfALevel::A2A, 'en-US'). CombiningenablePdfA(PdfALevel::A2A, 'en-US')withenablePdfUA('en-US')produces a single file that is both PDF/A-2a and PDF/UA-1. - Tagged PDF & PDF/UA-1 accessibility - opt-in structure tagging via
enableTagging(): cells, images, tables, and Markdown are tagged automatically into a logical structure tree (StructTreeRoot,MarkInfo, ParentTree, marked content), with an optional document language.enablePdfUA()goes further and produces output that validates as PDF/UA-1 (isCompliantunder veraPDF): decoration is marked as/Artifact, figures carry alternate text (image(alt: ...)), table headers get a scope,DisplayDocTitleand an XMPpdfuaidare emitted, and a fail-fast guard enforces embedded fonts, a title, and figure alt text. Text hyperlinks made withcell(link: ...)are tagged as accessible<Link>elements (with/OBJR,/StructParent, and a description). Markdown inline links are also tagged automatically as<Link>elements when tagging is on, somarkdown()with links is PDF/UA-1 conformant. Image hyperlinks are tagged on both surfaces:Page::image(link: ..., linkAlt: ...)and Markdown block image links[](url)both emit a<Link>wrapping the<Figure>, keeping documents with image links PDF/UA-1 conformant.
Not yet implemented
- Bidi explicit embedding/override/isolate controls, and per-column-header direction in tables.
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:
- Getting Started, Examples
- Text and Fonts, Cells, Tables, Graphics, Images
- Barcodes and QR Codes, SVG Support
- Markdown, Bookmarks and Hyperlinks, Viewer Preferences, Metadata and Encryption
- Interactive Forms, Digital Signatures, PDF/A Conformance
- Internals and contributing: Architecture, Contributing
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 :)
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-06
