PHPackages                             robregonm/yii2-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. robregonm/yii2-pdf

ActiveYii2-extension[PDF &amp; Document Generation](/categories/documents)

robregonm/yii2-pdf
==================

Yii 2 PDF Response Formatter

1.1.0(6y ago)4647.5k↑55.6%37[9 issues](https://github.com/robregonm/yii2-pdf/issues)1BSD-3-ClausePHPPHP ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0

Since Sep 26Pushed 6y ago7 watchersCompare

[ Source](https://github.com/robregonm/yii2-pdf)[ Packagist](https://packagist.org/packages/robregonm/yii2-pdf)[ RSS](/packages/robregonm-yii2-pdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (1)

Yii2-PDF
========

[](#yii2-pdf)

PDF formatter for Yii2 using mPDF library.

This extension "format" HTML responses to PDF files (by default Yii2 includes HTML, JSON and XML formatters). Great for reports in PDF format using HTML views/layouts.

\##Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require robregonm/yii2-pdf "*"

```

or add

```
"robregonm/yii2-pdf": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, modify your application configuration to include:

```
return [
	'components' => [
		...
		'response' => [
			'formatters' => [
				'pdf' => [
					'class' => 'robregonm\pdf\PdfResponseFormatter',
					'mode' => '', // Optional
					'format' => 'A4',  // Optional but recommended. http://mpdf1.com/manual/index.php?tid=184
					'defaultFontSize' => 0, // Optional
					'defaultFont' => '', // Optional
					'marginLeft' => 15, // Optional
					'marginRight' => 15, // Optional
					'marginTop' => 16, // Optional
					'marginBottom' => 16, // Optional
					'marginHeader' => 9, // Optional
					'marginFooter' => 9, // Optional
					'orientation' => 'Landscape', // optional. This value will be ignored if format is a string value.
					'options' => [
						// mPDF Variables
						// 'fontdata' => [
							// ... some fonts. http://mpdf1.com/manual/index.php?tid=454
						// ]
					]
				],
			]
		],
		...
	],
];
```

In the controller:

```
class MyController extends Controller {
	public function actionPdf(){
		Yii::$app->response->format = 'pdf';

		// Rotate the page
		Yii::$container->set(Yii::$app->response->formatters['pdf']['class'], [
			'format' => [216, 356], // Legal page size in mm
			'orientation' => 'Landscape', // This value will be used when 'format' is an array only. Skipped when 'format' is empty or is a string
			'beforeRender' => function($mpdf, $data) {},
			]);

		$this->layout = '//print';
		return $this->render('myview', []);
	}
}
```

License
-------

[](#license)

Yii2-Pdf is released under the BSD-3 License. See the bundled `LICENSE.md` for details.

Useful URLs
===========

[](#useful-urls)

- [mPDF Manual](http://mpdf1.com/manual/index.php)

Enjoy!

[![Flattr this git repo](https://camo.githubusercontent.com/7e3f46a36526479d701ef7f90a0f8c3ac2fbab3087446e2a9fceed75cd1ab802/687474703a2f2f6170692e666c617474722e636f6d2f627574746f6e2f666c617474722d62616467652d6c617267652e706e67)](https://flattr.com/submit/auto?user_id=robregonm&url=https://github.com/robregonm/yii2-pdf&title=Yii2-PDF&language=&tags=github&category=software)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 77.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 ~443 days

Total

5

Last Release

2481d ago

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

1.0.2PHP &gt;=5.4.0 &lt;7.0.0

1.1.0PHP ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c856ae829dc0d11e64f7142022edf7cfe49850341d99978a00b273aea3c72828?d=identicon)[robregonm](/maintainers/robregonm)

---

Top Contributors

[![robregonm](https://avatars.githubusercontent.com/u/1051457?v=4)](https://github.com/robregonm "robregonm (21 commits)")[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (2 commits)")[![Julian-B90](https://avatars.githubusercontent.com/u/4377396?v=4)](https://github.com/Julian-B90 "Julian-B90 (2 commits)")[![lgualtieri75](https://avatars.githubusercontent.com/u/1993497?v=4)](https://github.com/lgualtieri75 "lgualtieri75 (1 commits)")[![machour](https://avatars.githubusercontent.com/u/304450?v=4)](https://github.com/machour "machour (1 commits)")

---

Tags

responseformatterpdfyii2yiireportsdocuments

### Embed Badge

![Health badge](/badges/robregonm-yii2-pdf/health.svg)

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

###  Alternatives

[kartik-v/yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.

1605.5M84](/packages/kartik-v-yii2-mpdf)[borales/yii-pdf

Yii-wrapper for PHP-PDF libraries (mPDF, HTML2PDF)

60109.1k](/packages/borales-yii-pdf)[yii2assets/yii2-pdfjs

Yii2 Extension pdf.js Portable Document Format (PDF) viewer

23209.3k](/packages/yii2assets-yii2-pdfjs)[phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

158.9k](/packages/phpnt-yii2-export)

PHPackages © 2026

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