Render view to pdf

I found this in the docs

and am trying to create an action to download a view as a PDF

in my action i have this

function actionDownload() {

$content = $this->render('@app/modules/bla/views/view', [
                    'model' => $model,
                ]);

$filename =' bla.pdf';

 return \Yii::$app->response->sendContentAsFile($content, $filename, ['mimeType' => 'application/pdf'])->send();

}

when the pdf is saved to my downloads folder, i can’t open it. does sendContentAsFile() not save as a PDF? or am i missing something in the options ?

It won’t convert HTML to PDF for you. It will just tell the browser that “it should be read as PDF”.

1 Like

ah ok, got it. thanks