PHPackages                             trianity/laravel-mpdf - 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. trianity/laravel-mpdf

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

trianity/laravel-mpdf
=====================

Laravel integration for generating PDF documents with mPDF.

3.0.0(today)20MITPHPPHP ^8.4CI passing

Since Apr 21Pushed todayCompare

[ Source](https://github.com/trianity/laravel-mpdf)[ Packagist](https://packagist.org/packages/trianity/laravel-mpdf)[ Docs](https://github.com/trianity/laravel-mpdf)[ Fund](https://www.paypal.me/mccarlosen)[ RSS](/packages/trianity-laravel-mpdf/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (6)Versions (18)Used By (0)

Laravel mPDF
============

[](#laravel-mpdf)

Laravel integration for [mPDF](https://mpdf.github.io/), maintained in the [Trianity GitHub repository](https://github.com/trianity/laravel-mpdf). It provides a small wrapper for generating PDF files from HTML, files, and Laravel views.

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

[](#requirements)

- PHP 8.4 or newer
- Laravel 12 or 13 (the package uses `illuminate/support`)
- mPDF 8.3.x

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

[](#installation)

```
composer require trianity/laravel-mpdf
```

The service provider and `PDF` facade are registered automatically by Laravel package discovery.

Dependency injection is also supported:

```
use Trianity\LaravelMpdf\LaravelMpdfWrapper;

public function show(LaravelMpdfWrapper $pdf)
{
    return $pdf->loadHTML('Hello')->output();
}
```

Usage
-----

[](#usage)

```
use Trianity\LaravelMpdf\Facades\PDF;

class ReportController
{
    public function show()
    {
        $pdf = PDF::loadView('pdf.document', ['name' => 'World']);

        $pdf->stream('document.pdf');
    }
}
```

The wrapper supports the following methods:

```
PDF::loadHTML('Hello');
PDF::loadFile(storage_path('app/document.html'));
PDF::loadView('pdf.document', $data);

PDF::chunkLoadHTML($html, '');
PDF::chunkLoadFile($file, '');
PDF::chunkLoadView('pdf.document', '', $data);
```

Chunk methods split the rendered HTML at the supplied separator and write each part separately. This can help with large HTML documents and PCRE backtrack limits. The separator must not be an empty string.

The returned `LaravelMpdf` instance provides:

```
$pdf->output();                         // Return the PDF as a string
$pdf->save($path);                      // Save the PDF and return $path
$pdf->download('document.pdf');         // Send it as a download
$pdf->stream('document.pdf');           // Send it inline
$pdf->getMpdf()->AddPage();             // Access the underlying mPDF instance
$pdf->WriteHTML('More HTML');
```

`output()` returns the PDF contents. `save()` returns the supplied path. `download()` and `stream()` send the PDF directly through mPDF and return nothing.

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

[](#configuration)

Publish the configuration file with:

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

The published file is `config/pdf.php`. It contains the mPDF defaults used by the wrapper, including page format, margins, fonts, language detection, watermarks, PDF/A, and temporary directory settings.

Configuration can also be overridden for an individual document. The per-document values take precedence over the application configuration:

```
$pdf = PDF::loadView('pdf.document', $data, [], [
    'format' => 'A5',
    'orientation' => 'L',
    'title' => 'Another title',
]);
```

### Custom fonts

[](#custom-fonts)

Set a font directory and font data in `config/pdf.php`:

```
return [
    'custom_font_dir' => base_path('resources/fonts'),
    'custom_font_data' => [
        'examplefont' => [
            'R' => 'ExampleFont-Regular.ttf',
            'B' => 'ExampleFont-Bold.ttf',
            'I' => 'ExampleFont-Italic.ttf',
            'BI' => 'ExampleFont-Bold-Italic.ttf',
        ],
    ],
];
```

Use the font in your HTML/CSS as `font-family: examplefont;`.

Headers and footers
-------------------

[](#headers-and-footers)

mPDF headers and footers can be defined in the HTML and CSS passed to the wrapper:

```
Your header
Page {PAGENO}
```

```
@page {
    header: page-header;
    footer: page-footer;
}
```

See the [mPDF documentation](https://mpdf.github.io/) for the complete list of supported HTML, CSS, and configuration options.

Testing
-------

[](#testing)

Install the development dependencies and run the complete local check with:

```
composer install
composer check
```

The check runs Pest, Larastan/PHPStan, and Pint.

Attribution
-----------

[](#attribution)

The package has an earlier history in the [Trianity GitHub repository](https://github.com/trianity/laravel-mpdf). The previous clone was abandoned and the current codebase was rewritten by Trianity while preserving the supported public API and configuration behavior.

The source still contains the original `Carlos Meneses` author attribution. The current package namespace and maintenance are provided by Trianity.

Notes
-----

[](#notes)

mPDF may block while fetching external HTTP resources when the application runs on a single-threaded server such as `php -S` or `artisan serve`. Use a production web server for applications that need external resources.

License
-------

[](#license)

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

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~494 days

Total

14

Last Release

0d ago

Major Versions

v1.1 → 2.0.02018-11-28

2.1.8 → 3.0.02026-08-28

PHP version history (5 changes)v1.0PHP &gt;=5.4.0

2.0.0PHP &gt;=7.0.0

2.1.6PHP ^8.0

2.1.7PHP ^7.4|^8.0

3.0.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6353141?v=4)[István Holbok](/maintainers/trianity)[@trianity](https://github.com/trianity)

---

Top Contributors

[![mccarlosen](https://avatars.githubusercontent.com/u/8524361?v=4)](https://github.com/mccarlosen "mccarlosen (39 commits)")[![mccarlosen-design](https://avatars.githubusercontent.com/u/273206368?v=4)](https://github.com/mccarlosen-design "mccarlosen-design (18 commits)")[![abumosaab](https://avatars.githubusercontent.com/u/3581324?v=4)](https://github.com/abumosaab "abumosaab (14 commits)")[![pindab0ter](https://avatars.githubusercontent.com/u/5128166?v=4)](https://github.com/pindab0ter "pindab0ter (7 commits)")[![webmasterpacifico](https://avatars.githubusercontent.com/u/22247174?v=4)](https://github.com/webmasterpacifico "webmasterpacifico (5 commits)")[![trianity](https://avatars.githubusercontent.com/u/6353141?v=4)](https://github.com/trianity "trianity (4 commits)")[![danielrona](https://avatars.githubusercontent.com/u/1699775?v=4)](https://github.com/danielrona "danielrona (3 commits)")[![rabrowne85](https://avatars.githubusercontent.com/u/8293543?v=4)](https://github.com/rabrowne85 "rabrowne85 (2 commits)")[![MortezaPoussaneh](https://avatars.githubusercontent.com/u/49806042?v=4)](https://github.com/MortezaPoussaneh "MortezaPoussaneh (2 commits)")[![mudasserzahid](https://avatars.githubusercontent.com/u/16418084?v=4)](https://github.com/mudasserzahid "mudasserzahid (2 commits)")[![abronin](https://avatars.githubusercontent.com/u/1532185?v=4)](https://github.com/abronin "abronin (1 commits)")[![dsturm](https://avatars.githubusercontent.com/u/384815?v=4)](https://github.com/dsturm "dsturm (1 commits)")[![ali-alharthi](https://avatars.githubusercontent.com/u/29173253?v=4)](https://github.com/ali-alharthi "ali-alharthi (1 commits)")[![tamer-dev](https://avatars.githubusercontent.com/u/434489?v=4)](https://github.com/tamer-dev "tamer-dev (1 commits)")[![finwe](https://avatars.githubusercontent.com/u/195675?v=4)](https://github.com/finwe "finwe (1 commits)")

---

Tags

laravelpdfmpdf

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/trianity-laravel-mpdf/health.svg)

```
[![Health](https://phpackages.com/badges/trianity-laravel-mpdf/health.svg)](https://phpackages.com/packages/trianity-laravel-mpdf)
```

###  Alternatives

[rockett/weasyprint

A feature-rich WeasyPrint wrapper for generating PDFs from HTML and CSS, with support for PDF/A, PDF/UA, attachments, and optional Laravel integration.

29233.1k](/packages/rockett-weasyprint)

PHPackages © 2026

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