I-Net Clear Report Engine is an excellent tool which also can support standard HTML/CSS well. You can define rpt template by clear designer, and can create datasource to query result from database, pass parameter by java......
import java.io.FileOutputStream;
import com.inet.report.Datasource;
import com.inet.report.Engine;
/**
* @Class name: IClearTest.java
*
* Short description on the purpose of the program.
*
* @author: wangxiang
* @modified: 2011-11-30
*
*/
public class IClearTest {
private static boolean useStdout=false;
private static String reportFile = "file:D:/Report4.rpt";
/**
* @param args
*/
static void usage () {
System.err.println("Usage: ProgrammingTheEngine [--use-stdout]");
System.exit(1);
}
/**
* Checks if parameter values has been set.
* @param args first parameter is stdout, second parameter is report file URL
*/
static void getOpt (String[] args) {
for (int i = 0; i< args.length; i++) {
if (args[i].equals("--use-stdout")) {
useStdout = true;
System.err.println("writing PDF file to stdout");
}
else if (args[i].equals("--report")) {
reportFile = args[++i];
} else {
usage();
}
}
}
/**
* Executes a report and exports it to PDF.
* @param args first parameter is stdout, second parameter is report file URL
*/
public static void main(String[] args) {
getOpt(args);
try {
// Create an engine -> pdf export
Engine engine = new Engine(Engine.EXPORT_PDF);
// Set the report file
engine.setReportFile(reportFile);
// At this point you can change the default values from the rpt file, e.g.:
// Change Data Source Configuration - Use another database at runtime as at design time
Datasource ds = engine.getDatabaseTables().getDatasource(0);
ds.setDataSourceConfigurationName( "ORCL" ); // name of the Data Source Configuration
ds.setUsername("userid"); // that should be used for creation of database connection
ds.setPassword("password"); // If the password is not saved in Data Source Configuration
// Set Parameter Field values
engine.setPrompt("htmlContent", "<table><tr><td>test</td></tr></table>");
// Start the report execution
engine.execute();
// Open the output file and save the data in a .pdf file or in standard out
java.io.OutputStream pdfFile;
if(useStdout) {
pdfFile = System.out;
} else {
pdfFile = new FileOutputStream("D:/cleartest.pdf");
}
// Request all report pages from the engine
for(int i=1;i<=engine.getPageCount();i++) {
pdfFile.write(engine.getPageData(i));
}
if(useStdout) {
pdfFile.flush();
} else {
pdfFile.close();
}
} catch (Throwable t ) {
t.printStackTrace();
}
System.exit(0);
}
}