Class 'mPDF' not found


}

        return $this->_mpdf;

    }

 

    /**

     * Sets the mPDF API instance

     */

    public function setApi()

    {

        $this->_mpdf = new mPDF(

            $this->mode,

            $this->format,

            $this->defaultFontSize,

            $this->defaultFont,

            $this->marginLeft,

            $this->marginRight,

            $this->marginTop,

            $this->marginBottom,

            $this->marginHeader,







i am install mpdf widget, during installation it gives error “Class ‘mPDF’ not found” .

please give me a solution to solve this problem

thanks

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




 Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;



then look at the example of Widget Type Usage on http://demos.krajee.com/mpdf.

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.




<table>

 <tr>

   <th>ID</th>

   <th>Customer</th>

   <th>Total</th>

  </tr>

  <tr>

    <td><?= $model->id; ?></td>

    <td><?= $model->customer; ?></td>

    <td><?= $model->total; ?></td>

  </tr>

</table>



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(); 

}