I-Net Clear Report Engine

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);
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值