preparando el imprimir

This commit is contained in:
2025-10-12 21:42:04 +02:00
parent 6641c1f077
commit 26c2ca543a
41 changed files with 1325 additions and 208 deletions

View File

@ -0,0 +1,32 @@
package com.imprimelibros.erp.pdf;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Locale;
import java.util.Map;
@RestController
@RequestMapping("/api/pdf")
public class PdfController {
private final PdfService pdfService;
public PdfController(PdfService pdfService) { this.pdfService = pdfService; }
@PostMapping("/{type}/{templateId}")
public ResponseEntity<byte[]> generate(
@PathVariable("type") DocumentType type,
@PathVariable String templateId,
@RequestBody Map<String,Object> model,
Locale locale) {
var spec = new DocumentSpec(type, templateId, locale, model);
var pdf = pdfService.generate(spec);
var fileName = type.name().toLowerCase() + "-" + templateId + ".pdf";
return ResponseEntity.ok()
.header("Content-Type", "application/pdf")
.header("Content-Disposition", "inline; filename=\"" + fileName + "\"")
.body(pdf);
}
}