Pdf Download | Taming Thymeleaf
public PdfController(PdfService pdfService) this.pdfService = pdfService;
public byte[] generateInvoicePdf(InvoiceDto invoice) Context context = new Context(); context.setVariable("invoice", invoice); taming thymeleaf pdf download
private final SpringTemplateEngine templateEngine; public PdfController(PdfService pdfService) this
String html = templateEngine.process("invoice", context); private final SpringTemplateEngine templateEngine
public PdfService(SpringTemplateEngine templateEngine) this.templateEngine = templateEngine;
return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=invoice_" + id + ".pdf") .contentType(MediaType.APPLICATION_PDF) .body(pdfBytes);