public class PDFReportServiceAccess {
/** */
/** 初始化的状态 */
protected static boolean initStatus = false;
private static IReportEngine engine = null;
private static EngineConfig config = null;
private static IReportRunnable design = null;
//private static PDFRenderOption ro = null;
private static PDFRenderOption ro = null; // doubley0
/** */
/** 初始化资源 */
public void initilize() {
if (initStatus == true)
return;
try {
config = new EngineConfig();
config.setEngineHome("E://Program Files1//apache-tomcat-5.5.26//webapps//birt//WEB-INF//platform"); // birt doubley1
// runtime
// web应用中的报表引擎目录
config.setLogConfig("E://Program Files1//apache-tomcat-5.5.26//webapps//birt//logs", Level.FINE); //doubley2
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
engine.changeLogLevel(Level.WARNING);
ro = new PDFRenderOption();
ro.setBaseURL("http://localhost:8080/birt"); // birt runtime
// web应用
config.getEmitterConfigs().put("pdf", ro); // 生成pdf格式 doubley3
initStatus = true;
} catch (Exception ex) {
ex.printStackTrace();
initStatus = false;
}
}
/** */
/** 释放资源 */
public void release() {
engine.shutdown();
Platform.shutdown();
initStatus = false;
}
protected OutputStream run(String filename, HashMap parameters)
throws EngineException {
design = engine.openReportDesign(filename);
// Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
HashMap contextMap = new HashMap();
contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT, ro);
task.setAppContext(contextMap);
task.setParameterValues(parameters);
task.validateParameters();
OutputStream os = new ByteArrayOutputStream();
ro.setOutputStream(os);
ro.setOutputFormat("pdf"); //doubley4
task.setRenderOption(ro);
task.run();
task.close();
return os;
}
/** */
/**
* 生成PDF格式报表,以OutputStream格式返回
*
* @param filename
* 报表设计文件名全路径
* @param parameters
* 报表参数
* @return ByteArrayOutputStream
* @throws EngineException
*/
public OutputStream call(String filename, HashMap parameters)
throws EngineException {
initilize();
OutputStream os = run(filename, parameters);
release();
return os;
}
/** */
/**
* @param args
*/
public static void main(String[] args) {
HashMap parameters = new HashMap();
// 三个Report Parameters,名称必须在报表设计文件中预先定义好
//parameters.put("begindate", "2004/01/01");
//parameters.put("enddate", "2007/12/31");
//parameters.put("sql", " where cust_id = 1234567");
int temp=7;
parameters.put("mystr1", "7"); //doubley5
//parameters.put("mystr1", temp);
ByteArrayOutputStream bos = null;
PDFReportServiceAccess ebr = new PDFReportServiceAccess();
String filename = "E://Program Files1//apache-tomcat-5.5.26//webapps//birt//new_report1.rptdesign"; //doubley6
try {
bos = (ByteArrayOutputStream) ebr.call(filename, parameters);
OutputStream fis = new FileOutputStream("c:/test.pdf");
bos.writeTo(fis);
} catch (Exception e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
This paper investigates acoustic modeling for recognition of bird species from audio field recordings. First, the acoustic scene is decomposed into isolated segments, corresponding to detected ...
02-flappy bird.pdf
flappybird源代码[归纳].pdf
Flappy Bird java 源代码.pdf
FlappyBird_Java代码.pdf
ThunderBird常用组件
《flappy bird》是一款由来自越南的独立游戏开发者Dong Nguyen所开发的作品,游戏于2013年5月24日上线,并在2014年2月突然暴红。2014年2月,《Flappy Bird》被开发者本人从苹果及谷歌应用商店撤下。2014年8月份正式...
flappybird图像音频资源,用于配合《简单小游戏flappybird制作》相关博客。
该资源是flappy bird游戏涉及到的素材资源,包括背景、管道、小鸟的不同状态以及游戏开始、重启、失败等。
flappybird游戏资源,图片+音效
FLappy Bird,《flappybird》是由来自越南的独立游戏开发者DongNguyen所开发的作品,游戏中玩家必须控制一只小鸟,跨越由各种不同长度水管所组成的障碍。
该文章对于想学习鸟群算法的人来说是很不错的入门级读物
Internet Daemons "Hummingbird Inetd "——为基于Windows的桌面提供了UNIX功能。 Hummingbird Basic——为自动重复的函数创建强大的脚本。 SOCKS——为TCP/IP程序提供的无缝、透明的安全性; Kerberos——仅保证...
基于HTML5的Flappy bird游戏设计与开发.pdf
世界各国大学生优秀建筑毕业设计作品集
25-提交-自主学习Flappy Bird游戏实例介绍.pdf
全flappybird套图片和音效,学习开发必备
https://blog.csdn.net/cb269267/article/details/20214107 按照此博主操作分解出来的方法,如果需要可以去原博客自行操作,也可以直接下载本资源
Flappy Bird素材及公开课视频,适合自学开发FlappyBird游戏