PHPackages                             himelali/pdf-generator - 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. himelali/pdf-generator

ActiveLibrary

himelali/pdf-generator
======================

Laravel wrapper for Snappy, DomPDF, mPDF, fPDF

10PHP

Since May 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/himelali/pdf-generator)[ Packagist](https://packagist.org/packages/himelali/pdf-generator)[ RSS](/packages/himelali-pdf-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

 [![Total Downloads](https://camo.githubusercontent.com/d58310429ac0eabfc85048ec9d605f27ab326f9e6bac096839fe1b0d3fdf8755/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68696d656c616c692f7064662d67656e657261746f72)](https://camo.githubusercontent.com/d58310429ac0eabfc85048ec9d605f27ab326f9e6bac096839fe1b0d3fdf8755/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68696d656c616c692f7064662d67656e657261746f72) [![License](https://camo.githubusercontent.com/191bd7f296d6c8cafa7323c73bedb524574eb3384a106584c1341a3b8b0878c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68696d656c616c692f7064662d67656e657261746f72)](https://camo.githubusercontent.com/191bd7f296d6c8cafa7323c73bedb524574eb3384a106584c1341a3b8b0878c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68696d656c616c692f7064662d67656e657261746f72) [![Stars](https://camo.githubusercontent.com/929f9c11f171c84952541f216aa293f6290bd86169284169456a203b95f72a2b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f68696d656c616c692f7064662d67656e657261746f72)](https://camo.githubusercontent.com/929f9c11f171c84952541f216aa293f6290bd86169284169456a203b95f72a2b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f68696d656c616c692f7064662d67656e657261746f72) [![Forks](https://camo.githubusercontent.com/b1ed6158d8040528044a1fd11a2519ff7e1c2d47672a186e9387c5b13229405f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f68696d656c616c692f7064662d67656e657261746f72)](https://camo.githubusercontent.com/b1ed6158d8040528044a1fd11a2519ff7e1c2d47672a186e9387c5b13229405f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f68696d656c616c692f7064662d67656e657261746f72)

📄 PdfGenerator for Laravel
==========================

[](#-pdfgenerator-for-laravel)

PdfGenerator is a flexible and extensible PDF generation wrapper for Laravel that supports multiple drivers including **DomPDF**, **Snappy (wkhtmltopdf)**, **mPDF**, and **FPDF** — all with a unified interface.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#pdfgenerator-is-a-flexible-and-extensible-pdf-generation-wrapper-for-laravel-that-supports-multiple-drivers-including-dompdf-snappy-wkhtmltopdf-mpdf-and-fpdf--all-with-a-unified-interface)

🚀 Features
----------

[](#-features)

- Multiple driver support: `dompdf`, `snappy`, `mpdf`, `fpdf`
- Unified API for all drivers
- Configurable driver options
- Easily extendable with custom drivers
- Laravel service provider and config publishing
- Supports UTF-8, HTML5, CSS3, custom fonts, header/footer, margins, and more

---

📦 Installation
--------------

[](#-installation)

```
composer require himelali/pdf-generator
```

⚙️ Configuration
----------------

[](#️-configuration)

### 🧪 Laravel Version Compatibility

[](#-laravel-version-compatibility)

Depending on your Laravel version, register the service provider as follows:

#### Laravel 11+

[](#laravel-11)

Edit `bootstrap/providers.php`:

```
return [
    // Other providers...
    \Himelali\PdfGenerator\PdfServiceProvider::class,
];
```

#### Laravel 10 and below

[](#laravel-10-and-below)

```
'providers' => [
    // Other providers...
    \Himelali\PdfGenerator\PdfServiceProvider::class,
],
```

For older versions, register the alias manually in `config/app.php`:

```
'aliases' => Facade::defaultAliases()->merge([
    'Pdf' => Himelali\PdfGenerator\Facades\Pdf::class,
])->toArray(),
```

⚠️ If Facade::defaultAliases() doesn't exist in your Laravel version, just use:

```
'aliases' => [
    // Other aliases...
    'Pdf' => Himelali\PdfGenerator\Facades\Pdf::class,
],
```

#### The service provider will register the PDF manager and allow you to publish the config file using:

[](#the-service-provider-will-register-the-pdf-manager-and-allow-you-to-publish-the-config-file-using)

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

This will publish `config/pdf-generator.php`. Example configuration:

```
return [
    'default' => env('PDF_DRIVER', 'dompdf'),

    'drivers' => [
        'dompdf' => [
            'options' => [
                'is_html5_parser_enabled' => true,
                'is_php_enabled' => true,
            ],
        ],
        'snappy' => [
            'binary' => env('SNAPPY_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
            'options' => [
                'page-size' => 'A4',
                'margin-top' => '10mm',
                'margin-bottom' => '10mm',
                'footer-left' => 'Your Company Name',
                'footer-center' => '[page]',
                'footer-right' => 'Confidential',
            ],
        ],
        'mpdf' => [
            'format' => 'A4',
            'orientation' => 'P',
            'margin_top' => 10,
            'margin_bottom' => 10,
            'margin_left' => 10,
            'margin_right' => 10,
            'temp_dir' => storage_path('app/mpdf/temp'),
            'font_dir' => storage_path('app/pdf/fonts'),
        ],
        'fpdf' => [
            'orientation' => 'P',
            'unit' => 'mm',
            'format' => 'A4',
            'font_dir' => storage_path('app/pdf/fonts'),
        ],
    ],
];
```

🧩 Supported Drivers
-------------------

[](#-supported-drivers)

DriverPackage DependencyBinary Requireddompdf`dompdf/dompdf`❌snappy`knplabs/knp-snappy` + `wkhtmltopdf` binary [link](https://github.com/KnpLabs/snappy)✅mpdf`mpdf/mpdf`❌fpdf`setasign/fpdf`❌Install the required dependencies based on your driver.

```
use Pdf;

$html = 'Hello PDF';
Pdf::loadHtml($html)->download('hello.pdf');
```

```
Pdf::setPageSize('A4')
    ->setMargins(10, 15, 10, 15)
    ->setHeader('Header HTML')
    ->setFooter('Footer HTML')
    ->loadHtml('With Headers and Margins')
    ->download('report.pdf');
```

📂 Available Methods
-------------------

[](#-available-methods)

MethodDescription`setPageSize()`Set paper size (e.g., A4, Letter)`setMargins()`Set page margins (top, right, bottom, left)`setHeader()`Set HTML for header`setFooter()`Set HTML for footer`setFooterText()`Set simple text footer (fallback)`setPageNumbers()`Enable or disable page numbers`setFonts()`Load custom fonts`loadHtml()`Load HTML content`download()`Download the PDF`stream()`Stream the PDF in browser```
Pdf::extend('custom', \App\Pdf\CustomPdfDriver::class);
Pdf::driver('custom')->loadHtml('Custom Driver')->download();
```

❗Exceptions
-----------

[](#exceptions)

Exception ClassWhen it’s Thrown`BinaryNotFoundException`[wkhtmltopdf](https://wkhtmltopdf.org/) binary missing (Snappy only)`InvalidDriverException`Driver not found in config or map`PdfGenerationException`General rendering failure`RenderException`Library-specific render issues✅ Requirements
--------------

[](#-requirements)

- Laravel 6+
- PHP 7.1 or higher
- At least one supported PDF library installed ([dompdf](https://dompdf.github.io), [mpdf](https://mpdf.github.io), [knplabs/knp-snappy](https://github.com/KnpLabs/snappy), or [setasign/fpdf](https://www.fpdf.org/))

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.txt).

Please note: This is a wrapper around the following libraries, each of which is maintained under its own license:

- [dompdf/dompdf](https://github.com/dompdf/dompdf) – [LGPL-2.1-only](https://github.com/dompdf/dompdf/blob/master/LICENSE.LGPL)
- [mpdf/mpdf](https://github.com/mpdf/mpdf) – [GNU GPL v2](https://github.com/mpdf/mpdf/blob/development/LICENSE.txt)
- [knplabs/knp-snappy](https://github.com/KnpLabs/KnpSnappy) – [MIT License](https://github.com/KnpLabs/KnpSnappy/blob/master/LICENSE)
- [setasign/fpdf](http://www.fpdf.org/) – [Free to use, non-copyleft](http://www.fpdf.org/)

Make sure to review and comply with each library’s license if you use this package in your projects.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d90b16b5d6c09a340245d3dd62b67072af6657934ae8aface8090067ef69b07?d=identicon)[himelali](/maintainers/himelali)

---

Top Contributors

[![himelali](https://avatars.githubusercontent.com/u/13802501?v=4)](https://github.com/himelali "himelali (10 commits)")

### Embed Badge

![Health badge](/badges/himelali-pdf-generator/health.svg)

```
[![Health](https://phpackages.com/badges/himelali-pdf-generator/health.svg)](https://phpackages.com/packages/himelali-pdf-generator)
```

PHPackages © 2026

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