PHPackages                             maestrodimateo/simple-word - 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. [Templating &amp; Views](/categories/templating)
4. /
5. maestrodimateo/simple-word

ActiveLibrary[Templating &amp; Views](/categories/templating)

maestrodimateo/simple-word
==========================

A simple, dev-friendly Laravel wrapper for PHPWord

v1.2.3(1mo ago)21MITPHPPHP ^8.3 || ^8.4

Since Apr 30Pushed 1mo agoCompare

[ Source](https://github.com/maestrodimateo/simple-word)[ Packagist](https://packagist.org/packages/maestrodimateo/simple-word)[ RSS](/packages/maestrodimateo-simple-word/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

Simple Word
===========

[](#simple-word)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ecf94356e7dba3071c94a3e7f564a765527135e498a4bc11ac17a9c9aef1df35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61657374726f64696d6174656f2f73696d706c652d776f72642e737667)](https://packagist.org/packages/maestrodimateo/simple-word)[![License](https://camo.githubusercontent.com/9bf87851f0f26170844b34133c54c8ecb577f76db5f273fe838e9d79be61880d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61657374726f64696d6174656f2f73696d706c652d776f72642e737667)](https://packagist.org/packages/maestrodimateo/simple-word)

A simple, dev-friendly Laravel wrapper for [PHPWord](https://github.com/PHPOffice/PHPWord).

Built on top of PHPWord's [`TemplateProcessor`](https://phpword.readthedocs.io/en/latest/templates-processing.html), this package provides a fluent API for generating Word documents from `.docx` templates — with variables, tables, images, conditional blocks, PDF conversion, and Mailable-style template classes out of the box.

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

[](#installation)

```
composer require maestrodimateo/simple-word
```

Publish the config:

```
php artisan vendor:publish --tag=word-config
```

Add to your `.env` (optional):

```
WORD_TEMPLATES_PATH=/path/to/your/templates
```

By default, templates are resolved from `resources/templates/word`.

---

Quick Start
-----------

[](#quick-start)

### Replace placeholders

[](#replace-placeholders)

In your `.docx` template, use [`${variable}` placeholders](https://phpword.readthedocs.io/en/latest/templates-processing.html#setValue):

> Hello **${name}**, your order **${ref}** was placed on **${date}**.

```
word()->template('order.docx')
    ->set('name', 'John Doe')
    ->set('ref', 'CMD-001')
    ->set('date', now()->format('d/m/Y'))
    ->save(storage_path('app/orders/order-john.docx'));
```

### Bulk replace

[](#bulk-replace)

```
word()->template('order.docx')
    ->set([
        'name' => 'John Doe',
        'ref'  => 'CMD-001',
        'date' => now()->format('d/m/Y'),
    ])
    ->download('order.docx');
```

### Nested arrays (dot notation)

[](#nested-arrays-dot-notation)

Nested associative arrays are automatically flattened with dot notation. This is useful for grouping related data:

```
word()->template('contract.docx')
    ->set([
        'client' => [
            'name'  => 'John Doe',
            'email' => 'john@example.com',
            'address' => [
                'city' => 'Paris',
                'zip'  => '75001',
            ],
        ],
        'date' => now()->format('d/m/Y'),
    ])
    ->download('contract.docx');
```

This replaces `${client.name}`, `${client.email}`, `${client.address.city}`, `${client.address.zip}`, and `${date}` in the template.

---

Tables
------

[](#tables)

In your template, prefix table cell placeholders with a group name. See [PHPWord cloneRowAndSetValues](https://phpword.readthedocs.io/en/latest/templates-processing.html#cloneRowAndSetValues):

${items.produit}${items.prix}```
word()->template('invoice.docx')
    ->table('items', [
        ['produit' => 'Widget A', 'prix' => '100 EUR'],
        ['produit' => 'Widget B', 'prix' => '200 EUR'],
        ['produit' => 'Widget C', 'prix' => '50 EUR'],
    ])
    ->download('invoice.docx');
```

The table row is cloned once for each entry and placeholders are filled automatically.

---

Images
------

[](#images)

Use `${placeholder}` in your template where an image should appear. See [PHPWord setImageValue](https://phpword.readthedocs.io/en/latest/templates-processing.html#setImageValue):

### Local file

[](#local-file)

```
word()->template('report.docx')
    ->set('company', 'Acme Corp')
    ->image('logo', storage_path('app/logo.png'), width: 150, height: 50)
    ->image('signature', storage_path('app/signature.png'))
    ->save(storage_path('app/report.docx'));
```

### Remote URL (GED, CDN, Alfresco, etc.)

[](#remote-url-ged-cdn-alfresco-etc)

`image()` accepts HTTP/HTTPS URLs. The image is downloaded automatically to a temp file:

```
word()->template('report.docx')
    ->set('company', 'Acme Corp')
    ->image('logo', 'https://alfresco.example.com/api/-default-/public/alfresco/versions/1/nodes/abc-123/content', width: 150)
    ->download('report.docx');
```

### From a Laravel filesystem disk

[](#from-a-laravel-filesystem-disk)

Use `imageFromDisk()` to load images from any configured [Laravel filesystem disk](https://laravel.com/docs/filesystem) (S3, SFTP, custom Alfresco adapter, etc.):

```
word()->template('report.docx')
    ->set('company', 'Acme Corp')
    ->imageFromDisk('logo', 'alfresco', 'logos/company.png', width: 150, height: 50)
    ->imageFromDisk('signature', 's3', 'signatures/ceo.png')
    ->download('report.docx');
```

---

Conditional Blocks
------------------

[](#conditional-blocks)

In your template, wrap conditional content with [block markers](https://phpword.readthedocs.io/en/latest/templates-processing.html#cloneBlock):

> ${has\_discount} You benefit from a 10% loyalty discount! ${/has\_discount}

```
word()->template('offer.docx')
    ->set('client', 'Jane Doe')
    ->when('has_discount', $client->is_vip)
    ->when('has_warranty', $product->warranty_months > 0)
    ->download('offer.docx');
```

When the condition is `true`, the content is kept (markers removed). When `false`, the entire block is removed.

---

Template Classes (Mailable-style)
---------------------------------

[](#template-classes-mailable-style)

For reusable, testable templates, generate a dedicated class:

```
php artisan make:word-template InvoiceDocument
```

This creates `app/Word/InvoiceDocument.php`:

```
namespace App\Word;

use Maestrodimateo\SimpleWord\DocumentBuilder;
use Maestrodimateo\SimpleWord\WordTemplate;

class InvoiceDocument extends WordTemplate
{
    protected string $template = 'invoice.docx';

    public function __construct(
        private Invoice $invoice,
        private Collection $lines,
    ) {}

    public function build(DocumentBuilder $builder): void
    {
        $builder
            ->set([
                'client' => [
                    'name'  => $this->invoice->client->name,
                    'email' => $this->invoice->client->email,
                ],
                'date'  => $this->invoice->date->format('d/m/Y'),
                'total' => number_format($this->invoice->total, 2) . ' EUR',
            ])
            ->table('lines', $this->lines->map(fn ($l) => [
                'description' => $l->description,
                'quantity'    => $l->quantity,
                'price'       => number_format($l->price, 2) . ' EUR',
            ])->all())
            ->image('logo', storage_path('app/logo.png'), width: 120, height: 40)
            ->when('has_notes', $this->invoice->notes !== null);
    }
}
```

Use it anywhere:

```
// In a controller
return word()->generate(new InvoiceDocument($invoice, $lines))
    ->download('invoice.docx');

// Save to disk
word()->generate(new InvoiceDocument($invoice, $lines))
    ->saveTo('s3', "invoices/{$invoice->id}.docx");
```

---

PDF Conversion
--------------

[](#pdf-conversion)

Convert any document to PDF with `toPdf()`:

```
word()->template('contract.docx')
    ->set('name', 'John Doe')
    ->toPdf()
    ->download('contract.pdf');
```

### Supported drivers

[](#supported-drivers)

DriverRequiresQuality`libreoffice` (default)[LibreOffice](https://www.libreoffice.org/) installed on serverExcellent`gotenberg`[Gotenberg](https://gotenberg.dev/) Docker containerExcellent### Configuration

[](#configuration)

```
WORD_PDF_DRIVER=libreoffice
LIBREOFFICE_PATH=/usr/bin/libreoffice

# Or with Gotenberg
WORD_PDF_DRIVER=gotenberg
GOTENBERG_URL=http://localhost:3000
```

### Custom converter

[](#custom-converter)

Implement the `PdfConverter` interface for any other conversion service:

```
use Maestrodimateo\SimpleWord\Contracts\PdfConverter;

class CloudConvertPdf implements PdfConverter
{
    public function convert(string $docxPath, string $pdfPath): void
    {
        // Your conversion logic
    }
}

// Use it directly
word()->template('doc.docx')
    ->set('key', 'value')
    ->toPdf(new CloudConvertPdf())
    ->download('doc.pdf');
```

---

Output Methods
--------------

[](#output-methods)

All output methods are available on both `DocumentBuilder` (docx) and `PdfBuilder` (after `toPdf()`):

MethodDescription`save($path)`Save to a local file path`saveTo($disk, $path)`Save to a Laravel filesystem disk (S3, local, etc.)`download($filename)`Return a download HTTP response`stream($filename)`Return an inline HTTP response (preview in browser)```
// Save locally
->save(storage_path('app/document.docx'));

// Save to S3
->saveTo('s3', 'documents/2026/contract.docx');

// Download
return ->download('contract.docx');

// Preview in browser
return ->stream('contract.docx');
```

---

Advanced Usage
--------------

[](#advanced-usage)

Access the underlying PHPWord [`TemplateProcessor`](https://phpword.readthedocs.io/en/latest/templates-processing.html) for features not covered by the fluent API:

```
$builder = word()->template('complex.docx');

$processor = $builder->getProcessor();
$processor->cloneBlock('repeating_section', 3);

$builder->save('output.docx');
```

---

Facade
------

[](#facade)

```
use Maestrodimateo\SimpleWord\Facades\Word;

Word::template('doc.docx')->set('key', 'value')->save('output.docx');
Word::generate(new InvoiceDocument($invoice, $lines))->download('invoice.docx');
```

Helper
------

[](#helper)

```
word()->template('doc.docx')->set('key', 'value')->save('output.docx');
```

---

Configuration
-------------

[](#configuration-1)

```
// config/word.php
return [
    // Default directory for .docx templates
    'templates_path' => env('WORD_TEMPLATES_PATH', resource_path('templates/word')),

    // PDF conversion
    'pdf' => [
        'driver'           => env('WORD_PDF_DRIVER', 'libreoffice'),
        'libreoffice_path' => env('LIBREOFFICE_PATH', '/usr/bin/libreoffice'),
        'gotenberg_url'    => env('GOTENBERG_URL', 'http://localhost:3000'),
    ],
];
```

---

Artisan Commands
----------------

[](#artisan-commands)

CommandDescription`make:word-template`Generate a new WordTemplate class---

Testing
-------

[](#testing)

```
./vendor/bin/pest
```

---

Useful PHPWord Links
--------------------

[](#useful-phpword-links)

- [PHPWord Documentation](https://phpword.readthedocs.io/en/latest/)
- [Template Processing](https://phpword.readthedocs.io/en/latest/templates-processing.html) — setValue, cloneRow, cloneBlock, setImageValue
- [Elements](https://phpword.readthedocs.io/en/latest/elements.html) — text, tables, images, lists, headers/footers
- [Styles](https://phpword.readthedocs.io/en/latest/styles.html) — fonts, paragraphs, tables
- [Writers](https://phpword.readthedocs.io/en/latest/writers-readers.html) — Word2007, ODText, HTML, PDF
- [GitHub Repository](https://github.com/PHPOffice/PHPWord)

---

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

- [Noel Mebale](https://github.com/maestrodimateo)
- Built on [PHPOffice/PHPWord](https://github.com/PHPOffice/PHPWord)

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance92

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

6

Last Release

40d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92a2c64304e341345f2854b5bc9c43806b9e54f0b5b9b57135d37d69dd7c5c67?d=identicon)[mebalenoel](/maintainers/mebalenoel)

---

Top Contributors

[![maestrodimateo](https://avatars.githubusercontent.com/u/40523415?v=4)](https://github.com/maestrodimateo "maestrodimateo (6 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/maestrodimateo-simple-word/health.svg)

```
[![Health](https://phpackages.com/badges/maestrodimateo-simple-word/health.svg)](https://phpackages.com/packages/maestrodimateo-simple-word)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k91.3M277](/packages/laravel-horizon)[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k449.3k30](/packages/tightenco-jigsaw)[spatie/laravel-health

Monitor the health of a Laravel application

88011.3M149](/packages/spatie-laravel-health)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[kimai/kimai

Kimai - Time Tracking

4.7k8.7k1](/packages/kimai-kimai)

PHPackages © 2026

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