Я реализовал руководство по генерации PDF. В моем классе PdfView
есть метод:
@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) {
response.setHeader("Content-Disposition", "attachment; filename=\"animal-profile.pdf\"");
List<Animal> animals = (List<Animal>) model.get("animals");
try {
document.add(new Paragraph("Generated animals: " + LocalDate.now()));
} catch (DocumentException e) {
e.printStackTrace();
}
PdfPTable table = new PdfPTable(animals.stream().findAny().get().getColumnCount());
table.setWidthPercentage(100.0f);
table.setSpacingBefore(10);
Font font = FontFactory.getFont(FontFactory.TIMES);
font.setColor(BaseColor.WHITE);
PdfPCell cell = new PdfPCell();
cell.setBackgroundColor(BaseColor.DARK_GRAY);
cell.setPadding(5);
cell.setPhrase(new Phrase("Animal Id", font));
table.addCell(cell);
cell.setPhrase(new Phrase("Animal name", font));
for (Animal animal : animals) {
table.addCell(animal.getId().toString());
table.addCell(animal.getName());
}
document.add(table);
}
Как мне реализовать контроллер с методом GET для загрузки PDF?