PHPackages                             chanthoeun/filament-document-builder - 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. chanthoeun/filament-document-builder

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

chanthoeun/filament-document-builder
====================================

A Filament plugin for building dynamic documents and exporting to PDF.

v1.3.8(3w ago)0221↑50%1MITPHPPHP ^8.2CI passing

Since Jun 3Pushed 3w agoCompare

[ Source](https://github.com/Chanthoeun/filament-document-builder)[ Packagist](https://packagist.org/packages/chanthoeun/filament-document-builder)[ RSS](/packages/chanthoeun-filament-document-builder/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (13)Versions (41)Used By (1)

Filament Document Builder
=========================

[](#filament-document-builder)

A powerful and simplified Filament PHP plugin to build dynamic document templates (like invoices, certificates, and registration forms) using a full-featured TinyMCE editor, and automatically export them to PDFs with native support for complex scripts like Khmer.

It is designed to easily integrate with standalone Filament panels or with other plugins like `chanthoeun/filament-custom-forms`.

Features
--------

[](#features)

- **Advanced HTML Designer:** Uses `amidesfahani/filament-tinyeditor` (TinyMCE) instead of the native Tiptap editor to provide robust support for complex HTML structures and native table editing.
- **Dynamic Variables:** Inject runtime database values directly into your text blocks (e.g., `{{ customer.name }}`). Fallbacks safely to a blank space if data is missing (perfect for printing blank forms).
- **Native PDF Engine:** Powered by `carlos-meneses/laravel-mpdf` (mPDF) for pure PHP generation.
- **Complex Text Shaping:** Pre-configured with `autoScriptToLang` and `autoLangToFont` to perfectly render complex alphabets like Khmer natively, without needing headless Chrome or Puppeteer.
- **Easy Integration:** Drop a simple `Action` onto any Filament table to export the current record as a PDF.
- **Support for Filament v4 &amp; v5 (Laravel 10-13).**

---

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

[](#installation)

### 1. Requirements

[](#1-requirements)

- PHP 8.2+
- Filament v4.0 or v5.0
- TinyMCE (`amidesfahani/filament-tinyeditor`)
- mPDF (`carlos-meneses/laravel-mpdf`)

*(Note: Node.js, Puppeteer, and Chromium are **no longer required**!)*

### 2. Install via Composer

[](#2-install-via-composer)

```
composer require chanthoeun/filament-document-builder
```

### 3. Publish &amp; Run Migrations

[](#3-publish--run-migrations)

You can publish the migration file to customize the table prefix or structure before running it:

```
php artisan vendor:publish --tag="filament-document-builder-migrations"
```

After publishing, run the migrations to create the `document_templates` table:

```
php artisan migrate
```

### 4. Register the Plugin

[](#4-register-the-plugin)

Add the plugin to your Filament Panel provider (`app/Providers/Filament/AdminPanelProvider.php`):

```
use Chanthoeun\FilamentDocumentBuilder\DocumentBuilderPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(
            DocumentBuilderPlugin::make()
                // Optional: Customize or remove the navigation group
                // ->navigationGroup('Custom Group') // Move to another group
                // ->navigationGroup(false) // Remove from groups entirely
                // ->navigationIcon('heroicon-o-document-text') // Change the navigation icon
        );
}
```

---

Configuration &amp; Publishing
------------------------------

[](#configuration--publishing)

Because this plugin is built with `Spatie\LaravelPackageTools`, all publishing logic is wired up natively.

### 1. Publishing the Config File

[](#1-publishing-the-config-file)

To customize default paper sizes, orientations, margins, and the predefined TinyMCE templates (like layout tables and shapes), publish the config file:

```
php artisan vendor:publish --tag="filament-document-builder-config"
```

This will create `config/filament-document-builder.php` in your application where you can edit the `templates` array to add your own custom document layouts.

### 2. Publishing Translations

[](#2-publishing-translations)

To override the default English and Khmer language files, run:

```
php artisan vendor:publish --tag="filament-document-builder-translations"
```

### 3. Publishing the Document Template Resource

[](#3-publishing-the-document-template-resource)

If you want complete control over the `DocumentTemplateResource` (e.g., to change its location, permissions, or logic), you can safely publish it to your application by running:

```
php artisan filament-document-builder:publish-resource
```

This command intelligently copies the resource files into your `app/Filament/Resources` directory and automatically updates all namespaces. The plugin will automatically detect that you've published the resource and will gracefully yield control, preventing any conflicts.

### 4. Updating the Package

[](#4-updating-the-package)

When pulling the latest updates for this package (e.g., via `composer update`), you generally don't need to re-publish anything if you are using the default plugin configuration. However:

- **If you previously published the resource:** Your local copy in `app/Filament/Resources/` will NOT automatically receive the new package updates. You will need to either manually copy over the new changes or re-publish the resource (which will overwrite your local customizations).
- **Assets:** It is always a good idea to run `php artisan filament:assets` after updating to ensure any cached scripts or editor plugins are properly synced to your `public` directory.

---

Usage
-----

[](#usage)

### 1. Creating a Template

[](#1-creating-a-template)

1. Navigate to the **Document Builder** resource in your Filament sidebar.
2. Click **Create Document Template**.
3. Set the layout rules (A4, Portrait) in the Template Details tab.
4. Construct your document using the **Document Designer** tab. Because it uses TinyMCE, you can easily insert and modify highly complex HTML tables.
5. If you plan to inject dynamic variables, type them using standard brace syntax (e.g., `Hello {{ name }}!`).

#### Built-in Shapes and Forms Support

[](#built-in-shapes-and-forms-support)

This plugin adds several pre-configured shapes to the TinyMCE editor to make designing forms significantly easier:

- Click the **Templates** dropdown in the toolbar to insert pre-made shapes like a **Circle Logo Placeholder**, a **4x6 Photo Box**, a **Rounded Rectangle**, or a **Signature Line**, as well as full document layouts.
- **Keyboard Shortcuts (Text Patterns):** You can also quickly insert shapes by typing the following codes and pressing Space:
    - `#logo` -&gt; Circular Logo Box
    - `#box` -&gt; Square Box
    - `#photo` -&gt; 4x6 Rectangle Photo Box
    - `#checkbox` -&gt; Small Checkbox
    - `#rounded` -&gt; Rounded Rectangle
    - `#oval` -&gt; Oval Shape
    - `#sign` -&gt; Signature Area with "ហត្ថលេខា / Signature"

#### Flexbox Support in mPDF

[](#flexbox-support-in-mpdf)

By default, mPDF does not support modern CSS Flexbox (`display: inline-flex`), which often breaks designs created in TinyMCE. This plugin **automatically polyfills** Flexbox behaviors (such as `inline-flex`, `align-items`, and `justify-content`) directly in PHP during the export process. Your TinyMCE layouts will render pixel-perfect in the final PDF without requiring complex CSS hacks!

### 2. Looping over Data (Table Repeaters)

[](#2-looping-over-data-table-repeaters)

If you need to iterate over an array or Eloquent relationship (like line items on an invoice), you can use the built-in `{{#foreach}}` syntax directly in your template.

Switch your TinyMCE editor to **Source Code (``)** view and wrap your repeating elements like this:

```

    {{#foreach items as item}}

        {{ item.description }}
        {{ item.qty }}
        {{ item.price }}
        {{ item.total }}

    {{/foreach}}

```

- The engine will automatically loop through the `items` array or relationship.
- You can access properties of each item using the prefix you define (e.g., `item.`).
- **Bonus:** Inside the loop, you still have full access to global variables from the parent record!

#### Handling Calculations (e.g., Invoices)

[](#handling-calculations-eg-invoices)

The document rendering engine intentionally avoids executing arbitrary PHP code within the template for security and performance reasons. Therefore, you cannot perform inline math like `{{ item.qty * item.price }}` inside the TinyMCE editor.

To handle calculations such as line totals, taxes, or grand totals, you should use **Laravel Eloquent Accessors** directly on your models.

**Example (Line Item Total):**On your `InvoiceItem` model, add an accessor:

```
public function getTotalAttribute() {
    return $this->qty * $this->price;
}
```

Now, you can simply use `{{ item.total }}` inside your `{{#foreach}}` loop!

**Example (Invoice Grand Total):**On your parent `Invoice` model:

```
public function getGrandTotalAttribute() {
    return $this->items->sum('total') + $this->tax_amount;
}
```

Then, anywhere in your document, you can output the grand total using `{{ grand_total }}`.

### 3. Additional Data Sources (Multi-Model Support)

[](#3-additional-data-sources-multi-model-support)

If your document requires data from multiple independent models (e.g., a student application form that needs global `SchoolSettings` or a specific `Principal` user), you can map them entirely through the UI without touching any code!

1. In the **Template Details** tab, click **Add to additional data sources**.
2. Give it a Variable Name (e.g., `school`).
3. Select the Database Model (e.g., `App\Models\SchoolSetting`) and choose "First Record" or "Latest Record".
4. The TinyMCE editor will instantly update its **Insert Variable** dropdown to include all the fields from your new model (e.g., `school.name`, `school.address`).

The PDF Engine will automatically execute these queries at runtime and securely merge the data into your document!

### 4. Exporting PDFs from your Resources

[](#4-exporting-pdfs-from-your-resources)

To allow users to download a PDF of a specific record or bulk download multiple records, use the built-in Action classes.

#### Row Action (Single PDF)

[](#row-action-single-pdf)

Add `DownloadPdfAction` to your resource's table actions to download individual records:

```
use Chanthoeun\FilamentDocumentBuilder\Tables\Actions\DownloadPdfAction;

public static function table(Table $table): Table
{
    return $table
        // ... columns ...
        ->actions([
            DownloadPdfAction::make('download_pdf')
                ->templateType('invoice') // The type string of the template you created
                // Optional: Customize the filename
                ->filename(fn ($record) => 'invoice-' . $record->id . '.pdf')
                // Optional: Pass custom data (defaults to the $record itself)
                ->recordData(fn ($record) => [
                    'name' => $record->customer_name,
                    'total' => $record->total_amount,
                ])
        ]);
}
```

#### Page Header Action (Bulk PDF)

[](#page-header-action-bulk-pdf)

Add `DownloadAllPdfAction` to your List page header to download multiple records at once (combined into a single PDF with pagebreaks):

```
use Chanthoeun\FilamentDocumentBuilder\Actions\DownloadAllPdfAction;

protected function getHeaderActions(): array
{
    return [
        DownloadAllPdfAction::make('download_all_pdf')
            ->templateType('invoice')
            ->records(fn () => $this->getFilteredTableQuery()->get()) // Provide the records to export
            ->filename('invoices-export.pdf')
    ];
}
```

---

Changelog
---------

[](#changelog)

### v1.0.15

[](#v1015)

- **Bug Fix**: Fixed an issue where the TinyMCE editor did not dynamically resize based on the live `page_settings` configuration.
- **Bug Fix**: Bypassed Filament TinyEditor's `wire:ignore` caching to ensure that the "Insert Variable" dropdown accurately populates when `extra_data_sources` are modified without requiring a page refresh.
- **Improvement**: Set `format` to uppercase prior to sending it to mPDF to ensure strict compatibility.

### v1.0.13

[](#v1013)

- Update README with migration publishing instructions

### v1.0.12

[](#v1012)

- Hide label and remove required validation from content editor

### v1.0.11

[](#v1011)

- Add navigationSort to allow changing menu order

### v1.0.10

[](#v1010)

- Rename data method to recordData to avoid conflict with Filament Actions

### v1.0.9

[](#v109)

- Fix namespace for Action inheritance

### v1.0.8

[](#v108)

- Update README with new action instructions

### v1.0.7

[](#v107)

- Create reusable PDF action classes

### v1.0.6

[](#v106)

- Add renderMultiple to support bulk PDF generation

### v1.0.5

[](#v105)

- Fix variable extraction to use CustomFormField model

### v1.0.4

[](#v104)

- Fix Array to string conversion

### v1.0.3

[](#v103)

- Fix Action namespace for Filament v4/v5 compatibility

### v1.0.2

[](#v102)

- Add publish resource command and improve custom forms integration

### v1.0.1

[](#v101)

- Fix Filament v4 Action namespaces

### v1.0.0

[](#v100)

- Update composer.json keywords and prepare for Packagist release

---

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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 ~1 days

Total

40

Last Release

23d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a03658d695707779308099003188e968ac140b52edd15abf2f1cf0b2feb41130?d=identicon)[Chanthoeun](/maintainers/Chanthoeun)

---

Top Contributors

[![Chanthoeun](https://avatars.githubusercontent.com/u/817917?v=4)](https://github.com/Chanthoeun "Chanthoeun (100 commits)")

---

Tags

laravelpdfmpdffilamentfilamentphpdocument builder

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chanthoeun-filament-document-builder/health.svg)

```
[![Health](https://phpackages.com/badges/chanthoeun-filament-document-builder/health.svg)](https://phpackages.com/packages/chanthoeun-filament-document-builder)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k253.1k86](/packages/moonshine-moonshine)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.8k](/packages/rawilk-profile-filament-plugin)[stephenjude/filament-jetstream

A Laravel starter kit built with Filament inspired by Jetstream.

17760.2k3](/packages/stephenjude-filament-jetstream)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)

PHPackages © 2026

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