#!/usr/bin/env python3 """Genera PDF del informe ejecutivo desde Markdown usando Chrome headless.""" import markdown import subprocess import sys import os SRC = "01_informe_ejecutivo_DASUTEN.md" OUT = "01_informe_ejecutivo_DASUTEN.pdf" TMP = "/tmp/_informe_tmp.html" # Leer markdown with open(SRC, "r", encoding="utf-8") as f: md_text = f.read() # Convertir a HTML html_body = markdown.markdown(md_text, extensions=["tables", "fenced_code"]) # Envolver con estilos profesionales html = f"""
{html_body} """ # Guardar HTML temporal with open(TMP, "w", encoding="utf-8") as f: f.write(html) # Generar PDF con Chrome headless result = subprocess.run([ "google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--disable-software-rasterizer", f"--print-to-pdf={OUT}", "--print-to-pdf-no-header", TMP ], capture_output=True, text=True) if os.path.exists(OUT): size = os.path.getsize(OUT) / 1024 print(f"✅ PDF generado: {OUT} ({size:.0f} KB)") else: print(f"❌ Error al generar PDF") print(result.stderr) sys.exit(1) # Limpiar os.remove(TMP)