<commit_before>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 "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:

```php
return [
	'components' => [
		...
		'response' => [
			'formatters' => [
				'pdf' => [
					'class' => 'robregonm\pdf\PdfResponseFormatter',
					'mode' => '',
					'format' => 'A4',
					'defaultFontSize' => 0,
					'defaultFont' => '',
					'marginLeft' => 15,
					'marginRight' => 15,
					'marginTop' => 16,
					'marginBottom' => 16,
					'marginHeader' => 9,
					'marginFooter' => 9,
					'orientation' => 'Landscape',
					'options' => [
						// mPDF Variables
					]
				],
			]
		],
		...
	],
];
```

In the controller:

```php

class MyController extends Controller {
	public function actionPdf(){
		Yii::$app->response->format = 'pdf';
		
		//Can you it if needed to rotate the page
		Yii::$container->set(Yii::$app->response->formatters['pdf']['class'], [
			'orientation' => 'Landscape',
			'beforeRender' => function($mpdf, $data) {},
			]);
		
		$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

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

Enjoy!

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=robregonm&url=https://github.com/robregonm/yii2-pdf&title=Yii2-PDF&language=&tags=github&category=software) <commit_msg>Added some documentation to README file<commit_after>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 "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:

```php
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. Skipped when format includes "-L" suffix
					'options' => [
						// mPDF Variables
						'fontdata' => [
							// ... some fonts. http://mpdf1.com/manual/index.php?tid=454
						]
					]
				],
			]
		],
		...
	],
];
```

In the controller:

```php

class MyController extends Controller {
	public function actionPdf(){
		Yii::$app->response->format = 'pdf';
		
		//Can you it if needed to rotate the page
		Yii::$container->set(Yii::$app->response->formatters['pdf']['class'], [
			'orientation' => 'Landscape', // Only valid if "format" has NOT set "-L" or "-P" suffix
			'beforeRender' => function($mpdf, $data) {},
			]);
		
		$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

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

Enjoy!

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=robregonm&url=https://github.com/robregonm/yii2-pdf&title=Yii2-PDF&language=&tags=github&category=software) 
{'fraction_non_alphanumeric': 0.17298150654036987, 'fraction_numerical': 0.011727559765448805, 'mean_word_length': 3.3954410307234886, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 56, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2509860', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1467, 'n_words': 364}