first(); self::$gutachter = Gutachter::where('id', self::$projekt->gutachter_id)->first(); self::$auftraggeber = Auftraggeber::where('id', self::$projekt->auftraggeber_id)->first(); $headers = [ 'Content-Type: application/pdf', 'Cache-Control: max-age=0', 'Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT', 'Cache-Control: cache, must-revalidate', ]; $filepath = Storage::disk('public')->path("/download/$projekte_id/"); $filename = \ucfirst($part).' '.preg_replace("'[^0-9a-zA-Z]'", '', self::$projekt->interner_name).'.pdf'; if (! File::isDirectory($filepath)) { File::makeDirectory($filepath, 0777, true, true); } $file = $filepath.$filename; ob_start(); $mpdf = new Mpdf( [ 'debug' => true, 'use_kwt' => true, 'mode' => 'utf-8', 'format' => 'A4-P', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 12, 'margin_bottom' => 20, 'margin_header' => 0, 'margin_footer' => 0, ] ); $stylesheet = file_get_contents(__DIR__.'/../../../resources/css/pdf-download.css'); $colors = []; if (self::$projekt?->projekt_farben_verwenden) { $colors["'###BG_DECKBLATT###'"] = self::$projekt->deckblatt_bg; $colors["'###BG_HEADER###'"] = self::$projekt->schmuckfarbe_header; $colors["'###FARBE_RAHMEN###'"] = self::$projekt->farbe_borders; } else { $colors["'###BG_DECKBLATT###'"] = self::$gutachter->deckblatt_bg; $colors["'###BG_HEADER###'"] = self::$gutachter->schmuckfarbe_header; $colors["'###FARBE_RAHMEN###'"] = self::$gutachter->farbe_borders; } $stylesheet = Platzhalter::replace($colors, $stylesheet); // dd($stylesheet); $mpdf->WriteHTML($stylesheet, HTMLParserMode::HEADER_CSS); $mpdf->SetTitle($filename); $mpdf->SetCreator('nutzwerte.at'); $mpdf->SetAuthor(self::$gutachter->title.' '.self::$gutachter->gender.' '.self::$gutachter->name); $inhaltesverzeichnis = ProjektInhaltsverzeichnis::where('projekte_id', $projekte_id)->where('part', $part)->orderBy('sort')->get(); $platzhalter = Platzhalter::load($projekte_id); foreach ($inhaltesverzeichnis as $inhalt) { if ($inhalt->neue_seite) { if ($part == 'nutzwerte') { $mpdf->AddPage('P', '', $inhalt->seite); } else { $mpdf->AddPage(); } } $html = ''; $html = Ueberschrift::load($inhalt); $textblock = ''; $textblock2 = ''; if ($inhalt->textblock) { $textblock = Platzhalter::replace($platzhalter, $inhalt->textblock); $textblock = Format::fix_str($textblock); if (! in_array($inhalt->inhaltselement_id, [9, 10])) { $html .= $textblock; } } if ($inhalt->textblock2) { $textblock2 = Platzhalter::replace($platzhalter, $inhalt->textblock2); $textblock2 = Format::fix_str($textblock2); } switch ($inhalt->inhaltselement_id) { case '1': $html .= Inhalt::load($projekte_id); break; case '3': $html .= Paragraph6::load($projekte_id); break; case '4': $html .= Allgemeinflaechen::load($projekte_id); break; case '5': $html .= ZuUndAbschlaege::load($projekte_id); break; case '6': $html .= Nutzwertberechnung::load($projekte_id); break; case '7': $html .= Zusammenstellung::load($projekte_id); break; case '8': // AUFTRAGGEBER $str = RichContentRenderer::make(self::$auftraggeber->referenz_formatting)->toHtml(); $html .= Format::fix_str($str); break; case '9': $html .= Deckblatt::load($inhalt, $textblock, $textblock2); break; case '10': $html .= DigitaleSignatur::load($projekte_id, $textblock); break; } if ($inhalt->textblock2 and $inhalt->inhaltselement_id != 9) { $html .= $textblock2; } if ($inhalt->seite != 0) { $mpdf->SetHTMLFooter('
Seite {PAGENO}

'); } if ($html) { $mpdf->WriteHTML($html, HTMLParserMode::HTML_BODY); } } if ($part == 'standard') { $inhaltesverzeichnis = ProjektInhaltsverzeichnis::where('projekte_id', $projekte_id)->where('part', 'nutzwerte')->orderBy('sort')->first(); $inhaltesverzeichnis->seite = $mpdf->page + 1; $inhaltesverzeichnis->save(); } ob_clean(); $mpdf->Output($file, 'F'); return Response::file($file, $headers); // return Response::download($file, $filename, $headers); } }