Blame |
Last modification |
View Log
| Download
| RSS feed
package br.gov.al.saude.rhd.web.managebean.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
public class RelatorioUtils
{
public static StreamedContent gerarPdf
(JasperPrint relatorio,
String nomeRelatorio
) throws Exception {
byte[] arquivo =
null;
arquivo = JasperExportManager.
exportReportToPdf(relatorio
);
String nomeDoArquivo = nomeRelatorio +
".pdf";
OutputStream out =
new ByteArrayOutputStream();
out.
write(arquivo
);
ByteArrayInputStream input =
new ByteArrayInputStream(((ByteArrayOutputStream)out
).
toByteArray());
return new DefaultStreamedContent
(input,
"application/pdf", nomeDoArquivo
);
}
}