3
I’m using JSF and Primefaces, and I need to download a PDF that I generated with iReports and Jasper.
I save the PDF this way, this way:
String caminhoReports = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports");
File pdf = new File(caminhoReports+"/relatorio2.pdf");
pdf.createNewFile();
FileOutputStream arquivo = new FileOutputStream(pdf);
JasperExportManager.exportReportToPdfStream(impressoraJasper, arquivo);
He’s safe in that directory:
D:\Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\monitorias\WEB-INF\reports\relatorio2.pdf
How do I put a button that downloads this report? I tried to use the download component of primefaces but did not, when I step this way it says that Resource is not valid.
It may look stupid. But as I write the Inputstream for Outputstream?
– João Neto
@Joãoneto I edited the answer, see if it works for you.
– stderr
Yes, it worked! But after this way I managed to do it also using the component of the primefaces. I will post my solution as well.
– João Neto
@Joãoneto I’m glad it worked out. If you can mark the answer as accepted. =)
– stderr
I’d forgotten that kkk detail. =)
– João Neto