use of net.sf.jasperreports.export.SimpleOutputStreamExporterOutput in project bamboobsc by billchen198318.
the class JReportUtils method fillReportToResponse.
public static void fillReportToResponse(String reportId, Map<String, Object> paramMap, HttpServletResponse response) throws ServiceException, Exception {
if (StringUtils.isBlank(reportId)) {
throw new java.lang.IllegalArgumentException("error, reportId is blank");
}
TbSysJreport sysJreport = new TbSysJreport();
sysJreport.setReportId(reportId);
DefaultResult<TbSysJreport> result = sysJreportService.findEntityByUK(sysJreport);
if (result.getValue() == null) {
throw new ServiceException(result.getSystemMessage().getValue());
}
sysJreport = result.getValue();
String jasperFileFullPath = Constants.getDeployJasperReportDir() + "/" + sysJreport.getReportId() + "/" + sysJreport.getReportId() + ".jasper";
File jasperFile = new File(jasperFileFullPath);
if (!jasperFile.exists()) {
jasperFile = null;
throw new Exception("error, Files are missing : " + jasperFileFullPath);
}
InputStream reportSource = new FileInputStream(jasperFile);
Connection conn = null;
try {
conn = DataUtils.getConnection();
ServletOutputStream ouputStream = response.getOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, paramMap, conn);
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline; filename=" + sysJreport.getReportId() + ".pdf");
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
jrPdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(ouputStream));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
jrPdfExporter.setConfiguration(configuration);
configuration.setOwnerPassword(Constants.getEncryptorKey1());
jrPdfExporter.exportReport();
ouputStream.flush();
ouputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
DataUtils.doReleaseConnection(conn);
if (null != reportSource) {
try {
reportSource.close();
} catch (IOException e) {
e.printStackTrace();
}
}
reportSource = null;
jasperFile = null;
}
}
use of net.sf.jasperreports.export.SimpleOutputStreamExporterOutput in project jgnash by ccavanaugh.
the class JasperViewerDialogController method handleSaveAction.
@FXML
private void handleSaveAction() {
Preferences preferences = Preferences.userNodeForPackage(JasperViewerDialogController.class);
final String lastDir = preferences.get(LAST_DIR, null);
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
if (lastDir != null) {
fileChooser.setInitialDirectory(new File(lastDir));
}
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF Document", "*.pdf", "*.PDF"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("ODT Document", "*.odt", "*.ODT"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("DOCX Document", "*.docx", "*.DOCX"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XLSX Document", "*.xlsx", "*.XLSX"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV Document", "*.csv", "*.CSV"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("RTF Document", "*.rtf", "*.RTF"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
preferences.put(LAST_DIR, file.getParent());
switch(FileUtils.getFileExtension(file.getAbsolutePath()).toLowerCase(Locale.ROOT)) {
case "pdf":
try {
JasperExportManager.exportReportToPdfFile(jasperPrint.get(), file.getAbsolutePath());
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
case "odt":
try {
final JROdtExporter exporter = new JROdtExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
exporter.exportReport();
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
case "docx":
try {
final JRDocxExporter exporter = new JRDocxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
exporter.exportReport();
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
case "xlsx":
try {
final JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
final SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
case "csv":
try {
final JRCsvExporter exporter = new JRCsvExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
exporter.exportReport();
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
case "rtf":
try {
final JRRtfExporter exporter = new JRRtfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
exporter.exportReport();
} catch (final JRException e) {
StaticUIMethods.displayException(e);
}
break;
default:
}
}
}
use of net.sf.jasperreports.export.SimpleOutputStreamExporterOutput in project midpoint by Evolveum.
the class ReportCreateTaskHandler method generateReport.
private String generateReport(ReportType reportType, JasperPrint jasperPrint) throws JRException {
String destinationFileName = getDestinationFileName(reportType);
switch(reportType.getExport()) {
case PDF:
JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFileName);
break;
case XML:
JasperExportManager.exportReportToXmlFile(jasperPrint, destinationFileName, true);
break;
case XML_EMBED:
JasperExportManager.exportReportToXmlFile(jasperPrint, destinationFileName, true);
break;
case XHTML:
case HTML:
JasperExportManager.exportReportToHtmlFile(jasperPrint, destinationFileName);
break;
case CSV:
JRCsvExporter csvExporter = new JRCsvExporter();
csvExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
csvExporter.setExporterOutput(new SimpleWriterExporterOutput(destinationFileName));
csvExporter.exportReport();
break;
case RTF:
case XLS:
case ODT:
case ODS:
case DOCX:
case XLSX:
case PPTX:
case JXL:
ExporterInput input = new SimpleExporterInput(jasperPrint);
ExporterOutput output = new SimpleOutputStreamExporterOutput(destinationFileName);
Exporter exporter = createExporter(reportType.getExport());
if (exporter == null) {
break;
}
exporter.setExporterInput(input);
exporter.setExporterOutput(output);
exporter.exportReport();
break;
default:
break;
}
return destinationFileName;
}
use of net.sf.jasperreports.export.SimpleOutputStreamExporterOutput in project dhis2-core by dhis2.
the class JRExportUtils method export.
/**
* Export the provided JasperPrint the format given by type.
*
* @param type the type to export to. XLS, PDF and HTML are supported.
* @param out the OutputStream to export to.
* @param jasperPrint the JasperPrint to export.
* @throws JRException on export failure.
*/
public static void export(String type, OutputStream out, JasperPrint jasperPrint) throws JRException {
if (TYPE_XLS.equals(type)) {
SimpleXlsReportConfiguration config = new SimpleXlsReportConfiguration();
config.setDetectCellType(true);
config.setRemoveEmptySpaceBetweenRows(true);
config.setRemoveEmptySpaceBetweenRows(true);
config.setCollapseRowSpan(true);
config.setWhitePageBackground(false);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
exporter.setConfiguration(config);
exporter.exportReport();
} else if (TYPE_PDF.equals(type)) {
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
exporter.exportReport();
}
}
Aggregations