Jump to content
We've recently updated our Privacy Statement, available here ×

ProgrammerBR

Members
  • Posts

    5
  • Joined

  • Last visited

ProgrammerBR's Achievements

  1. The problem was the front-end, I fixed it using this: .then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', type + '_'+month'_'+ year +'.pdf'); document.body.appendChild(link); link.click(); })
  2. The problem was the front-end, I fixed it using this: .then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', type + '_'+month'_'+ year +'.pdf'); document.body.appendChild(link); link.click(); })
  3. I just tried both, unfortunately it didn't work. Thanks for answering
  4. Hi guys, I really need some help with this.. I tried everything I found here and on other sites to make it work, but unfortunately it still doesn't work. I tried to do this in several different ways. I'm using Jasper Reports and I just need to download the file instead of saving it to my desktop. This is my code: @RestControllerpublic class ReportController {@Autowiredprivate ReportService reportService;@GetMapping("/report/{month}/{year}")public void export(HttpServletResponse response, @PathVariable Integer month, @PathVariable Integer year) throws IOException, JRException, SQLException { JasperPrint jasperPrint = null; response.setContentType("application/x-download"); response.setHeader("Content-Disposition", String.format("attachment; filename="despesas.pdf"")); OutputStream out = response.getOutputStream(); jasperPrint = reportService.exportPdfFile(month,year); JasperExportManager.exportReportToPdfStream(jasperPrint, out);}} And: @Servicepublic class ReportService {@Autowiredprivate ExpenseRepository er;@Autowiredprivate ResourceLoader resourceLoader;public JasperPrint exportPdfFile(Integer month, Integer year) throws IOException, JRException { List<Expense> expenses = er.findAll(); String period = month + "/" + year; //File desktop = new File(System.getProperty("user.home"), "Desktop"); String path = resourceLoader.getResource("classpath:jasper_reports/expenses.jrxml").getURI().getPath(); JasperReport jasperReport = JasperCompileManager.compileReport(path); JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(expenses); Map<String, Object> parameters = new HashMap<>(); parameters.put("periodParameter", period); JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, dataSource); //JasperExportManager.exportReportToPdfFile(print, desktop +"\despesas.pdf"); This saves the file on my desktop return print;}} When I run this nothing happens, the console does not report any errors and the download does not start. I've already tried it in different browsers Can someone tell me why is it not working or give me a suggestion ? Thank you so much..
  5. I really need some help with this.. I tried everything I found here and on other sites to make it work, but unfortunately it still doesn't work. I tried to do this in several different ways. I'm using Jasper Reports and I just need to download the file instead of saving it to my desktop. This is my code: @RestControllerpublic class ReportController {@Autowiredprivate ReportService reportService;@GetMapping("/report/{month}/{year}")public void export(HttpServletResponse response, @PathVariable Integer month, @PathVariable Integer year) throws IOException, JRException, SQLException { JasperPrint jasperPrint = null; response.setContentType("application/x-download"); response.setHeader("Content-Disposition", String.format("attachment; filename="despesas.pdf"")); OutputStream out = response.getOutputStream(); jasperPrint = reportService.exportPdfFile(month,year); JasperExportManager.exportReportToPdfStream(jasperPrint, out);}} And: @Servicepublic class ReportService {@Autowiredprivate ExpenseRepository er;@Autowiredprivate ResourceLoader resourceLoader;public JasperPrint exportPdfFile(Integer month, Integer year) throws IOException, JRException { List<Expense> expenses = er.findAll(); String period = month + "/" + year; //File desktop = new File(System.getProperty("user.home"), "Desktop"); String path = resourceLoader.getResource("classpath:jasper_reports/expenses.jrxml").getURI().getPath(); JasperReport jasperReport = JasperCompileManager.compileReport(path); JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(expenses); Map<String, Object> parameters = new HashMap<>(); parameters.put("periodParameter", period); JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, dataSource); //JasperExportManager.exportReportToPdfFile(print, desktop +"\despesas.pdf"); This saves the file on my desktop return print;}} When I run this nothing happens, the console does not report any errors and the download does not start. I've already tried it in different browsers Can someone tell me why is it not working or give me a suggestion ? Thank you so much..
×
×
  • Create New...