caijq4ever / yii2-pdf
A yii2 wrapper for wkhtmltopdf
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 106
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2019-10-06 00:50:09 UTC
README
A yii2 wrapper for wkhtmltopdf
Requirements
Installation
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist caijq4ever/yii2-pdf "dev-master"
or add
"caijq4ever/yii2-pdf": "dev-master"
to the require section of your composer.json
file.
Usage
1.Edit config/web.php
file
'components' => [ ... 'pdf' => [ 'class' => 'junqi\pdf\Pdf', 'tmpDir' => '@runtime/pdf/', 'options' => [ 'headerLeft' => 'world,hello', 'headerLine' => true, //more options see `wkhtmltopdf -H` ], ], ... ],
2.Add following code somewhere in your yii2 project
2.1.Just get file
$html = <<<HTML <h1>hello,world</h1> HTML; try { $fileName = Yii::$app->pdf ->loadHtml($html) ->execute() ->getFile('test.pdf'); echo $fileName; } catch (\junqi\pdf\PdfException $e) { echo $e->getMessage(); }
2.2.Download file with browser
$html = <<<HTML <h1>hello,world</h1> HTML; try { Yii::$app->pdf ->loadHtml($html) ->execute() ->sendFile('test.pdf'); } catch (\junqi\pdf\PdfException $e) { echo $e->getMessage(); }