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.3.0(1y ago)826.0k↓28.3%[1 PRs](https://github.com/enflow/document-replacer/pulls)MITPHPPHP ^8.2CI failing

Since Apr 25Pushed 1y 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 1mo ago

READMEChangelog (10)Dependencies (4)Versions (29)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

47

—

FairBetter than 94% of packages

Maintenance43

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.3% 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 ~97 days

Recently: every ~181 days

Total

23

Last Release

450d ago

Major Versions

0.8.0 → v1.x-dev2021-06-25

1.0.0 → 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 (6 changes)0.1.0PHP ^7.1

0.7.0PHP ^7.2.5

v1.x-devPHP ^7.4|^8.0

2.0.0-rc.1PHP ^8.0

2.0.0PHP ^8.1

3.0.0PHP ^8.2

### 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 (69 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

[mnvx/lowrapper

PHP wrapper over LibreOffice converter

129190.5k](/packages/mnvx-lowrapper)[enzim/tika-wrapper

This is a simple PHP Wrapper for Apache Tika (using the tika-app jar)

6021.3k](/packages/enzim-tika-wrapper)[ninoskopac/php-tika-wrapper

This is a simple PHP Wrapper for Apache Tika (using the tika-app jar)

6011.1k](/packages/ninoskopac-php-tika-wrapper)[novay/laravel-word-template

Package Laravel untuk melakukan penggantian kata pada file menggunakan template dokumen (.doc atau .docx) yang sudah disediakan.

4815.1k](/packages/novay-laravel-word-template)[nilgems/laravel-textract

A Laravel package to extract text from files like DOC, XL, Image, Pdf and more. I've developed this package by inspiring "npm textract".

195.2k](/packages/nilgems-laravel-textract)

PHPackages © 2026

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