protected function getPdfResponse($action, $result, $params)
    {
        if (Yii::$app->response->format !== Response::FORMAT_PDF) {
            return false;
        }
        $headers = Yii::$app->response->getHeaders();
        if (($location = $headers->get('Location')) !== null) {
            return $this->redirect($location);
        }
        $content = Yii::$app->request->isAjax
            ? $this->renderAjax($action->viewName, $params)
            : $this->render($action->viewName, $params);
        parent::afterAction($action, $content);

        $renderer = new \mPDF(
            'pl-x', // mode
            'A4', // format
            0, // font-size
            '', // font
            12, // margin-left
            12, // margin-right
            5, // margin-top
            5, // margin-bottom
            2, // margin-header
            2, // margin-footer
            'P' // orientation
        );
        $renderer->useSubstitutions = true;
        $renderer->simpleTables = false;
        @$renderer->WriteHTML($content);

        $response = new \yii\web\Response();
        $response->setDownloadHeaders($action->id.'.pdf', 'application/pdf', true);
        $response->format = Response::FORMAT_RAW;
        $response->content = $renderer->Output('print', 'S');
        return $response;
    }
protected function getPdfResponse($action, $result, $params)
    {
        if (Yii::$app->response->format !== Response::FORMAT_PDF) {
            return false;
        }
        $headers = Yii::$app->response->getHeaders();
        if (($location = $headers->get('Location')) !== null) {
            return $this->redirect($location);
        }
        $content = Yii::$app->request->isAjax
            ? $this->renderAjax($action->viewName, $params)
            : $this->render($action->viewName, $params);
        parent::afterAction($action, $content);

        $renderer = new \mPDF(
            'pl-x', // mode
            'A4', // format
            0, // font-size
            '', // font
            12, // margin-left
            12, // margin-right
            5, // margin-top
            5, // margin-bottom
            2, // margin-header
            2, // margin-footer
            'P' // orientation
        );
        $renderer->useSubstitutions = true;
        $renderer->simpleTables = false;
        @$renderer->WriteHTML($content);

        $response = new \yii\web\Response();
        $response->setDownloadHeaders($action->id.'.pdf', 'application/pdf', true);
        $response->format = Response::FORMAT_RAW;
        $response->content = $renderer->Output('print', 'S');
        return $response;
    }
protected function getPdfResponse ( $ action , $ result , $ params ) { if ( Yii :: $ app -> response -> format !== Response :: FORMAT_PDF ) { return false ; } $ headers = Yii :: $ app -> response -> getHeaders ( ) ; if ( ( $ location = $ headers -> get ( 'Location' ) ) !== null ) { return $ this -> redirect ( $ location ) ; } $ content = Yii :: $ app -> request -> isAjax ? $ this -> renderAjax ( $ action -> viewName , $ params ) : $ this -> render ( $ action -> viewName , $ params ) ; parent :: afterAction ( $ action , $ content ) ; $ renderer = new \ mPDF ( 'pl-x' , // mode 'A4' , // format 0 , // font-size '' , // font 12 , // margin-left 12 , // margin-right 5 , // margin-top 5 , // margin-bottom 2 , // margin-header 2 , // margin-footer 'P' // orientation ) ; $ renderer -> useSubstitutions = true ; $ renderer -> simpleTables = false ; @ $ renderer -> WriteHTML ( $ content ) ; $ response = new \ yii \ web \ Response ( ) ; $ response -> setDownloadHeaders ( $ action -> id . '.pdf' , 'application/pdf' , true ) ; $ response -> format = Response :: FORMAT_RAW ; $ response -> content = $ renderer -> Output ( 'print' , 'S' ) ; return $ response ; }
Returns a PDF file with rendered view if response format is PDF, boolean false otherwise.
Name of the view is the same as the action id.
@param Action $action the action just executed.
@param mixed $result  the action return result.
@param array $params
@return string rendered view or boolean false if response format is not HTML.
Returns a PDF file with rendered view if response format is PDF boolean false otherwise . Name of the view is the same as the action id .