PHPackages                             danielfnz/laravel-dompdf - 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. danielfnz/laravel-dompdf

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

danielfnz/laravel-dompdf
========================

Generate PDFs in Laravel with this mPDF wrapper.

v1.4.3(9y ago)021MITPHPPHP &gt;=5.4.0

Since Apr 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/danielfnz/laravel-pdf)[ Packagist](https://packagist.org/packages/danielfnz/laravel-dompdf)[ RSS](/packages/danielfnz-laravel-dompdf/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (13)Used By (0)

Laravel PDF: mPDF wrapper for Laravel 5
=======================================

[](#laravel-pdf-mpdf-wrapper-for-laravel-5)

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

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

[](#installation)

Require this package in your `composer.json` or install it by running:

```
composer require niklasravnsborg/laravel-pdf

```

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

```
'providers' => [
	// ...
	niklasravnsborg\LaravelPdf\PdfServiceProvider::class
]
```

```
'aliases' => [
	// ...
	'PDF' => niklasravnsborg\LaravelPdf\Facades\Pdf::class
]
```

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

[](#basic-usage)

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

```
use PDF;

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
];
```

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_path' => 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;
}
```

Set Protection
--------------

[](#set-protection)

To set protection, you just call the `SetProtection()` method and pass an array with permissions, an user password and an owner password.

The passwords are optional.

There are a fews permissions: `'copy'`, `'print'`, `'modify'`, `'annot-forms'`, `'fill-forms'`, `'extract'`, `'assemble'`, `'print-highres'`.

```
use PDF;

function generate_pdf() {
	$data = [
		'foo' => 'bar'
	];
	$pdf = PDF::loadView('pdf.document', $data);
	$pdf->SetProtection(['copy', 'print'], '', 'pass');
	return $pdf->stream('document.pdf');
}
```

Find more information to `SetProtection()` here:

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~24 days

Recently: every ~4 days

Total

12

Last Release

3404d ago

### Community

---

Top Contributors

[![niklasravnsborg](https://avatars.githubusercontent.com/u/6717303?v=4)](https://github.com/niklasravnsborg "niklasravnsborg (20 commits)")[![danielfnz](https://avatars.githubusercontent.com/u/6144301?v=4)](https://github.com/danielfnz "danielfnz (1 commits)")[![urielo](https://avatars.githubusercontent.com/u/10448109?v=4)](https://github.com/urielo "urielo (1 commits)")

### Embed Badge

![Health badge](/badges/danielfnz-laravel-dompdf/health.svg)

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

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.2k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M100](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M128](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

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