merge: issue/0020-pdf-generation — PDF generation Python+Go
# Conflicts: # registry.db
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package infra
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ReportSection es una seccion de un reporte PDF simple.
|
||||
// Contiene un titulo, texto descriptivo y una tabla opcional.
|
||||
type ReportSection struct {
|
||||
Title string
|
||||
Text string
|
||||
Table *ReportTable
|
||||
}
|
||||
|
||||
// ReportTable es una tabla opcional dentro de una seccion de reporte.
|
||||
type ReportTable struct {
|
||||
Headers []string
|
||||
Rows [][]string
|
||||
}
|
||||
|
||||
// PdfSimpleReport genera un PDF simple con titulo, secciones y tablas opcionales.
|
||||
//
|
||||
// Stub: requiere go-pdf/fpdf que no esta en el modulo. Para generar PDFs
|
||||
// desde Go usar la alternativa Python (pdf_create_py_infra + pdf_add_table_py_infra
|
||||
// + pdf_save_py_infra) o añadir go-pdf/fpdf al go.mod.
|
||||
//
|
||||
// Para usar la implementacion real:
|
||||
//
|
||||
// go get github.com/go-pdf/fpdf
|
||||
//
|
||||
// y reemplazar el cuerpo de esta funcion con la implementacion completa.
|
||||
func PdfSimpleReport(title string, sections []ReportSection, outputPath string) (string, error) {
|
||||
return "", fmt.Errorf(
|
||||
"not implemented: pdf_simple_report requires go-pdf/fpdf. "+
|
||||
"Add it with: go get github.com/go-pdf/fpdf. "+
|
||||
"Alternatively use pdf_create_py_infra + pdf_add_table_py_infra + pdf_save_py_infra for Python",
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
name: pdf_simple_report
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func PdfSimpleReport(title string, sections []ReportSection, outputPath string) (string, error)"
|
||||
description: "Genera un PDF simple con titulo, secciones de texto y tablas opcionales. Stub activo: requiere go-pdf/fpdf que no esta en el modulo. Para PDFs desde Go añadir la dependencia; para casos complejos usar el builder Python."
|
||||
tags: [pdf, report, go, stub, infra]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [fmt]
|
||||
params:
|
||||
- name: title
|
||||
desc: "titulo principal del reporte PDF, aparece en la cabecera del documento"
|
||||
- name: sections
|
||||
desc: "lista de ReportSection, cada una con Title (string), Text (string) y Table opcional (*ReportTable con Headers y Rows)"
|
||||
- name: outputPath
|
||||
desc: "ruta del archivo PDF a generar en disco"
|
||||
output: "outputPath con el PDF generado, o string vacio + error si la dependencia no esta disponible"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "functions/infra/pdf_simple_report.go"
|
||||
---
|
||||
|
||||
## Tipos auxiliares
|
||||
|
||||
```go
|
||||
type ReportSection struct {
|
||||
Title string
|
||||
Text string
|
||||
Table *ReportTable // nil = sin tabla en esta seccion
|
||||
}
|
||||
|
||||
type ReportTable struct {
|
||||
Headers []string
|
||||
Rows [][]string
|
||||
}
|
||||
```
|
||||
|
||||
## Ejemplo de uso
|
||||
|
||||
```go
|
||||
sections := []infra.ReportSection{
|
||||
{
|
||||
Title: "Estado del Registry",
|
||||
Text: "El registry contiene 142 funciones, 38 tipos y 12 proposals pendientes.",
|
||||
},
|
||||
{
|
||||
Title: "Funciones por Dominio",
|
||||
Table: &infra.ReportTable{
|
||||
Headers: []string{"Dominio", "Funciones", "Tipos"},
|
||||
Rows: [][]string{
|
||||
{"core", "45", "12"},
|
||||
{"infra", "38", "8"},
|
||||
{"finance", "22", "6"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
path, err := infra.PdfSimpleReport("Registry Status Report", sections, "registry_report.pdf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("PDF generado:", path)
|
||||
```
|
||||
|
||||
## Activar la implementacion real
|
||||
|
||||
```bash
|
||||
# Añadir dependencia al modulo Go
|
||||
go get github.com/go-pdf/fpdf
|
||||
|
||||
# La funcion usa la API de go-pdf/fpdf:
|
||||
# pdf := fpdf.New("P", "mm", "A4", "")
|
||||
# pdf.AddPage()
|
||||
# pdf.SetFont("Arial", "B", 16)
|
||||
# pdf.Cell(0, 10, title)
|
||||
# ... para cada seccion y tabla
|
||||
# pdf.OutputFileAndClose(outputPath)
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Stub activo: retorna `fmt.Errorf("not implemented: ...")` hasta que `go-pdf/fpdf` se añada al modulo. No añadida como dependencia directa porque solo la usa esta funcion y añade peso al modulo. Para generacion de PDFs desde el registry, la solucion recomendada es el builder Python (`pdf_create_py_infra` + `pdf_add_text_py_infra` + `pdf_add_table_py_infra` + `pdf_save_py_infra`) que es mas completo y no requiere dependencias adicionales en Go.
|
||||
Reference in New Issue
Block a user