yii2-pdf PDF Reports from HTML Views (Html to PDF formatter)

Yii2-Pdf

  1. Installation
  2. Usage
  3. License

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 reporting in PDF format using HTML views/layouts.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require robregonm/yii2-pdf "dev-master"

or add

"robregonm/yii2-pdf": "dev-master"

to the require section of your composer.json file.

Usage

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

return [
	'components' => [
		...
		'response' => [
			'formatters' => [
				'pdf' => [
					'class' => 'robregonm\pdf\PdfResponseFormatter',
				],
			]
		],
		...
	],
];

In the controller:

class MyController extends Controller {
	public function actionPdf(){
		Yii::$app->response->format = 'pdf';
		$this->layout = '//print';
		return $this->render('myview', []);
	}
}

License

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

Useful URLs

Enjoy!

3 0
7 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: Others
Developed by: robregonm
Created on: May 15, 2014
Last updated: 10 years ago

Related Extensions