$html = $this->renderPartial('html-pdf', ['model' => $model]);
//rozwiązuje problem z kodowaniem znaków
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
$mpdf = new \Mpdf\Mpdf([
'tempDir' => sys_get_temp_dir(),
'mode' => 'utf-8',
//'format' => 'A4-L',
'default_font_size' => 8,
'margin_left' => 15,
'margin_right' => 10,
'margin_top' => 5,
'margin_bottom' => 1,
'margin_header' => 0,
'margin_footer' => 2,
'setAutoBottomMargin' => 'stretch'
]);
$mpdf->SetTitle($nazwa_pliku);
$mpdf->SetHTMLFooter('
{DATE j-m-Y}
{PAGENO}/{nbpg}
' . $stopka . '
');
$mpdf->WriteHTML($html);
ob_start();
$mpdf->Output($nazwa_pliku, 'I');
$output = ob_get_clean();
// yii2 headers for pdf
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', 'application/pdf');
Yii::$app->response->headers->add('Content-Disposition', 'inline; filename="' . $nazwa_pliku . '"');
Yii::$app->response->headers->add('Content-Length', strlen($output));
return $output;
Inna wersja
$path = Yii::getAlias('@pliki') . '/prace-dyplomowe/' . $nazwa_pliku;
$mpdf = new \Mpdf\Mpdf([
'tempDir' => sys_get_temp_dir(),
'mode' => 'utf-8',
//'format' => 'A4-L',
'default_font_size' => 10,
'margin_left' => 15,
'margin_right' => 10,
'margin_top' => 5,
'margin_bottom' => 1,
'margin_header' => 0,
'margin_footer' => 2,
'setAutoBottomMargin' => 'stretch'
]);
$mpdf->SetTitle('Wniosek');
$mpdf->SetHTMLFooter('
Wydruk z dnia: {DATE j-m-Y} Numer sprawy ' . $crd['znak'] . '
Strona: {PAGENO} z {nbpg}
'
);
$mpdf->WriteHTML($tresc_pdf);
$mpdf->Output($path, 'F');
===== Zapisywanie do pliku =====
$mpdf->Output("./your_folder_location/".$nazwa_pliku, 'F');
===== Zapisywanie do bazy - blob =====
...
$mpdf->WriteHTML($html);
$model = new Dokument();
$model->plik = $mpdf->Output('protokol', 'S');
$model->save();
==== Odczytywanie z bazy i wyświetlanie w przeglądarce ====
$model = Dokument::find()
->where(['id'=>1])
->one();
header('Content-Type: application/pdf');
header('Content-Disposition:inline; filename=' . $model->nazwa. '.pdf');
echo $model->plik;