PHPWord

A pure-PHP library to read and write word processing documents in DOCX, ODT, RTF, HTML, and more.

Library
Composer
v1.4.0
7,582stars
LGPL-3.0-only

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
76/100Good
Development Activity68
Maintenance44
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality82
Innovation76
Learning Curve72

PHPWord is a pure-PHP library that provides a set of classes to write to and read from word processing document formats. It supports Microsoft Office Open XML (DOCX), OASIS OpenDocument (ODT), Rich Text Format (RTF), HTML, and PDF output, giving PHP applications a single API for generating and parsing documents without any external Office software.

Beyond raw document creation, PHPWord offers a template processor for filling placeholders in existing DOCX templates, rich styling of text, paragraphs, tables, images, headers, footers, and table of contents. It is part of the well-established PHPOffice family of libraries and is widely used for automated report and contract generation.

What You Get

  • Writers and readers for DOCX, ODT, RTF, HTML, and PDF (via bundled renderers)
  • A TemplateProcessor for populating placeholders and cloning rows/blocks in existing DOCX templates
  • Rich styling of fonts, paragraphs, tables, cells, borders, headers, footers, and page settings
  • Structural elements including tables, images, links, table of contents, footnotes, and text boxes
  • An IOFactory abstraction for choosing formats without changing document-building code

Common Use Cases

  • Generating Word documents such as invoices, contracts, and reports from application data
  • Filling DOCX templates with dynamic values using the template processor
  • Converting between document formats or exporting generated documents to PDF

Under The Hood

Architecture - src/PhpWord/PhpWord.php is the document root that owns sections and shared collections. Content is built from Element/ classes (Text, Table, Image, ListItem, TOC, etc.), styled via Style/ classes, and serialized by format-specific Writer/ implementations while Reader/ classes parse documents back in; IOFactory.php selects the right writer/reader by name. TemplateProcessor.php operates directly on a DOCX zip to substitute placeholders and clone blocks. Tech Stack - Pure PHP 7.1+/8.x requiring the dom, gd, zip, json, and xml extensions, plus phpoffice/math for equation support; DOCX/ODT are handled as zipped XML. Code Quality - The project has a long history under the PHPOffice organization with GitHub Actions CI, Coveralls coverage tracking, and an extensive PHPUnit test suite covering readers, writers, and elements. API Design - The fluent builder API (addSection(), addText(), addTable(), save() via IOFactory) reads naturally, and the TemplateProcessor offers a simple setValue()/cloneRow() interface; the breadth of styling options gives a moderate learning curve, mitigated by thorough documentation at the project site.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search