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,49 @@
|
||||
"""pdf_add_page — añade una pagina al documento PDF."""
|
||||
|
||||
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_page(
|
||||
doc: PDFDoc,
|
||||
orientation: str = "portrait",
|
||||
width: float | None = None,
|
||||
height: float | None = None,
|
||||
) -> PDFDoc:
|
||||
"""Añade una pagina nueva al documento PDF.
|
||||
|
||||
Usa orientacion y dimensiones especificadas, o hereda las del documento.
|
||||
Si se especifica width/height se usa formato personalizado;
|
||||
si no, se usa A4 con la orientacion indicada.
|
||||
|
||||
Args:
|
||||
doc: PDFDoc retornado por pdf_create.
|
||||
orientation: orientacion de la pagina: 'portrait' o 'landscape'.
|
||||
width: ancho personalizado en mm. Si None, usa A4 (210 mm).
|
||||
height: alto personalizado en mm. Si None, usa A4 (297 mm).
|
||||
|
||||
Returns:
|
||||
PDFDoc con la nueva pagina añadida (mismo objeto modificado).
|
||||
"""
|
||||
fpdf = doc.fpdf
|
||||
|
||||
orient_char = "P" if orientation == "portrait" else "L"
|
||||
|
||||
if width is not None and height is not None:
|
||||
fpdf.add_page(orientation=orient_char, format=(width, height))
|
||||
else:
|
||||
fpdf.add_page(orientation=orient_char, format="A4")
|
||||
|
||||
actual_w = fpdf.w
|
||||
actual_h = fpdf.h
|
||||
doc.pages.append({
|
||||
"orientation": orientation,
|
||||
"width": actual_w,
|
||||
"height": actual_h,
|
||||
})
|
||||
|
||||
return doc
|
||||
Reference in New Issue
Block a user