pdfyii2responseformat

yii2 response formatter not being called


I'm trying to use robregonm pdfresponseFormatter to create a PDF, problem is, the pdf class is never called as the format reponse type.

    'response' => [
        'formatters' => [
            'html' => [
                'class' => 'yii\web\HtmlResponseFormatter',
            ],
            'pdf' => [
                'class' => 'robregonm\pdf\PdfResponseFormatter',
                'mode' => '',
                'format' => 'A4',
                'defaultFontSize' => 0,
                'defaultFont' => '',
                'marginLeft' => 15,
                'marginRight' => 15,
                'marginTop' => 16,
                'marginBottom' => 16,
                'marginHeader' => 9,
                'marginFooter' => 9,
            ]
        ]
    ],
....
$file = $this->getPdf($report);
....
private function getPdf($report){
    Yii::$app->response->format = 'pdf';

   Yii::$container->set(Yii::$app->response->formatters['pdf']['class']);

    $this->layout = '//attachment';

    return $this->render('pdf/actionplan', ['model' => $report]);
}

the $file variable has the HTML text in it from the view


Solution

  • Unfortunately I've not been able to get this extension to work. I did get kartik pdf to work great

    I recommend using the kartik extension instead.