Narzędzia użytkownika

Narzędzia witryny


mpdf

To jest stara wersja strony!


Generowanie PDF

$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->WriteHTML($html);
$mpdf->Output($nazwa_pliku, 'I');
exit;

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;
mpdf.1664545622.txt.gz · ostatnio zmienione: 2024/09/15 16:22 (edycja zewnętrzna)