Jump to content
We've recently updated our Privacy Statement, available here ×

command line report generation


darthwader100

Recommended Posts

Are there any command-line frontends available to JasperReports?

 

I have designed a report using iReport. Now I want to do something simple in my Perl cgi script like calling a command-line program with the report definition as a parameter and get a pdf in return that I can present to the web user.

 

I am new to JasperReports and any help is appreciated.

Post edited by: darthwader100, at: 2006/10/27 11:18

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Are you familiar with the java language at all? Its a fairly straightforward bit of code if you are.

 

 

The only tricky part is getting the right data source depending on the requirements of your report. Here is a sample program I would use, where the only thing that is left to change is the datasource:

 

Code:
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class JavaReportRunner {

//args[0] - full path to .jrxml file
//args[1] - full path to output pdf file
public static void main(String[] args) {
JasperReport jasperReport;
JasperPrint jasperPrint;
try
{

jasperReport = JasperCompileManager.compileReport(args[0]);

Map customParameters = new HashMap();

jasperPrint = JasperFillManager.fillReport(
jasperReport, customParameters, new JREmptyDataSource());

JasperExportManager.exportReportToPdfFile(
jasperPrint, args[1]);

}
catch (JRException e)
{
e.printStackTrace();
}

}
}

 

you would then compile this code to a java .class file and call this file using the appropriate java commands.

 

HTH,

Robin

Link to comment
Share on other sites

  • 8 months later...

Came across this post when I had a similar need and wrote a simple java command line utility like the above to generate PDF or HTML to disk and optionally email. It can be downloaded at http://www.gtportalbase.com/opensource

 

At time of writing, only tested on two computers, so anyone who uses it please email me if you get any problems.

 

Oliver

Post edited by: okohll, at: 2007/07/05 13:34

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...