1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| EngineConfig config = new EngineConfig();
// Create the report engine
HTMLEmitterConfig hc = new HTMLEmitterConfig();
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();
//IReportEngineFactory factory = (IReportEngineFactory) Platform
// .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
//IReportEngine engine = factory.createReportEngine( config );
hc.setImageHandler(imageHandler);
config.setEmitterConfiguration(HTMLRenderOption.OUTPUT_FORMAT_HTML, hc);
ReportEngine engine = new ReportEngine(config);
IReportRunnable design = null;
try {
// Open a report design - use design to modify design, retrieve
// embedded images etc.
String reportPath = strPath;
FileInputStream fs = new FileInputStream(reportPath);
design = engine.openReportDesign(fs);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("c:/test/image");
HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
task.setAppContext(contextMap);
// Set rendering options - such as file or stream output,
// output format, whether it is embeddable, etc
IRenderOption options;
options = new HTMLRenderOption( );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
options.setOutputStream(bos);
options.setOutputFormat("html");
//task.setd
task.setRenderOption(options);
// run the report and destroy the engine
task.run();
task.close();
//set Browser text accordingly
browser.setText(bos.toString());
//browser.setLocation("javascript:print()");
bos.close();
//browser.execute()
engine.destroy();
button9.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
} |
Partager