AppSetting::getAppName() ?? 'Glastree', ]); } public function pdf(): View { return view('help.pdf', [ 'appName' => AppSetting::getAppName() ?? 'Glastree', ]); } public function downloadPdf(): BinaryFileResponse { $pdfPath = storage_path('app/help-guida.pdf'); if (!file_exists($pdfPath)) { $appName = AppSetting::getAppName() ?? 'Glastree'; $html = view('help.pdf', ['appName' => $appName])->render(); $tmpHtml = tempnam(sys_get_temp_dir(), 'help_') . '.html'; file_put_contents($tmpHtml, $html); $cmd = sprintf( '/usr/bin/chromium --headless --no-sandbox --disable-gpu --print-to-pdf=%s %s 2>&1', escapeshellarg($pdfPath), escapeshellarg('file://' . $tmpHtml) ); exec($cmd, $execOutput, $exitCode); unlink($tmpHtml); if ($exitCode !== 0 || !file_exists($pdfPath)) { abort(500, 'Errore generazione PDF. Assicurati che Chromium sia installato.'); } } return response()->download($pdfPath, 'guida-glastree.pdf', [ 'Content-Type' => 'application/pdf', ]); } }