58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\AppSetting;
|
|
use Illuminate\View\View;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class HelpController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
return view('help.index', [
|
|
'appName' => 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',
|
|
]);
|
|
}
|
|
}
|