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>
60 lines
2.2 KiB
Markdown
60 lines
2.2 KiB
Markdown
---
|
|
name: pdf_create
|
|
kind: function
|
|
lang: py
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "def pdf_create(title, author, subject, default_font, margin_left, margin_right, margin_top, margin_bottom) -> PDFDoc"
|
|
description: "Inicializa un documento PDF nuevo usando fpdf2. Crea un objeto FPDF configurado con metadatos y margenes. Retorna un PDFDoc listo para añadir paginas con pdf_add_page."
|
|
tags: [pdf, create, fpdf2, builder, infra]
|
|
uses_functions: []
|
|
uses_types: [pdf_doc_py_infra]
|
|
returns: [pdf_doc_py_infra]
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [fpdf2]
|
|
params:
|
|
- name: title
|
|
desc: "titulo del documento, aparece en metadata del PDF reader"
|
|
- name: author
|
|
desc: "autor del documento (metadata)"
|
|
- name: subject
|
|
desc: "asunto del documento (metadata)"
|
|
- name: default_font
|
|
desc: "fuente por defecto: Helvetica, Times, Courier (built-ins sin .ttf)"
|
|
- name: margin_left
|
|
desc: "margen izquierdo en mm, por defecto 20"
|
|
- name: margin_right
|
|
desc: "margen derecho en mm, por defecto 20"
|
|
- name: margin_top
|
|
desc: "margen superior en mm, por defecto 20"
|
|
- name: margin_bottom
|
|
desc: "margen inferior (page break) en mm, por defecto 20"
|
|
output: "PDFDoc inicializado con objeto fpdf2 configurado, listo para pdf_add_page"
|
|
tested: true
|
|
tests: ["crear documento con titulo y autor", "margenes personalizados aplicados"]
|
|
test_file_path: "python/functions/infra/pdf_create_test.py"
|
|
file_path: "python/functions/infra/pdf_create.py"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```python
|
|
import sys
|
|
sys.path.insert(0, "python/functions/infra")
|
|
sys.path.insert(0, "python/types/infra")
|
|
|
|
from pdf_create import pdf_create
|
|
from pdf_add_page import pdf_add_page
|
|
from pdf_save import pdf_save
|
|
|
|
doc = pdf_create(title="Mi Reporte", author="Agente")
|
|
doc = pdf_add_page(doc)
|
|
pdf_save(doc, "reporte.pdf")
|
|
```
|
|
|
|
## Notas
|
|
|
|
Funcion impura: inicializa un objeto FPDF con estado mutable. Usa una subclase interna `_PDFWithHeaderFooter` que sobreescribe `header()` y `footer()` de FPDF para soportar header/footer recurrente configurado via `pdf_add_header_footer`. Los margenes se aplican con `set_margins` y `set_auto_page_break`. Requiere `fpdf2` instalado (`uv add fpdf2`).
|