PHPackages                             ananikomlanmh/word-for-laravel - 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. ananikomlanmh/word-for-laravel

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

ananikomlanmh/word-for-laravel
==============================

A Laravel package to generate Word documents easily

v1.0.1(4mo ago)12191[1 PRs](https://github.com/ananikomlanMH/word-for-laravel/pulls)MITPHPPHP ^8.1CI passing

Since Nov 23Pushed 1mo agoCompare

[ Source](https://github.com/ananikomlanMH/word-for-laravel)[ Packagist](https://packagist.org/packages/ananikomlanmh/word-for-laravel)[ Docs](https://github.com/ananikomlanmh/word-for-laravel)[ RSS](/packages/ananikomlanmh-word-for-laravel/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (2)Dependencies (13)Versions (4)Used By (0)

[![](/art/logo.svg)](https://github.com/ananikomlanMH/word-for-laravel)

 [![Build Status](https://github.com/ananikomlanmh/word-for-laravel/actions/workflows/tests.yml/badge.svg)](https://github.com/ananikomlanmh/word-for-laravel/actions) [![Coding Standards](https://github.com/ananikomlanmh/word-for-laravel/actions/workflows/quality.yml/badge.svg)](https://github.com/ananikomlanmh/word-for-laravel/actions/workflows/quality.yml) [![Total Downloads](https://camo.githubusercontent.com/075579c27d9385602f6fa616ad690d24c587add5d42548a8ea316e0392a03c5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e616e696b6f6d6c616e6d682f776f72642d666f722d6c61726176656c)](https://packagist.org/packages/ananikomlanmh/word-for-laravel) [![Latest Stable Version](https://camo.githubusercontent.com/017fa138a11e5d66cefac8acd36790270c38601739bb2dcf52d572cbfdf61552/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e616e696b6f6d6c616e6d682f776f72642d666f722d6c61726176656c)](https://packagist.org/packages/ananikomlanmh/word-for-laravel) [![License](https://camo.githubusercontent.com/217df2ebf02e62983b1b3cff098df05545c9a48b0a05c10d6928d67dc1c290a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e616e696b6f6d6c616e6d682f776f72642d666f722d6c61726176656c)](https://packagist.org/packages/ananikomlanmh/word-for-laravel)

Generate Word documents (.docx) from Laravel Blade templates using PHPWord under the hood. This package provides an elegant API for creating professional Word documents with the full power of Blade templating.

Table of Contents
-----------------

[](#table-of-contents)

- **[Requirements](#requirements)**
- **[Installation](#installation)**
- **[Basic Usage](#basic-usage)**
    - [Simple Document Generation](#simple-document-generation)
    - [Saving to Disk](#saving-to-disk)
    - [Setting Document Properties](#setting-document-properties)
    - [Controller Example](#controller-example)
- **[Creating Word Templates](#creating-word-templates)**
    - [Using Artisan Command](#using-artisan-command)
    - [Template Structure](#template-structure)
    - [Supported HTML Elements](#supported-html-elements)
- **[Advanced Usage](#advanced-usage)**
    - [Getting Document Content](#getting-document-content)
    - [Accessing PHPWord Instance](#accessing-phpword-instance)
    - [Resetting the Converter](#resetting-the-converter)
- **[Configuration](#configuration)**
    - [Orientation](#orientation)
- **[Testing](#testing)**
- **[Examples](#examples)**
    - [Invoice Example](#invoice-example)
    - [Report with Tables](#report-with-tables)
- **[CSS Support](#css-support)**
- **[Images](#images)**
- **[Changelog](#changelog)**
- **[Contributing](#contributing)**
- **[Security](#security)**
- **[Credits](#credits)**
- **[License](#license)**

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x or higher

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

[](#installation)

Install the package via Composer:

```
composer require ananikomlanmh/word-for-laravel
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag="word-for-laravel-config"
```

Basic Usage
-----------

[](#basic-usage)

### Simple Document Generation

[](#simple-document-generation)

```
use WordForLaravel\Facades\WordForLaravel;

// Generate and download a document
return WordForLaravel::load('word.invoice', [
        'invoiceNumber' => 'INV-001',
        'client' => 'John Doe',
        'total' => 1500.00
    ])
    ->download('invoice.docx');
```

### Saving to Disk

[](#saving-to-disk)

```
use Illuminate\Support\Facades\Storage;
use WordForLaravel\Facades\WordForLaravel;

// Save to the default disk
WordForLaravel::load('word.report', $data)
    ->save('reports/monthly-report.docx');

// Save to a specific disk
WordForLaravel::load('word.report', $data)
    ->save('reports/monthly-report.docx', 's3');

// Get the full path
$path = Storage::disk('local')->path('reports/monthly-report.docx');
```

### Setting Document Properties

[](#setting-document-properties)

```
WordForLaravel::load('word.contract', $data)
    ->setProperties([
        'title' => 'Employment Contract',
        'creator' => 'HR Department',
        'company' => 'ACME Corporation',
        'subject' => 'Contract Agreement',
        'description' => 'Employment contract for new hire'
    ])
    ->download('contract.docx');
```

### Controller Example

[](#controller-example)

```
