PHPackages                             misterspelik/laravel-pdf - 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. misterspelik/laravel-pdf

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

misterspelik/laravel-pdf
========================

Generate PDFs in Laravel with this mPDF wrapper.

2.2.0(1y ago)55190.5k↓56.3%10[4 issues](https://github.com/misterspelik/laravel-pdf/issues)[1 PRs](https://github.com/misterspelik/laravel-pdf/pulls)MITPHPPHP ^7.4 || ^8.0

Since Jul 21Pushed 1y ago2 watchersCompare

[ Source](https://github.com/misterspelik/laravel-pdf)[ Packagist](https://packagist.org/packages/misterspelik/laravel-pdf)[ Docs](https://github.com/misterspelik/laravel-pdf)[ RSS](/packages/misterspelik-laravel-pdf/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

[![Stable Version](https://camo.githubusercontent.com/5408b268415592912be3abe95a4eeda1be489a77b489b5f5467bfb5b1bff770d/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f762f737461626c65)](https://packagist.org/packages/misterspelik/laravel-pdf)[![Unstable Version](https://camo.githubusercontent.com/2ff7b97517601b670096fc369afcb4462b4df96fccd90b12387aa2b59f174062/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f762f756e737461626c65)](https://packagist.org/packages/misterspelik/laravel-pdf)[![License](https://camo.githubusercontent.com/27b2848c5fabc4fefccc465a3af4034c57aa02916467fd90521d4b1c168b6331/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f6c6963656e7365)](https://packagist.org/packages/misterspelik/laravel-pdf)[![Total Downloads](https://camo.githubusercontent.com/d31b0e19212fcb41426010b8ceea18b34abae0a4d0b4bb5e894507383618b3eb/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f646f776e6c6f616473)](https://packagist.org/packages/misterspelik/laravel-pdf)[![Monthly Downloads](https://camo.githubusercontent.com/3c748cd298af3708d8612f3f44e44c3de32f14b3c4ddacba4b3e8093503a1f89/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f642f6d6f6e74686c79)](https://packagist.org/packages/misterspelik/laravel-pdf)[![Daily Downloads](https://camo.githubusercontent.com/bb59103bcb1c857969287682dfc44aef580556b1ff35eec1a965d028648894e1/68747470733a2f2f706f7365722e707567782e6f72672f6d69737465727370656c696b2f6c61726176656c2d7064662f642f6461696c79)](https://packagist.org/packages/misterspelik/laravel-pdf)

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

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

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

Supported versions
------------------

[](#supported-versions)

Minimum supported version is Laravel 5

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

[](#installation)

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

```
composer require misterspelik/laravel-pdf

```

> 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

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

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

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

Now, you should publish package's config file to your config directory by using following command:

```
php artisan vendor:publish

```

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

Other methods
-------------

[](#other-methods)

It is also possible to use the following methods on the `pdf` object:

`output()`: Outputs the PDF as a string.
`save($filename)`: Save the PDF to a file
`download($filename)`: Make the PDF downloadable by the user.
`stream($filename)`: Return a response with the PDF to show in the browser.

Config
------

[](#config)

If you have published config file, you can change the default settings in `config/pdf.php` file:

```
return [
	'format'           => 'A4', // See https://mpdf.github.io/paging/page-size-orientation.html
	'author'           => 'John Doe',
	'subject'          => 'This Document will explain the whole universe.',
	'keywords'         => 'PDF, Laravel, Package, Peace', // Separate values with comma
	'creator'          => 'Laravel Pdf',
	'display_mode'     => 'fullpage',
];
```

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

```
PDF::loadView('pdf', $data, [], [
  'format' => 'A5-L'
])->save($pdfFilePath);
```

You can use a callback with the key 'instanceConfigurator' to access mpdf functions:

```
$config = ['instanceConfigurator' => function($mpdf) {
    $mpdf->SetImportUse();
    $mpdf->SetDocTemplate(/path/example.pdf, true);
}]

PDF::loadView('pdf', $data, [], $config)->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 [
	// ...
	'font_path' => base_path('resources/fonts/'),
	'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
			//'useOTL' => 0xFF,    // required for complicated langs like Persian, Arabic and Chinese
			//'useKashida' => 75,  // required for complicated langs like Persian, Arabic and Chinese
		]
		// ...add as many as you want.
	]
	// ...
];
```

*Note*: If you are using `laravel-pdf` for producing PDF documents in a complicated language (like Persian, Arabic or Chinese) you should have `useOTL` and `useKashida` indexes in your custom font definition array. If you do not use these indexes, your characters will be shown dispatched and incorrectly in the produced PDF.

Now you can use the font in CSS:

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

Custom Styles
-------------

[](#custom-styles)

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

```
return [
	//...
    'defaultCssFile' => base_path('public/css/pdf.css'),
];
```

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:

PDF Wrapper extension
---------------------

[](#pdf-wrapper-extension)

This package has own wrapper for the Mpdf\\Mpdf class. But it can be also overrided or extended on the project level.

There is a setting in the config file to use a custom PdfWrapper.

```
return [
    // ...
    'pdfWrapper' => 'misterspelik\LaravelPdf\Wrapper\PdfWrapper',
];
```

The only requirement that the wrapper must implement the interface `misterspelik\LaravelPdf\PdfInterface\PdfWrapperInterface`

Testing
-------

[](#testing)

To use the testing suite, you need some extensions and binaries for your local PHP. On macOS, you can install them like this:

```
brew install imagemagick ghostscript
pecl install imagick

```

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.8% 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 ~134 days

Total

5

Last Release

542d ago

Major Versions

1.1.0 → 2.0.02023-07-28

PHP version history (3 changes)1.0.0PHP &gt;=7.0

1.1.0PHP &gt;=7.4

2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f6e5ed1da722746fea0d5cfa7d98174419bfc9ed934dcdcb4e3b59d6f90c840?d=identicon)[misterspelik](/maintainers/misterspelik)

---

Top Contributors

[![niklasravnsborg](https://avatars.githubusercontent.com/u/6717303?v=4)](https://github.com/niklasravnsborg "niklasravnsborg (34 commits)")[![misterspelik](https://avatars.githubusercontent.com/u/3395617?v=4)](https://github.com/misterspelik "misterspelik (7 commits)")[![erfansahaf](https://avatars.githubusercontent.com/u/12012168?v=4)](https://github.com/erfansahaf "erfansahaf (6 commits)")[![daveismynamecom](https://avatars.githubusercontent.com/u/60222583?v=4)](https://github.com/daveismynamecom "daveismynamecom (5 commits)")[![stefanullrich](https://avatars.githubusercontent.com/u/3226657?v=4)](https://github.com/stefanullrich "stefanullrich (2 commits)")[![tezkerek](https://avatars.githubusercontent.com/u/12715035?v=4)](https://github.com/tezkerek "tezkerek (2 commits)")[![urielo](https://avatars.githubusercontent.com/u/10448109?v=4)](https://github.com/urielo "urielo (1 commits)")[![HarryTheWulf](https://avatars.githubusercontent.com/u/4353340?v=4)](https://github.com/HarryTheWulf "HarryTheWulf (1 commits)")[![ianmustafa](https://avatars.githubusercontent.com/u/5209746?v=4)](https://github.com/ianmustafa "ianmustafa (1 commits)")[![PanovAlexey](https://avatars.githubusercontent.com/u/15037622?v=4)](https://github.com/PanovAlexey "PanovAlexey (1 commits)")[![pavinthan](https://avatars.githubusercontent.com/u/13897936?v=4)](https://github.com/pavinthan "pavinthan (1 commits)")[![DanieliMi](https://avatars.githubusercontent.com/u/31039652?v=4)](https://github.com/DanieliMi "DanieliMi (1 commits)")

---

Tags

laravelmpdfpdfpdf-generationlaravelpdfmpdf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/misterspelik-laravel-pdf/health.svg)

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[laravel/nightwatch

The official Laravel Nightwatch package.

36210.1M36](/packages/laravel-nightwatch)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3856.2M31](/packages/gotenberg-gotenberg-php)

PHPackages © 2026

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