Generate PDF report with jasper reports and spring

1

Hello,

I'm having a problem generating a report with jasper reports in spring.

I made the implementation exactly as it appears in method 4 of this explanation: link

When I click the button to generate the report, I'm redirected to the link as @RequestMapping and the browser loads the report into the browser's built-in pdf reader .. then the problem starts ..

On the desktop, as browsers have the built-in pdf reader, it is loaded but when I save it, the file does not even have a defined name (it always remains as document.pdf).

If I try to generate this same report for a mobile phone (I'm testing on an android), the pdf reader that is installed is opened and then the error saying that the format is not supported. When I force a download of the link, an unformatted file is downloaded (if I put the .pdf extension in the file it normally opens).

I can change something in this implementation so that when I click the button to generate the report, it is directed directly to the generated .pdf file so that it works on both the desktop and the mobile or in that case I have to do a more " (like the link method 1) (which I think should work because it defines the name and type of the direct file in the response)?

vlw!

    
asked by anonymous 22.02.2016 / 03:32

1 answer

1

The problem is that the browser is not getting a name for the received file. I already saw systems one the "name" of all reports saved was relatorio.jsp because this was a view that sent the content.

In your case, you can use the JasperReportsViewResolver.setHeaders() " to add the headers as in method 1 of the above link.

Example:

Properties p = new Properties();
p.setProperty("Content-disposition", "inline; filename=meuRelatorioLegal.pdf")
resolver.setHeaders(p);
    
22.02.2016 / 04:07