PHPackages                             enflow/document-replacer - 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. enflow/document-replacer

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

enflow/document-replacer
========================

Modify docx templates and convert them to PDF

3.4.0(2mo ago)830.9k—0.6%[3 PRs](https://github.com/enflow/document-replacer/pulls)MITPHPPHP ^8.4CI passing

Since Apr 25Pushed 1w ago2 watchersCompare

[ Source](https://github.com/enflow/document-replacer)[ Packagist](https://packagist.org/packages/enflow/document-replacer)[ Docs](https://github.com/enflow-nl/document-replacer)[ Fund](https://enflow.nl/contact)[ RSS](/packages/enflow-document-replacer/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (34)Used By (0)

Modify docx templates and convert them to PDF
=============================================

[](#modify-docx-templates-and-convert-them-to-pdf)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0e972620fa51f0cef09b30b6ee057f4915f9dd8738a809d806fadb246ce1f1a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e666c6f772f646f63756d656e742d7265706c616365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/enflow/document-replacer)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c870477e74d47dd1acae50c949f356b3f75738140edd224556577f0b24948e69/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f656e666c6f772d6e6c2f646f63756d656e742d7265706c616365722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/document-replacer)[![Total Downloads](https://camo.githubusercontent.com/482a8584f6b74a644195f5250a490a5db54def170da5d4eba4eb3be90278177a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e666c6f772f646f63756d656e742d7265706c616365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/enflow/document-replacer)

The `enflow/document-replacer` package provides a easy way to modify docx templates, replace text and save it. Adds the ability to export it to PDF trough unoserver/unoconvert.

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

[](#installation)

You can install the package via composer:

```
composer require enflow/document-replacer
```

PDF conversion
--------------

[](#pdf-conversion)

This package comes with an implementation to convert docx templates to PDF using unoserver. You can install this on your machine globally using:

```
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt install libreoffice
sudo pip install unoserver

```

Converters
----------

[](#converters)

It's highly recommend using the new `unoconvert` converter. If you are unable to upgrade, we still provide the deprecated `UnoconvConverter` for the time being. `UnoconvConverter` is deprecated and will be removed in 3.0.

Server
------

[](#server)

Unoserver works together with unoconvert. Unoserver runs as a daemon on the server, and unoconvert connects through it to pass the files. To see why this is more efficient, see

Start the server with: `unoserver --daemon`

It's recommended setting this up with a server like supervisord, without the `--daemon` flag, to auto restart the process if needed.

Usage
-----

[](#usage)

```
use Enflow\DocumentReplacer\DocumentReplacer;

DocumentReplacer::template('filename.docx')
    ->converter(UnoserverConverter::class)
    ->replace([
        '${user}' => 'Michel',
        '${address.city}' => 'Alphen aan den Rijn',
        '${company}' => 'Enflow',
    ])
    ->save('document.pdf');
```

#### Images

[](#images)

If you wish to replace images in your document, you can pass the `Image` class to the replacement array like this:

```
use Enflow\DocumentReplacer\DocumentReplacer;
use Enflow\DocumentReplacer\ValueTypes\Image;

DocumentReplacer::template('filename.docx')
    ->converter(UnoconvConverter::class)
    ->replace([
        '${primary}' => Image::forPath('image.png'),
        '${second}' => Image::forBase64('iVBORw0KGgoA...'),
    ])
    ->save('document.pdf');
```

The search-pattern model for images can be like:

- `${search-image-pattern}`
- `${search-image-pattern:[width]:[height]:[ratio]}`
- `${search-image-pattern:[width]x[height]}`
- `${search-image-pattern:size=[width]x[height]}`
- `${search-image-pattern:width=[width]:height=[height]:ratio=false}`Where:
- \[width\] and \[height\] can be just numbers or numbers with measure, which supported by Word (cm|mm|in|pt|pc|px|%|em|ex)
- \[ratio\] uses only for `false`, `-` or `f` to turn off respect aspect ration of image. By default template image size uses as 'container' size.

More info can be found in the [`PHPWord` documentation](https://github.com/PHPOffice/PHPWord/blob/develop/docs/templates-processing.rst#setimagevalue)

Non-default server options
--------------------------

[](#non-default-server-options)

Running the server on non-default options (IP 127.0.0.1 / port 2002)? You can pass along the interface and port to the `UnoserverConverter`:

```
DocumentReplacer::template('filename.docx')
    ->converter(UnoserverConverter::class, [
        'interface' => '192.168.0.1',
        'port' => 1533,
    ])
```

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Michel Bardelmeijer](https://github.com/mbardelmeijer)
- [All Contributors](../../contributors)

About Enflow
------------

[](#about-enflow)

Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info [on our website](https://enflow.nl/en).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance92

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~111 days

Recently: every ~286 days

Total

24

Last Release

73d ago

Major Versions

0.8.0 → 1.0.02021-06-25

v1.x-dev → 2.0.0-rc.12021-12-04

2.3.0 → 3.0.02023-02-25

v2.x-dev → 3.1.02023-03-02

PHP version history (7 changes)0.1.0PHP ^7.1

0.7.0PHP ^7.2.5

1.0.0PHP ^7.4|^8.0

2.0.0-rc.1PHP ^8.0

2.0.0PHP ^8.1

3.0.0PHP ^8.2

3.4.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/665ee1919e7c3d12f556cb913d0012a632271f912dc9c3250b7da67d7f3f4b16?d=identicon)[enflow](/maintainers/enflow)

---

Top Contributors

[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (70 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

docxdocumentenflow

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/enflow-document-replacer/health.svg)

```
[![Health](https://phpackages.com/badges/enflow-document-replacer/health.svg)](https://phpackages.com/packages/enflow-document-replacer)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[pontedilana/php-weasyprint

PHP library allowing PDF generation from an url or a html page. Wrapper for Kozea/WeasyPrint.

781.2M17](/packages/pontedilana-php-weasyprint)[rockett/weasyprint

A feature-rich WeasyPrint wrapper for generating PDFs from HTML and CSS, with support for PDF/A, PDF/UA, attachments, and optional Laravel integration.

30224.7k](/packages/rockett-weasyprint)[paperdoc-dev/paperdoc-lib

A zero-dependency PHP library for generating, parsing and converting documents (PDF, HTML, CSV, DOCX)

1253.7k](/packages/paperdoc-dev-paperdoc-lib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
