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:
@@ -0,0 +1,41 @@
|
||||
"""pdf_add_header_footer — configura header/footer recurrente con numeracion de pagina."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
_types_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "python", "types", "infra")
|
||||
sys.path.insert(0, _types_dir)
|
||||
from pdf_doc import PDFDoc
|
||||
|
||||
|
||||
def pdf_add_header_footer(
|
||||
doc: PDFDoc,
|
||||
header_text: str = "",
|
||||
footer_text: str = "",
|
||||
page_numbers: bool = True,
|
||||
) -> PDFDoc:
|
||||
"""Configura header y/o footer recurrente para todas las paginas del documento.
|
||||
|
||||
El header/footer se aplicara automaticamente en cada pagina nueva.
|
||||
Debe llamarse ANTES de añadir paginas con pdf_add_page para que surta efecto.
|
||||
El footer acepta {n} (numero de pagina actual) y {total} (total de paginas).
|
||||
|
||||
Args:
|
||||
doc: PDFDoc inicializado con pdf_create.
|
||||
header_text: texto a mostrar en el header de cada pagina. Vacio = sin header.
|
||||
footer_text: texto del footer. Acepta {n} y {total} como placeholders.
|
||||
Si page_numbers=True y footer_text esta vacio, usa 'Pagina {n} de {total}'.
|
||||
page_numbers: si True incluye numeracion automatica en el footer.
|
||||
|
||||
Returns:
|
||||
PDFDoc con la configuracion de header/footer establecida.
|
||||
"""
|
||||
doc.header_text = header_text
|
||||
doc.footer_text = footer_text
|
||||
doc.page_numbers = page_numbers
|
||||
|
||||
# Activar alias de paginas totales en fpdf2 para {nb}
|
||||
if page_numbers:
|
||||
doc.fpdf.alias_nb_pages("{nb}")
|
||||
|
||||
return doc
|
||||
Reference in New Issue
Block a user