Last active
November 13, 2017 10:35
-
-
Save nenodias/3599fc2d947b801a7ed0c986708cc990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package br.com.support.sinc.core.util; | |
| import java.io.File; | |
| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import net.sf.jasperreports.engine.JasperCompileManager; | |
| import net.sf.jasperreports.engine.JasperFillManager; | |
| import net.sf.jasperreports.engine.JasperPrint; | |
| import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; | |
| import net.sf.jasperreports.engine.export.JRPdfExporter; | |
| import net.sf.jasperreports.export.Exporter; | |
| import net.sf.jasperreports.export.SimpleExporterInput; | |
| import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput; | |
| public class RelatoriosUtils { | |
| public static void main(String[] args) { | |
| File entrada = new File("/home/nenodias/Downloads/sample.jrxml"); | |
| File saida = new File("/home/nenodias/Downloads/sample.jasper"); | |
| File relatorio = new File("/home/nenodias/Downloads/sample.pdf"); | |
| try { | |
| FileInputStream input = new FileInputStream(entrada); | |
| FileOutputStream output = new FileOutputStream(saida); | |
| JasperCompileManager.compileReportToStream(input, output); | |
| //Imprimir | |
| FileInputStream inputRelatorio = new FileInputStream(entrada); | |
| JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(new ArrayList<>()); | |
| JasperPrint jasperPrint = JasperFillManager.fillReport(saida.getAbsolutePath(), new HashMap<>(), beanCollectionDataSource); | |
| //JasperPrintManager.printReport(jasperPrint, true); | |
| Exporter exporter = new JRPdfExporter(); | |
| SimpleExporterInput itemsInput = new SimpleExporterInput(jasperPrint); | |
| SimpleOutputStreamExporterOutput itemOutput = new SimpleOutputStreamExporterOutput(relatorio); | |
| exporter.setExporterInput(itemsInput); | |
| exporter.setExporterOutput(itemOutput); | |
| exporter.exportReport(); | |
| }catch(Exception ex) { | |
| ex.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment