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!
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'
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', ], ], ],
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:
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.
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
@Виталий 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.
Google Chart
Hi!
First I want to thank you for your work !!
I need to create a pdf with some Google Charts but this not render the image.
I have modified the the module i use for Google Chart (Link) to render as an PNG image and it works only when render the view as HTML but not in PDF, also, i tried to include the
<img src="data:image/png;base64,iVBORw0KGg.....">
tag in the view and this work in HTML and PDF too.
I am also open to alternative or different ways to generate a PDF with Goochar Chart
Coogle Chart Native
Google Chart as PNG
PDF render
PDF with tag inline and Google Chart generated
PDF is not rendering
Hello,
I have installed the extension via composer, and added the component code into the common/config/main.php file and added the function into the my controller file. But its not working, how the pdf will be created of the form. Please help me out asap.
Thanks in advance.
Hi,
How do i can set the document's page orientation with this extension and how do i can set a page's footer for a document in this section on config/web.php?
'pdf' => [
'class' => 'robregonm\pdf\PdfResponseFormatter', 'mode' => '', // Optional 'format' => 'letter', // Optional but recommended. http://mpdf1.com/manual/index.php?tid=184 'defaultFontSize' => 11, // Optional 'defaultFont' => '', // Optional 'marginLeft' => 15, // Optional 'marginRight' => 15, // Optional 'marginTop' => 20, // Optional 'marginBottom' => 15, // Optional 'marginHeader' => 10, // Optional 'marginFooter' => 10, // Optional 'orientation' => 'Landscape', // optional. This value will be ignored if format is a string value. ** 'options' => [ 'title' => 'Document', // mPDF Variables // 'fontdata' => [ // ... some fonts. http://mpdf1.com/manual/index.php?tid=454 // ] ]** ],
Thanks for your help...
robregonm/yii2-pdf dev-master requires php ^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 -> your php version (7.4.28) does not satisfy that requirement.
Is this correct?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.