feat: issue/0020 — generacion de PDFs en Python y Go

Añade 3 tipos Python (PDFDoc, PDFPage, PDFStyle) y 10 funciones Python
para construir PDFs con fpdf2 (builder fluent), fusionar PDFs con pypdf
y convertir HTML/Markdown a PDF via weasyprint (stub si no disponible).
Añade pdf_simple_report en Go como stub hasta que go-pdf/fpdf se integre.

- python/types/infra/: pdf_doc, pdf_page, pdf_style
- python/functions/infra/: pdf_create, pdf_add_page, pdf_add_text,
  pdf_add_table, pdf_add_image, pdf_add_header_footer, pdf_from_html,
  pdf_from_markdown, pdf_merge, pdf_save
- functions/infra/pdf_simple_report.go: stub Go con ReportSection/ReportTable
- 17 tests Python pasando (pytest)
- fpdf2 y pypdf añadidos via uv al venv Python

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 02:02:51 +02:00
parent 092f14eff0
commit df424f2de0
35 changed files with 1818 additions and 0 deletions
@@ -0,0 +1,65 @@
---
name: pdf_from_markdown
kind: function
lang: py
domain: infra
version: "1.0.0"
purity: impure
signature: "def pdf_from_markdown(markdown_string, output_path, css, page_size) -> str"
description: "Convierte un string Markdown a PDF via HTML + weasyprint. Incluye CSS por defecto para tipografia legible. Soporta tablas, codigo y headers. Requiere weasyprint y markdown instalados."
tags: [pdf, markdown, conversion, weasyprint, infra]
uses_functions: [pdf_from_html_py_infra]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [weasyprint, markdown]
params:
- name: markdown_string
desc: "contenido Markdown como string; soporta tablas GFM, codigo cercado y listas"
- name: output_path
desc: "ruta del archivo PDF a generar"
- name: css
desc: "CSS adicional a añadir sobre los estilos por defecto (tipografia, tablas, codigo)"
- name: page_size
desc: "tamaño de pagina: A4, letter. Por defecto A4"
output: "output_path con el PDF generado en disco"
tested: false
tests: []
test_file_path: ""
file_path: "python/functions/infra/pdf_from_markdown.py"
---
## Ejemplo
```python
md_content = """
# Especificacion de la API
## Endpoints
| Metodo | Path | Descripcion |
|--------|------|-------------|
| GET | /fn | Lista funciones |
| POST | /fn | Crea funcion |
## Notas
Usar `Authorization: Bearer <token>` en todos los requests.
"""
output = pdf_from_markdown(md_content, "api_spec.pdf")
```
## Instalacion
```bash
pip install weasyprint markdown
# Linux
sudo apt install libpango-1.0-0 libcairo2 libgdk-pixbuf-2.0-0
```
## Notas
Usa las extensiones `tables`, `fenced_code` y `nl2br` de la libreria `markdown`. El CSS por defecto incluye estilos para: tipografia base (Helvetica 11pt), headers jerarquicos, bloques de codigo con fondo gris, tablas con bordes y blockquotes. Stub activo: lanza `RuntimeError` con instrucciones si alguna dependencia falta.