Download the PHP package dskripchenko/php-docx without Composer

On this page you can find all versions of the php package dskripchenko/php-docx. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-docx

dskripchenko/php-docx

🌐 English Β· δΈ­ζ–‡

Tests Conformance Latest Version Total Downloads PHP

The HTML layer for your PHPWord pipeline β€” and a standalone DOCX ↔ HTML round-trip library. Pure-PHP: read arbitrary Word / Google Docs / LibreOffice / PHPWord documents into a typed AST, turn them into clean HTML, convert HTML into DOCX, detect template variables (MERGEFIELD, content controls, {{placeholders}}). Works next to PHPWord, not instead of it. No external dependencies beyond standard PHP extensions.

Read this in other languages: English Β· Русский Β· δΈ­ζ–‡ Β· Deutsch


Table of contents


Features

Out of scope

Tracked changes, comments, embedded charts, OLE objects, footnotes/endnotes, SmartArt, math equations (OMML), form fields, custom XML parts.


Examples

Runnable scripts with committed output live in examples/: HTML β†’ DOCX with headers and watermarks, the fluent builder, DOCX β†’ HTML import, template-variable detection and substitution, round-trip stability, CSS inlining, and the PHPWord bridge.

php-docx and PHPWord

PHPWord is the established library for building Word documents in PHP. php-docx does not replace it β€” it adds the two things PHPWord is weakest at: reading arbitrary DOCX (with a full style cascade) and HTML in both directions. Use both, each for what it does best.

What php-docx adds next to PHPWord:

What php-docx deliberately does not do (PHPWord or other tools do): ODF/RTF/PDF output, tracked changes, comments, footnotes/endnotes, charts, OMML math, form fields.

Zero-integration recipe β€” works today, no bridge required. PHPWord writes the file, php-docx reads the bytes:

A typed object-level bridge (PhpWordBridge::toHtml($phpWord), HTML import into PHPWord objects, reading straight into PHPWord models) ships separately as dskripchenko/php-docx-phpword.


Requirements


Installation


Quick start

1. HTML β†’ DOCX

2. Programmatic builder

3. DOCX β†’ HTML / AST


HTML β†’ DOCX

Input HTML must use inline styles only (no <style> blocks). Use a CSS-inliner upstream if needed.

Supported elements

Category HTML tags
Text blocks <p>, <h1..h6>, <div>, <pre>, <blockquote>
Inline marks <strong>/<b>, <em>/<i>, <u>, <s>/<del>, <sup>, <sub>, <mark>
Code/teletype <code>, <kbd>, <samp>, <var>, <cite>, <dfn>, <q>, <small>
Links <a href> external, <a href="#anchor"> internal, <a id> bookmarks
Images <img src="data:image/...;base64,...">
Tables <table>, <thead>/<tbody>, <tr>, <th>/<td>, <colgroup>/<col>, <caption>, colspan, rowspan
Lists <ul>, <ol type="a/A/i/I" start="N">, <li value="N">, <dl>/<dt>/<dd>
Custom tags <page-number/>, <page-total/>, <current-date format="...">, <page-break>
Marker classes class="page-number", class="page-total", class="page-break" β€” same fields, spelled so an HTML sanitizer keeps them
Layout <hr>, <br>, <figure>/<figcaption>

Inline styles

The converter understands style="…" properties:

Custom tags

These become OOXML field codes (<w:fldSimple w:instr="PAGE">).

Custom heading styles


Stylesheets and classes

fromHtml() understands inline styles only. For HTML carrying <style> blocks or class-based styling, use fromHtmlWithStyles() β€” it first runs the document through an HtmlPreprocessor. The default implementation inlines CSS via the optional tijsverkoyen/css-to-inline-styles package (composer require tijsverkoyen/css-to-inline-styles; php-docx itself stays zero-dependency), and you can plug your own preprocessor:


Programmatic builder API

The Build namespace provides a fluent API for assembling DOCX documents block by block, finalising to the same immutable AST that the HTML pipeline produces.

DocumentBuilder

Entry point. Accumulates body, header/footer, watermark, page setup.

ParagraphBuilder

Inside ->paragraph(fn ($p) => …):

Paragraph-level styling:

TableBuilder

Spans and merges:

ListBuilder

RunStyleBuilder

Used inside ->styled(text, fn (RunStyleBuilder) => …) or standalone via RunStyleBuilder::new()->…->build().

Length helpers

Convert common units to OOXML twips (1 twip = 1/20 pt). Used wherever a twip int is expected.

Most builders expose unit-aware shortcuts:


DOCX β†’ HTML (Reader)

High-level: DocxReader

This runs the full pipeline: package unpack β†’ styles resolve β†’ body/header/footer parsing β†’ vMerge/list reconstruction β†’ image extraction β†’ watermark detection β†’ page setup.

Low-level: DocxPackageReader

If you need the raw OOXML parts:

Serializer: AST β†’ HTML

HTML output uses inline styles only β€” re-loadable into the same library via Html\Converter::fromHtml($imported->bodyHtml).


Headers, footers & watermarks

Three header/footer types are supported per section: default, first (title page), even (even pages). Word automatically renders the right one based on page number.

The writer automatically:

Watermark

Renders as a 45Β°-rotated VML text shape on every page.


Variable detection

Scans an imported DOCX for three kinds of variables:

  1. MERGEFIELD β€” Word mail-merge native, both simple <w:fldSimple> and complex <w:fldChar> form.
  2. SDT content controls β€” <w:sdt> with <w:tag w:val="...">.
  3. Text patterns β€” configurable regexes (defaults: {{name}}, ${name}, %name%).

Detection runs across body + all headers + all footers. Results are deduplicated by (source, name).


Length helpers

See Length helpers above. Conversion table:

Unit Twips Pt Notes
1 twip 1 0.05 OOXML native
1 pt 20 1 typography
1 mm ~57 2.83 metric
1 cm ~567 28.35 metric
1 inch 1440 72 imperial
1 px 15 0.75 CSS @ 96 DPI

AST overview

All elements live under Dskripchenko\PhpDocx\Element namespace.

Element Type Notes
Document root { section: Section, watermarkText: ?string }
Section container { body, header, footer, pageSetup, firstHeader, firstFooter, evenHeader, evenFooter }
Paragraph BlockElement { children: InlineElement[], style: ParagraphStyle, headingLevel: ?int }
Run InlineElement { text: string, style: RunStyle }
Hyperlink InlineElement { href: ?string, anchor: ?string, children: InlineElement[] }
Bookmark InlineElement { name: string, children: InlineElement[] }
Image both { binary, format, widthEmu, heightEmu, altText }
Field InlineElement { instruction: string, style: RunStyle }
LineBreak, PageBreak, HorizontalRule both marker elements
Table BlockElement { rows: TableRow[], style, caption, gridColumnsTwips }
TableRow element { cells: TableCell[], isHeader, heightTwips }
TableCell element { children: BlockElement[], style: CellStyle }
ListNode BlockElement { items: ListItem[], ordered, format, startAt }
ListItem element { children: InlineElement[], nestedList: ?ListNode }

Styles live under Dskripchenko\PhpDocx\Style:


Round-trip

The library targets semantic round-trip safety, not byte equality β€” content, structure and styling survive, but XML ordering and whitespace may differ.

In-scope round-trip features:

Out-of-scope features are silently dropped (footnotes, comments, equations, etc.).


Architecture

The same Document AST is shared by HTML conversion, programmatic construction and DOCX reading β€” every entry/exit point operates on typed value-objects.


Conformance

Every push validates the writer's output externally, not just against our own reader:

Reproduce locally:


Development


License

MIT β€” see LICENSE.


All versions of php-docx with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-dom Version *
ext-mbstring Version *
ext-zip Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dskripchenko/php-docx contains the following files

Loading the files please wait ...