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

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

joaozica/laravel-mpdf
=====================

Laravel Mpdf: Using Mpdf in Laravel to generate Pdfs.

2.1.6(5y ago)0296MITPHPPHP ^8.0

Since Apr 21Pushed 4y agoCompare

[ Source](https://github.com/joaozica/laravel-mpdf)[ Packagist](https://packagist.org/packages/joaozica/laravel-mpdf)[ RSS](/packages/joaozica-laravel-mpdf/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (14)Used By (0)

Laravel Mpdf: Using Mpdf in Laravel for generate Pdfs
=====================================================

[](#laravel-mpdf-using-mpdf-in-laravel-for-generate-pdfs)

> Easily generate PDF documents from HTML right inside of Laravel using this mpdf wrapper.

Important Notes
---------------

[](#important-notes)

> Currently supported mpdf version `8.0` with FPDF version 2 and PHP version &gt;= 7.0

> mPDF will timeout on [fetching external HTTP resources](https://github.com/mpdf/mpdf#known-server-caveats) when using single-threaded servers such as `php -S` or `artisan serve`. Use a proper webserver for full functionality.

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

[](#installation)

Require this package in your `composer.json`

```
"require": {
	joaozica/laravel-mpdf: "2.1.6"
}

```

or install it by running:

```
composer require joaozica/laravel-mpdf

```

To start using Laravel, add the Service Provider and the Facade to your `config/app.php`:

```
'providers' => [
	// ...
	Meneses\LaravelMpdf\LaravelMpdfServiceProvider::class
]
```

```
'aliases' => [
	// ...
	'PDF' => Meneses\LaravelMpdf\Facades\LaravelMpdf::class
]
```

> Note: This package supports auto-discovery features of Laravel 5.5+, You only need to manually add the service provider and alias if working on Laravel version lower then 5.5

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

[](#basic-usage)

To use Laravel Mpdf add something like this to one of your controllers. You can pass data to a view in `/resources/views`.

```
//....
use PDF;
class ReportController extends Controller {
	public function generate_pdf()
	{
		$data = [
			'foo' => 'bar'
		];
		$pdf = PDF::loadView('pdf.document', $data);
		return $pdf->stream('document.pdf');
	}
}
```

Config
------

[](#config)

You can use a custom file to overwrite the default configuration. Just create `config/pdf.php` and add this:

```
return [
	'mode'                 => '',
	'format'               => 'A4',
	'default_font_size'    => '12',
	'default_font'         => 'sans-serif',
	'margin_left'          => 10,
	'margin_right'         => 10,
	'margin_top'           => 10,
	'margin_bottom'        => 10,
	'margin_header'        => 0,
	'margin_footer'        => 0,
	'orientation'          => 'P',
	'title'                => 'Laravel mPDF',
	'author'               => '',
	'watermark'            => '',
	'show_watermark'       => false,
	'watermark_font'       => 'sans-serif',
	'display_mode'         => 'fullpage',
	'watermark_text_alpha' => 0.1,
	'custom_font_dir'      => '',
	'custom_font_data' 	   => [],
	'auto_language_detection'  => false,
	'temp_dir'               => rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR),
	'pdfa' 			=> false,
        'pdfaauto' 		=> false,
];
```

To override this configuration on a per-file basis use the fourth parameter of the initializing call like this:

```
PDF::loadView('pdf', $data, [], [
  'title' => 'Another Title',
  'margin_top' => 0
])->save($pdfFilePath);
```

Headers and Footers
-------------------

[](#headers-and-footers)

If you want to have headers and footers that appear on every page, add them to your `` tag like this:

```

	Your Header Content

	Your Footer Content

```

Now you just need to define them with the name attribute in your CSS:

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

Inside of headers and footers `{PAGENO}` can be used to display the page number.

Included Fonts
--------------

[](#included-fonts)

By default you can use all the fonts [shipped with Mpdf](https://mpdf.github.io/fonts-languages/available-fonts-v6.html).

Custom Fonts
------------

[](#custom-fonts)

You can use your own fonts in the generated PDFs. The TTF files have to be located in one folder, e.g. `resources/fonts/`. Add this to your configuration file (`/config/pdf.php`):

```
return [
	'custom_font_dir' => base_path('resources/fonts/'), // don't forget the trailing slash!
	'custom_font_data' => [
		'examplefont' => [
			'R'  => 'ExampleFont-Regular.ttf',    // regular font
			'B'  => 'ExampleFont-Bold.ttf',       // optional: bold font
			'I'  => 'ExampleFont-Italic.ttf',     // optional: italic font
			'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
		]
		// ...add as many as you want.
	]
];
```

Now you can use the font in CSS:

```
body {
	font-family: 'examplefont', sans-serif;
}
```

Get instance your Mpdf
----------------------

[](#get-instance-your-mpdf)

You can access all mpdf methods through the mpdf instance with `getMpdf()`.

```
use PDF;

$pdf = PDF::loadView('pdf.document', $data);
$pdf->getMpdf()->AddPage(...);
```

Chunk HTML
----------

[](#chunk-html)

For big HTML you might get `Uncaught Mpdf\MpdfException: The HTML code size is larger than pcre.backtrack_limit xxx` error, or you might just get [empty or blank result](https://mpdf.github.io/troubleshooting/known-issues.html#blank-pages-or-some-sections-missing). In these situations you can use chunk methods while you added a separator to your HTML:

```
//....
use PDF;
class ReportController extends Controller {
	public function generate_pdf()
	{
		$data = [
			'foo' => 'hello 1',
            'bar' => 'hello 2'
		];
		$pdf = PDF::chunkLoadView('', 'pdf.document', $data);
		return $pdf->stream('document.pdf');
	}
}
```

```

    Hello World

        {{ $foo }}

        {{ $bar }}

```

License
-------

[](#license)

Laravel Mpdf is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

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

Recently: every ~159 days

Total

11

Last Release

1834d ago

Major Versions

v1.1 → 2.0.02018-11-28

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

2.0.0PHP &gt;=7.0.0

2.1.6PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/51ef961d09df0f682f34a68c05e2f5f27529540125154be2018ea25d1ac7ab78?d=identicon)[joaozica](/maintainers/joaozica)

---

Top Contributors

[![mccarlosen](https://avatars.githubusercontent.com/u/8524361?v=4)](https://github.com/mccarlosen "mccarlosen (37 commits)")[![abumosaab](https://avatars.githubusercontent.com/u/3581324?v=4)](https://github.com/abumosaab "abumosaab (14 commits)")[![joaozica](https://avatars.githubusercontent.com/u/1273441?v=4)](https://github.com/joaozica "joaozica (7 commits)")[![mccarlosen-design](https://avatars.githubusercontent.com/u/273206368?v=4)](https://github.com/mccarlosen-design "mccarlosen-design (7 commits)")[![webmasterpacifico](https://avatars.githubusercontent.com/u/22247174?v=4)](https://github.com/webmasterpacifico "webmasterpacifico (5 commits)")[![danielrona](https://avatars.githubusercontent.com/u/1699775?v=4)](https://github.com/danielrona "danielrona (3 commits)")[![mudasserzahid](https://avatars.githubusercontent.com/u/16418084?v=4)](https://github.com/mudasserzahid "mudasserzahid (2 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)")[![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)")[![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

### Embed Badge

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

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

###  Alternatives

[carlos-meneses/laravel-mpdf

Laravel Mpdf: Using Mpdf in Laravel to generate Pdfs.

4403.1M7](/packages/carlos-meneses-laravel-mpdf)

PHPackages © 2026

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