final JasperReport report = DynamicJasperHelper.generateJasperReport(dynamicReport, new ClassicLayoutManager(), new HashMap<Object, Object>());
final byte[] reportBytes = JasperRunManager.runReportToPdf(report, new HashMap<Object, Object>(), new DynamicExportDataSource(records));
// Set MIME type to binary data to prevent opening of PDF in browser window
final StreamResource streamResource = new StreamResource();
streamResource.open(new StreamHandler() {
@Override
public void onStream(final HttpServletRequest req, final HttpServletResponse response) {
response.reset();
response.setContentType("application/pdf");