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

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

bob/laravel-pdf
===============

Generate PDFs in Laravel with this mPDF wrapper.

v3.0.0(1y ago)09MITPHPPHP &gt;=7.4| ^8.1 | ^8.2 | ^8.3

Since Sep 22Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

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

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

> 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 bob/laravel-pdf

```

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',
	'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.
	]
	// ...
];
```

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

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:

```

## License

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

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

603d ago

### Community

Maintainers

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

---

Top Contributors

[![Khabweri](https://avatars.githubusercontent.com/u/114258686?v=4)](https://github.com/Khabweri "Khabweri (11 commits)")

---

Tags

laravelpdfmpdf

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
