Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.scs.web.managebean.util; |
| 2 | |||
| 3 | import java.io.ByteArrayInputStream; |
||
| 4 | import java.io.ByteArrayOutputStream; |
||
| 5 | import java.io.OutputStream; |
||
| 6 | |||
| 7 | import net.sf.jasperreports.engine.JasperExportManager; |
||
| 8 | import net.sf.jasperreports.engine.JasperPrint; |
||
| 9 | |||
| 10 | import org.primefaces.model.DefaultStreamedContent; |
||
| 11 | import org.primefaces.model.StreamedContent; |
||
| 12 | |||
| 13 | public class RelatorioUtils { |
||
| 14 | |||
| 15 | public static StreamedContent gerarPdf(JasperPrint relatorio, String nomeRelatorio) throws Exception { |
||
| 16 | byte[] arquivo = null; |
||
| 17 | arquivo = JasperExportManager.exportReportToPdf(relatorio); |
||
| 18 | String nomeDoArquivo = nomeRelatorio + ".pdf"; |
||
| 19 | OutputStream out = new ByteArrayOutputStream(); |
||
| 20 | out.write(arquivo); |
||
| 21 | ByteArrayInputStream input = new ByteArrayInputStream(((ByteArrayOutputStream)out).toByteArray()); |
||
| 22 | return new DefaultStreamedContent(input, "application/pdf", nomeDoArquivo); |
||
| 23 | } |
||
| 24 | |||
| 25 | } |