Monday, December 30, 2013

Simple Print from java

Printing from java code
Initialize

        JasperPrint jasperPrint = null;



JRXML file processing

JasperCompileManager.compileReportToFile(application.getRealPath("/reports/"+reportTemplate));
File reportFile = new File(application.getRealPath("/reports/"+reportRealPath));
if (!reportFile.exists())
throw new JRRuntimeException("File " + reportRealPath + " not found. The report design must be compiled first.");
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());



Get all your Report's parameters

Map<String, Object> parameters = new HashMap<String, Object>();
jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,new JREmptyDataSource());


Assign output view

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jp);
printDocumentToScreen(response, jp, viewType, reportType2);


private void printDocumentToScreen(HttpServletResponse response, JasperPrint jp, String reportView, String reportType) throws IOException{

byte bytes[] = null;
if(reportView.equalsIgnoreCase(VIEW_OPTION_HTML))
bytes = GenerateHTML.generateHTML(jp);
else if(reportView.equalsIgnoreCase(VIEW_OPTION_PDF))
bytes = GeneratePDF.generatePDF(jp);
else if(reportView.equalsIgnoreCase(VIEW_OPTION_XLS))
bytes = GenerateXLS.generateXLS(jp);
else if(reportView.equalsIgnoreCase(VIEW_OPTION_OTD))
bytes = GenerateODT.generateODT(jp);

response.setContentType("application/xls/csv/html/pdf/txt/html");
response.setHeader("Content-Disposition", "attachment;filename="+reportType+"."+reportView);
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes,0,bytes.length);
response.getOutputStream().flush();
}



Write you new about JREmptyDataSource() in another post.

These are the basic how to pass values from java to iReport

Friday, June 21, 2013

What is iReport , jasper Report , jfreechart How they are related ?

At first lot of doubts arise in my mind

iReport?

iReport is a graphical/visual tool for creating jasper reports.Design the report drag and drop do necessary changes ....s. Dynamic content is created using Parameters, Fields and  Variables . A XML file is created with extension jrxml for you.

What I found in their site is
iReport is a visual report designer for JasperReports. The library is a report engine that can be integrated in your open or commercial application to generate the reports designed with iReport, display them on screen or export them in a final format like PDF, OpenOffice, DOCX and many others. Alternatively, you can stream the result through a web application or send the final document directly to a printer. JasperReports is in some way the core of iReport.

JasperReports
Engine that takes the XML file and forms a report out of that file using the data source specified in the XML file.

jfreechart 
Library for generating charts like bar,line,pie etc.

Thursday, June 20, 2013

Introduction

When I start my report generation with iReport I totally fed up. Being a starter, there is not much online help or tutorials. Take a lot of time in the beginning .After familiar I thought of starting this blog for fresh people like me.

Here I am planning to write whatever I know  with my little time after work and family.