df424f2de0
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>
1.7 KiB
1.7 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| pdf_save | function | py | infra | 1.0.0 | impure | def pdf_save(doc, output_path) -> str | bytes | Serializa el documento PDF a disco o retorna los bytes en memoria. Si output_path es None retorna bytes para transmision directa (HTTP response, almacenamiento en BD). Si se especifica, escribe el archivo y retorna el path. |
|
|
false | error_go_core |
|
output_path (str) si se escribio a disco, o bytes del PDF si output_path es None | true |
|
python/functions/infra/pdf_save_test.py | python/functions/infra/pdf_save.py |
Ejemplo
# Guardar a disco
path = pdf_save(doc, "reporte.pdf")
print(f"PDF guardado en: {path}")
# Obtener bytes (para HTTP response o guardar en BD)
pdf_bytes = pdf_save(doc)
assert pdf_bytes[:4] == b"%PDF"
# En un endpoint web (ejemplo conceptual)
return Response(pdf_save(doc), content_type="application/pdf")
Notas
Llama a fpdf2.output(). Si el documento usa alias_nb_pages() (activado por pdf_add_header_footer con page_numbers=True), fpdf2 reemplaza el alias con el total real de paginas al serializar. Para retornar bytes, output() retorna un bytearray que se convierte a bytes para compatibilidad con APIs que esperan bytes.