set('defaultFont', 'DejaVu Sans');
$options->setIsHtml5ParserEnabled(true);
$options->setIsFontSubsettingEnabled(true);
$dompdf = new \Dompdf\Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$filename = 'Oficio_' . preg_replace('/[^A-Za-z0-9\-_]/', '_', $oficio['numero_oficio']) . '_' . date('Ymd') . '.pdf';
$dompdf->stream($filename, ['Attachment' => true]);
} else {
// Fallback: HTML descargable
header('Content-Type: text/html; charset=utf-8');
header('Content-Disposition: attachment; filename="oficio_' . $oficio['id'] . '.html"');
echo $html;
}
exit();
}
/**
* Genera HTML del oficio para PDF
*/
private static function htmlOficio(array $o): string {
$logo = file_exists(LOGO_PATH) ? '' : '';
$fecha = date('d/m/Y H:i');
$vence = $o['fecha_vencimiento'] ? date('d/m/Y', strtotime($o['fecha_vencimiento'])) : 'Sin fecha';
$recep = date('d/m/Y', strtotime($o['fecha_recepcion']));
$etiquetas = $o['etiquetas'] ?? '—';
$colorPrioridad = ['alta' => '#d32f2f', 'media' => '#fbc02d', 'baja' => '#388e3c'];
$colorEstado = ['recibido' => '#2e7d32', 'en_proceso' => '#fbc02d', 'respondido' => '#0288d1', 'vencido' => '#d32f2f', 'archivado' => '#64748b'];
$pColor = $colorPrioridad[$o['prioridad']] ?? '#64748b';
$eColor = $colorEstado[$o['estado']] ?? '#64748b';
return <<