I had some trouble with this as well. I got it to work in the following way;
I added kartik-v/yii2-mpdf : "*" at the end of the require section of composer.json from the app root directory, then with command window ran composer update.
Once installed try a test action in SiteController. You will have to start with
To output variable info based on a model, let’s say you have a model “Invoice” with attributes, id, customer, and total. Make a view file, say ‘invoice.php’, that will display the data in html.
The link to your controller action(we’ll call the action ‘pdf’) will need to pass the id -…invoice/pdf/id#
In InvoiceController
use kartik\mpdf\Pdf;
--------------------------
public function actionPdf($id)
{
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$model = $this->findModel($id)
$content = $this->renderPartial('invoice',['model'=>$model]);
//Then set up pdf
$pdf = new Pdf([
//only some of the options shown here
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $content,
]
]);
return $pdf->render();
}