I need to export PDF file by controller to an user. My REST is look like that however it returns empty file.
@RequestMapping(value="/pdfReport", method=RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public void downloadPDFReport(HttpServletResponse response, @RequestBody PDFReport pdfReport) throws IOException{
StringBuilder sB = storageManager.getPDF(pdfReport);
System.out.println(sB.toString());
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.setFont(PDType1Font.TIMES_ROMAN, 12);
contentStream.beginText();
contentStream.showText(sB.toString());
contentStream.endText();
contentStream.close();
document.save("pdfBoxHelloWorld.pdf");
PDStream pdfStream = new PDStream(document);
InputStream inputStream = pdfStream.createInputStream();
FileCopyUtils.copy(inputStream, response.getOutputStream());
}
I print out StringBuilder so I am 100% sure that the content of StringBuilder is correct.