Yii 2.0: yii2-pdf

PDF Reports from HTML Views (Html to PDF formatter)
5 followers

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 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!

Total 5 comments

#18601 report it
robregonm at 2014/11/27 05:56pm
@Виталий Fixed

This kind of bugs have been already fixed in the latest version. Please, check it out. Feel free to report any bugs you find.

#17414 report it
piero villata at 2014/06/08 12:40pm
example complete plis

please hava a example for export pfd views completes ad render_partial. Sorry iam new in mpdf. I are integrated with warrence crud extension and yii2-kartik extensions

#17340 report it
Виталий at 2014/05/26 10:28pm
can`t install

c:\xampp\htdocs\yii2adv>c:\xampp\php\php composer.phar require robregonm/yii2-pdf "dev-master" ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

Problem 1 - Installation request for robregonm/yii2-pdf dev-master -> satisfiable by robregonm/yii2-pdf[dev-master]. - robregonm/yii2-pdf dev-master requires yiisoft/yii2-composer dev-master -> no matching package found.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Installation failed, reverting ./composer.json to its original content.

#17320 report it
Huss at 2014/05/22 07:17pm
Unsupported response format

Solution was to add the html response formatter - only required if your application uses a mix of response formats.

'response' => [
            'formatters' => [
                'html' => [
                    'class' => 'yii\web\HtmlResponseFormatter',
                ],
                'pdf' => [
                    'class' => 'robregonm\pdf\PdfResponseFormatter',
                ],
            ],
        ],
#17315 report it
Huss at 2014/05/22 04:38am
Unsupported response format

Im having a problem with this config

'response' => [
            'formatters' => [
                'pdf' => [
                    'class' => 'robregonm\pdf\PdfResponseFormatter',
                ],
            ],
        ],

exception 'yii\base\InvalidConfigException' with message 'Unsupported response format: html'

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet