prepare('SELECT * FROM home WHERE idhome = ? LIMIT 1'); $stmt->execute([$idhome]); $home = $stmt->fetch(); if (!$home) { json_error(404, 'Home not found'); } // TCPDF is provided by the main app composer autoload. $autoload = __DIR__ . '/../../../vendor/autoload.php'; if (is_file($autoload)) { require_once $autoload; } if (!class_exists('TCPDF')) { json_error(501, 'PDF library (TCPDF) not installed'); } $pdf = new TCPDF(); $pdf->SetCreator('Casadoc'); $pdf->SetTitle('Report immobile'); $pdf->AddPage(); $pdf->SetFont('helvetica', 'B', 16); $pdf->Cell(0, 10, (string) ($home['name'] ?? 'Immobile'), 0, 1); $pdf->SetFont('helvetica', '', 11); $rows = [ 'Indirizzo' => trim(($home['address'] ?? '') . ', ' . ($home['zip'] ?? '') . ' ' . ($home['city'] ?? '')), 'Comune cat.'=> $home['cadastral_municipality'] ?? '', 'Foglio' => $home['cadastral_sheet'] ?? '', 'Particella' => $home['cadastral_particle'] ?? '', 'Categoria' => $home['cadastral_category'] ?? '', 'Superficie' => $home['cadastral_surface'] ?? '', 'Rendita' => $home['cadastral_rendita'] ?? '', ]; foreach ($rows as $label => $value) { $pdf->Cell(45, 8, $label . ':', 0, 0); $pdf->Cell(0, 8, (string) $value, 0, 1); } $body = $pdf->Output('report.pdf', 'S'); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="Report_' . $idhome . '.pdf"'); header('Content-Length: ' . strlen($body)); echo $body; exit;