PHPWord reads and writes Word, ODF, RTF, HTML, PDF, and legacy DOC files from PHP code to build or parse office documents programmatically.
Overview
PHPWord is a pure PHP library with classes for creating and reading word processing documents in several formats. Supported interchange formats include Microsoft Office Open XML (docx), OASIS OpenDocument (odt), RTF, HTML, PDF, and binary Microsoft Word (doc) for reading, with writer coverage varying by feature.
Document construction APIs let you set metadata, define sections with orientation and numbering, add headers and footers, and apply default or named font and paragraph styles including UTF-8 and East Asian text. Content can include paragraphs and rich text runs, headings, tables of contents, breaks, images, OLE objects, tables, lists, hyperlinks, footnotes, shapes, charts, and form fields.
Templates can seed new documents, and XSL 1.0 stylesheets can transform parts of OOXML templates. Readers extract structure and text from existing files where implemented, with feature matrices documenting which elements work per format for writers and readers.
The package installs through Composer and targets PHP 7.1 or newer. It is maintained as part of the PHPOffice ecosystem with developer documentation and sample scripts illustrating typical usage patterns.
Key features
- DOCX, ODT, RTF, HTML, PDF I/O
- Sections, headers, and footers
- Styles, tables, and lists
- Images, charts, and shapes
- Template and XSL transforms
- Form fields and hyperlinks
- Footnotes and table of contents
- Composer-installable PHP library
Use cases
- Server-side report generation
- Mail-merge style documents
- Converting or parsing office files
- Invoice and contract automation
- Template-driven document output