PHPackages                             gyselroth/docx-tidy - 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. gyselroth/docx-tidy

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

gyselroth/docx-tidy
===================

Simplify markup of DOCX XML by tidying successive elements w/ redundant properties / types.

0.5.1(8y ago)713.3k—2.9%[2 issues](https://github.com/gyselroth/docx-tidy/issues)Apache-2.0PHPPHP &gt;=7.1.0

Since Feb 15Pushed 7y ago2 watchersCompare

[ Source](https://github.com/gyselroth/docx-tidy)[ Packagist](https://packagist.org/packages/gyselroth/docx-tidy)[ Docs](https://github.com/gyselroth/docx-tidy)[ RSS](/packages/gyselroth-docx-tidy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (13)Used By (0)

DocxTidy
========

[](#docxtidy)

[![Total Downloads](https://camo.githubusercontent.com/1d9c02455acec725b572f4d446b590654e67458099ff96233dd93d1d6c5d7b3b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677973656c726f74682f646f63782d746964792e737667)](https://packagist.org/packages/gyselroth/docx-tidy)[![Latest Stable Version](https://camo.githubusercontent.com/f5ec85810444563bf037c6107da1523d6c0f6ae26e98ef2e4013eaa45c4e8c3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677973656c726f74682f646f63782d746964792e737667)](https://packagist.org/packages/gyselroth/docx-tidy)

Description
-----------

[](#description)

A PHP library to tidy DOCX XML files: merges successive elements of same type and properties.

By simplifying the markup of DOCX XML, DocxTidy alleviates the efforts needed for custom modifications (for instance DOCX-based templating).

- Merges successive runs having identical run-properties
- Merges successive elements of same type (&lt;w:t&gt;, &lt;w:instrText&gt;) within each run

DocxTidy supports two tidying modes:

1. DOCX files (includes unpacking and re-archiving of contained XML files)
2. XML string

Please Note
-----------

[](#please-note)

- By merging segmented tags, DocxTidy removes versioning/editing history information
- When run with default settings, DocxTidy removes spellchecking flags ("noProof", "proofErr", "lang")
- DocxTidy removes all xml:space="preserve" flags and re-inserts xml:space="preserve" into all &lt;w:t&gt; and &lt;w:instrText&gt; tags
- To standardize run properties, DocxTidy deletes any font hints
- After unifying consecutive runs w/ identical properties and removing any spellchecking flags, DocxTidy removes any resulting empty tags

This library is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

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

[](#installation)

The recommended way to install is via Composer:

```
$ composer require gyselroth/docx-tidy
```

PHP 7.1 is required since DocxTidy version 0.5.0 (PHP 5.6 until version 0.4.5)

Usage
-----

[](#usage)

### Example 1: Tidy a whole DOCX file

[](#example-1-tidy-a-whole-docx-file)

```
