1. Go to this page and download the library: Download kartik-v/yii2-mpdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kartik-v / yii2-mpdf example snippets
use kartik\mpdf\Pdf;
public function actionReport() {
// get your HTML raw content without any layouts or scripts
$content = $this->renderPartial('_reportView');
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if
use kartik\mpdf\Pdf;
// ...
'components' => [
// setup Krajee Pdf component
'pdf' => [
'class' => Pdf::classname(),
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
// refer settings section for all configuration options
]
]