Generador de reportes PDF financieros en Java con Spring Boot, Thymeleaf para plantillas y XChart para generar gráficos embebidos en el PDF.
- Java 17
- Spring Boot 4
- Thymeleaf (plantillas)
- XChart (gráficos)
- Flying Saucer (renderizado HTML -> PDF)
- Maven
Ejecutar:
mvnw.cmd spring-boot:run O empaquetar:
mvnw.cmd clean package luego java -jar target/pdf-report-pruebas-0.0.1-SNAPSHOT.jarEjecutar:
./mvnw spring-boot:run O empaquetar:
./mvnw clean package luego java -jar target/pdf-report-pruebas-0.0.1-SNAPSHOT.jar- application.properties — servidor por defecto server.port=8080 y configuración de BD (opcional).
- spring.thymeleaf.prefix
- spring.thymeleaf.suffix cargan la plantilla en templates.
- GET /api/reportes/generar-prueba — Genera y descarga un PDF con datos de ejemplo.
curl -o reporte.pdf http://localhost:8080/api/reportes/generar-prueba
GET /api/reportes/preview-prueba - Obtiene el PDF en modo inline (preview).
curl -o preview.pdf http://localhost:8080/api/reportes/preview-prueba- POST /api/reportes/generar — Genera y descarga un PDF usando la carga JSON (Modelo ReporteDTO).
Header: Content-Type: application/json
Ejemplo curl:
curl -X POST http://localhost:8080/api/reportes/generar \
-H "Content-Type: application/json" \
-d '{"tituloReporte":"Reporte","fechaGeneracion":"2024-01-15",...}'- GET /api/reportes/health — Check del servicio (texto simple).
ReporteDTO — src/main/java/com/pruebas/pdf/report/pdf_report_pruebas/Models/ReporteDTO.java
- tituloReporte (String)
- fechaGeneracion (LocalDate, formato ISO yyyy-MM-dd)
- periodoRepoerte (String)
- ingresoTotal (BigDecimal)
- gastoTotal (BigDecimal)
- balanceNeto (BigDecimal)
- categorias List — Categoria.java
- evolucionMensual List — DatoMensual.java
- transacciones List — Transaccion.java
src/main/resources/templates/reporte-financiero.html Los gráficos se inyectan como data URLs base64 (data:image/png;base64,....) desde ReportService.
- ReporteController — src/main/java/com/pruebas/pdf/report/pdf_report_pruebas/Controllers/ReporteController.java
- PdfGeneratorService — src/main/java/com/pruebas/pdf/report/pdf_report_pruebas/Services/PdfGeneratorService.java
- ReportService — src/main/java/com/pruebas/pdf/report/pdf_report_pruebas/Services/ReportService.java
Ejecutar tests: ./mvnw test o mvnw.cmd test. Mensajes útiles al arranque: src/main/java/com/pruebas/pdf/report/pdf_report_pruebas/PdfReportPruebasApplication.java.
- Flying Saucer tiene limitaciones CSS; la plantilla está optimizada para su motor.
- Si necesita logos o recursos, póngalos como data URL o en recursos accesibles en el HTML.
- Edita server.port en application.properties si deseas otro puerto.