>"; $objects[] = "<< /Type /Pages /Kids [3 0 R] /Count 1 >>"; $objects[] = "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>"; $objects[] = "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>"; $objects[] = "<< /Length " . strlen($content) . " >>\nstream\n" . $content . "\nendstream"; $pdf = "%PDF-1.4\n"; $offsets = [0]; foreach ($objects as $i => $obj) { $offsets[] = strlen($pdf); $pdf .= ($i + 1) . " 0 obj\n" . $obj . "\nendobj\n"; } $xref = strlen($pdf); $pdf .= "xref\n0 " . (count($objects) + 1) . "\n"; $pdf .= "0000000000 65535 f \n"; for ($i = 1; $i <= count($objects); $i++) { $pdf .= sprintf("%010d 00000 n \n", $offsets[$i]); } $pdf .= "trailer\n<< /Size " . (count($objects) + 1) . " /Root 1 0 R >>\n"; $pdf .= "startxref\n$xref\n%%EOF"; return $pdf; } $lines = [ 'Laporan Pendaftar', 'Tanggal: ' . date('Y-m-d H:i:s') . ' UTC', 'Total: ' . count($registrations), '------------------------------------------------------------', ]; foreach ($registrations as $row) { $lines[] = sprintf( '%s | %s | %s | %s', $row['reg_code'], $row['name'], $row['education'], $row['major'] ); } $pdf = build_pdf($lines); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="report_pendaftar.pdf"'); header('Content-Length: ' . strlen($pdf)); echo $pdf; exit;