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>
2.1 KiB
2.1 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_add_image | function | py | infra | 1.0.0 | impure | def pdf_add_image(doc, image, x, y, width, height, keep_aspect) -> PDFDoc | Añade una imagen PNG o JPEG al documento PDF desde un path de archivo o bytes. Calcula automaticamente la dimension faltante si solo se especifica width o height para mantener la relacion de aspecto. |
|
|
|
false | error_go_core |
|
PDFDoc con la imagen embebida en la pagina activa | false | python/functions/infra/pdf_add_image.py |
Ejemplo
# Imagen desde path con ancho fijo (height automatico)
doc = pdf_add_image(doc, "assets/logo.png", x=15, y=10, width=40)
# Imagen desde bytes
with open("chart.png", "rb") as f:
img_bytes = f.read()
doc = pdf_add_image(doc, img_bytes, width=120)
# Imagen en posicion actual del cursor
doc = pdf_add_image(doc, "diagrama.png", width=fpdf_doc.fpdf.epw)
Notas
Soporta PNG y JPEG nativamente en fpdf2. Para bytes, usa io.BytesIO como wrapper. fpdf2 gestiona automaticamente la relacion de aspecto cuando solo se especifica una dimension (fpdf calcula la otra si h=0). El cursor se mueve 5mm debajo de la imagen tras insertarla. Para SVG necesitaria fpdf2[svg] como extra opcional.