PHPackages                             cleaniquecoders/dokufy - 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. cleaniquecoders/dokufy

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

cleaniquecoders/dokufy
======================

Generate PDFs your way — Gotenberg, LibreOffice, or native PHP.

1.1.0(3mo ago)00[2 PRs](https://github.com/cleaniquecoders/dokufy/pulls)MITPHPPHP ^8.2CI passing

Since Jan 15Pushed 2mo agoCompare

[ Source](https://github.com/cleaniquecoders/dokufy)[ Packagist](https://packagist.org/packages/cleaniquecoders/dokufy)[ Docs](https://github.com/cleaniquecoders/dokufy)[ GitHub Sponsors]()[ RSS](/packages/cleaniquecoders-dokufy/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (28)Versions (6)Used By (0)

Dokufy
======

[](#dokufy)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a259f795ab32c178ddd03be4c7b72f342cbc291800b45ce86ce2410dc194ee7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c65616e69717565636f646572732f646f6b7566792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/dokufy)[![GitHub Tests Action Status](https://camo.githubusercontent.com/bcf40d4f67402ccc36408af6dc465439b5dbb4b19a538859beb817d2d62b888c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f646f6b7566792f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/cleaniquecoders/dokufy/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/9635cf99a4f4bdfb6dec895b6224b70878e7efd4f463e4ddc9673b21743c15a8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f646f6b7566792f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/cleaniquecoders/dokufy/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/fd2248c8dabf2b5d885f2788651033d168664f1d34c8bf3377f72e0fca551ae2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c65616e69717565636f646572732f646f6b7566792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/dokufy)

**Generate PDFs your way — Gotenberg, LibreOffice, or native PHP.**

A driver-based document generation and PDF conversion package for Laravel. Write code once, then swap between drivers via configuration — no code changes required.

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

[](#installation)

Install the package via Composer:

```
composer require cleaniquecoders/dokufy
```

Run the installation command to set up the package:

```
php artisan dokufy:install
```

This will:

- Publish the configuration file
- Create the templates directory at `resources/templates`
- Create a sample HTML template
- Check driver availability and offer to install missing dependencies

Alternatively, you can manually publish the config file:

```
php artisan vendor:publish --tag="dokufy-config"
```

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

[](#configuration)

The published config file (`config/dokufy.php`) contains all driver settings:

```
return [
    // Default driver: gotenberg, libreoffice, chromium, phpword, fake
    'default' => env('DOKUFY_DRIVER', 'phpword'),

    'drivers' => [
        'gotenberg' => [
            'url' => env('DOKUFY_GOTENBERG_URL', 'http://gotenberg:3000'),
            'timeout' => env('DOKUFY_GOTENBERG_TIMEOUT', 120),
        ],

        'libreoffice' => [
            'binary' => env('DOKUFY_LIBREOFFICE_BINARY', 'libreoffice'),
            'timeout' => env('DOKUFY_LIBREOFFICE_TIMEOUT', 120),
        ],

        'chromium' => [
            'node_binary' => env('DOKUFY_NODE_BINARY'),
            'npm_binary' => env('DOKUFY_NPM_BINARY'),
            'timeout' => env('DOKUFY_CHROMIUM_TIMEOUT', 60),
        ],

        'phpword' => [
            'pdf_renderer' => env('DOKUFY_PDF_RENDERER', 'dompdf'),
        ],
    ],

    'pdf' => [
        'format' => env('DOKUFY_PDF_FORMAT', 'A4'),
        'orientation' => env('DOKUFY_PDF_ORIENTATION', 'portrait'),
        'margin_top' => env('DOKUFY_PDF_MARGIN_TOP', '1in'),
        'margin_bottom' => env('DOKUFY_PDF_MARGIN_BOTTOM', '1in'),
        'margin_left' => env('DOKUFY_PDF_MARGIN_LEFT', '0.5in'),
        'margin_right' => env('DOKUFY_PDF_MARGIN_RIGHT', '0.5in'),
    ],

    'templates' => [
        'path' => env('DOKUFY_TEMPLATES_PATH', resource_path('templates')),
    ],
];
```

Usage
-----

[](#usage)

### Basic HTML to PDF

[](#basic-html-to-pdf)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

// Simple HTML string
Dokufy::html('Hello World')
    ->toPdf(storage_path('documents/hello.pdf'));

// With placeholder data
Dokufy::html('Hello {{ name }}')
    ->data(['name' => 'Ahmad'])
    ->toPdf(storage_path('documents/greeting.pdf'));
```

### Template to PDF

[](#template-to-pdf)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

// DOCX template with placeholders
Dokufy::template(resource_path('templates/offer-letter.docx'))
    ->data([
        'name' => 'Ahmad bin Ali',
        'position' => 'Senior Developer',
        'salary' => 'RM 8,500.00',
    ])
    ->toPdf(storage_path('documents/offer.pdf'));

// HTML template file
Dokufy::template(resource_path('templates/invoice.html'))
    ->data(['invoice_number' => 'INV-001', 'total' => '1,500.00'])
    ->toPdf(storage_path('invoices/inv-001.pdf'));
```

### Template to DOCX

[](#template-to-docx)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

// Process placeholders and save as DOCX
Dokufy::template(resource_path('templates/contract.docx'))
    ->data(['client_name' => 'Acme Corp', 'date' => '15 January 2026'])
    ->toDocx(storage_path('contracts/acme-contract.docx'));
```

### Streaming and Downloads

[](#streaming-and-downloads)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

// In a controller - stream PDF inline (for preview)
public function preview(Invoice $invoice)
{
    return Dokufy::template(resource_path('templates/invoice.docx'))
        ->data($invoice->toArray())
        ->stream("invoice-{$invoice->number}.pdf");
}

// Download PDF as attachment
public function download(Invoice $invoice)
{
    return Dokufy::template(resource_path('templates/invoice.docx'))
        ->data($invoice->toArray())
        ->download("invoice-{$invoice->number}.pdf");
}
```

### Blade Views to PDF

[](#blade-views-to-pdf)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

$html = view('documents.invoice', compact('invoice'))->render();

Dokufy::html($html)
    ->toPdf(storage_path("invoices/{$invoice->id}.pdf"));
```

### Using a Specific Driver

[](#using-a-specific-driver)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

// Force a specific driver
Dokufy::driver('gotenberg')
    ->html('Generated with Gotenberg')
    ->toPdf(storage_path('documents/gotenberg.pdf'));

// Create new instance with driver
Dokufy::make('chromium')
    ->html($htmlContent)
    ->toPdf($outputPath);
```

### With Placeholdify Integration

[](#with-placeholdify-integration)

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;
use CleaniqueCoders\Placeholdify\PlaceholderHandler;

$handler = (new PlaceholderHandler())
    ->useContext('employee', $employee, 'emp')
    ->addFormatted('salary', $employee->salary, 'currency', 'MYR')
    ->addDate('start_date', $employee->start_date, 'd F Y');

Dokufy::template(resource_path('templates/offer-letter.docx'))
    ->with($handler)
    ->toPdf(storage_path('documents/offer.pdf'));
```

Placeholder Syntax
------------------

[](#placeholder-syntax)

Dokufy uses double curly braces for placeholders with flexible spacing:

```
{{ name }}
{{name}}
{{ name}}
{{name }}
```

All variations are supported and will be replaced with the corresponding data value.

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

[](#artisan-commands)

### Check Driver Status

[](#check-driver-status)

```
php artisan dokufy:status
```

Displays a table showing all drivers and their availability status.

### Generate Documents via CLI

[](#generate-documents-via-cli)

```
# Basic usage
php artisan dokufy:generate input.html output.pdf

# With specific driver
php artisan dokufy:generate input.docx output.pdf --driver=gotenberg

# With placeholder data
php artisan dokufy:generate template.html output.pdf --data='{"name":"Ahmad"}'

# With data from JSON file
php artisan dokufy:generate template.docx output.pdf --data-file=data.json

# Overwrite existing output
php artisan dokufy:generate input.html output.pdf --force
```

Available Drivers
-----------------

[](#available-drivers)

### phpword (default)

[](#phpword-default)

- **Requirements:** `phpoffice/phpword`, `dompdf/dompdf`
- **Formats:** HTML, DOCX
- **Best for:** Shared hosting, simple documents

### gotenberg

[](#gotenberg)

- **Requirements:** Docker + Gotenberg container, `gotenberg/gotenberg-php`
- **Formats:** HTML, DOCX, XLSX, PPTX, ODT, Markdown
- **Best for:** Production, CI/CD, Kubernetes

### libreoffice

[](#libreoffice)

- **Requirements:** LibreOffice binary installed
- **Formats:** HTML, DOCX, XLSX, PPTX, ODT
- **Best for:** Local development, traditional VPS

### chromium

[](#chromium)

- **Requirements:** Node.js, `spatie/browsershot`, Puppeteer
- **Formats:** HTML only
- **Best for:** Pixel-perfect HTML rendering, Tailwind CSS

### fake

[](#fake)

- **Requirements:** None
- **Formats:** All
- **Best for:** Testing

### Installing Driver Dependencies

[](#installing-driver-dependencies)

```
# PHPWord driver (default)
composer require phpoffice/phpword dompdf/dompdf

# Gotenberg driver
composer require gotenberg/gotenberg-php
# Also requires: docker run -d -p 3000:3000 gotenberg/gotenberg:8

# Chromium driver
composer require spatie/browsershot
npm install puppeteer

# Placeholdify integration (optional)
composer require cleaniquecoders/placeholdify
```

Testing
-------

[](#testing)

Dokufy provides a fake driver for testing:

```
use CleaniqueCoders\Dokufy\Facades\Dokufy;

it('generates offer letter PDF', function () {
    Dokufy::fake();

    $employee = Employee::factory()->create();

    // Your code that generates documents
    app(GenerateOfferLetter::class)->execute($employee);

    // Assertions
    Dokufy::assertPdfGenerated();
    Dokufy::assertGenerated(storage_path("documents/offer-{$employee->id}.pdf"));
});

it('generates contract DOCX', function () {
    Dokufy::fake();

    // Your code
    app(GenerateContract::class)->execute($client);

    Dokufy::assertDocxGenerated();
});
```

Run tests:

```
composer test
```

API Reference
-------------

[](#api-reference)

### Facade Methods

[](#facade-methods)

```
// Input methods
Dokufy::template(string $path): self      // Set template file (HTML or DOCX)
Dokufy::html(string $content): self       // Set HTML content directly
Dokufy::data(array $data): self           // Set placeholder data (can be chained)
Dokufy::with(object $handler): self       // Use Placeholdify handler

// Output methods
Dokufy::toPdf(string $outputPath): string              // Generate PDF file
Dokufy::toDocx(string $outputPath): string             // Generate DOCX file
Dokufy::stream(?string $filename = null): StreamedResponse    // Stream PDF inline
Dokufy::download(?string $filename = null): BinaryFileResponse // Download PDF

// Driver selection
Dokufy::driver(string $name): self        // Select specific driver
Dokufy::make(?string $driver = null): self // Create new instance

// Utilities
Dokufy::getAvailableDrivers(): array      // List available drivers
Dokufy::isDriverAvailable(string $driver): bool // Check driver availability
Dokufy::reset(): self                     // Reset instance state

// Testing
Dokufy::fake(): FakeDriver                // Use fake driver
Dokufy::assertGenerated(string $path): void    // Assert file generated
Dokufy::assertPdfGenerated(): void        // Assert PDF generated
Dokufy::assertDocxGenerated(): void       // Assert DOCX generated
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance84

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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 ~73 days

Total

2

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b57069d0f4b634f65eccc6e5d5848990e25968d45ec2cf46d626c6a4658f944b?d=identicon)[nasrulhazim.m](/maintainers/nasrulhazim.m)

---

Top Contributors

[![nasrulhazim](https://avatars.githubusercontent.com/u/10341422?v=4)](https://github.com/nasrulhazim "nasrulhazim (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelpdfPhpWorddocumentLibreOfficeGotenbergCleanique Codersdokufy

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cleaniquecoders-dokufy/health.svg)

```
[![Health](https://phpackages.com/badges/cleaniquecoders-dokufy/health.svg)](https://phpackages.com/packages/cleaniquecoders-dokufy)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

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