0

How to make when user click the profile button,it will display in pdf file. I've install the mpdf extension. Below is the code that I try to convert personalinfo.php page to pdf.

class MpdfController extends Controller
{
    public function actionPersonalinfo() {
        // Your SQL query here
        $content = $this->renderPartial('personalinfo', ['model' => $model]);

        // 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/assets/kv-mpdf-bootstrap.min.css',
            // any css to be embedded if required
            'cssInline' => '.kv-heading-1{font-size:18px}',
            // set mPDF properties on the fly
            'options' => ['title' => 'ProfileStudent'],
            // call mPDF methods on the fly
            'methods' => [
                'SetHeader'=>['Profile'],
                'SetFooter'=>['{PAGENO}'],
            ]
        ]);

        /*------------------------------------*/
        Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
        $headers = Yii::$app->response->headers;
        $headers->add('Content-Type', 'application/pdf');
        /*------------------------------------*/

        // return the pdf output as per the destination setting
        return $pdf->render();
    }
    ...
}

Thanks

marche
  • 1,756
  • 1
  • 14
  • 24
Fyp16
  • 131
  • 1
  • 5
  • 16

1 Answers1

0

Seem that you don't have model. try passing the id when you call this action and use the id for retrieve info in $model

public function actionPersonalinfo($id) {

  $model = $this->findModel($id);


  $content = $this->renderPartial('personalinfo', ['model' => $model]);

  // setup kartik\mpdf\Pdf component
  $pdf = new Pdf([
  // set to use core fonts only
  'mode' => Pdf::MODE_CORE,
  ....
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107