I need to create a report (PDF file) with a list of objects from my controller class. I'm using Spring MVC and the method is as follow:
Controller method:
@RequestMapping(value = "/publicationsPDF")
public List<Publication> publicationsList(Model model){
List<Publication> publications = publicationService.publicationsList();
model.addAttribute("publications", publications);
return publications;
}
But I don't know how to get all those objects into my table.
public class PublicationsPDF extends AbstractPdfView{
@Override
protected void buildPdfDocument(Map<String, Object> model,
Document document, PdfWriter writer, HttpServletRequest request,
HttpServletResponse response) throws Exception {
// Here I need to get all those objects placed in my controller class and then list them in table.
PdfPTable table = new PdfPTable(3);
tabla.setWidthPercentage(100.0f);
tabla.setWidths(new float[] {1.0f, 3.0f, 6.0f});
tabla.setSpacingBefore(10);
PdfPCell column = new PdfPCell();
columna.setBackgroundColor(BaseColor.LIGHT_GRAY);
columna.setPadding(3);
columna.setPhrase(new Phrase("ID"));
tabla.addCell(column);
columna.setPhrase(new Phrase("Title"));
tabla.addCell(column);
columna.setPhrase(new Phrase("Content"));
tabla.addCell(column);
document.add(table);
}
}
What I need to do in order to get a report with all those objects? Thanks.
Aucun commentaire:
Enregistrer un commentaire