Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » How to run BIRT reports using Java swing?
How to run BIRT reports using Java swing? [message #363069] Mon, 09 June 2008 09:46 Go to next message
Eclipse UserFriend
Originally posted by: yazdani.mojtaba.yahoo.com

I want to generate a PDF file to produce a report of my data within
database. Home of my Birt runtime is C:\birt-runtime-2_2_2.
I have a report at this path: C:\BIRT\MyReport.rptdesign So how to run and
show this report when I click on myButton in my swing JFrame? I want to
show the report within my Frame and also out of my Frame, what are my
options to show my report? Could any one please provide me a sample code
to do this?
Help me please because I'm so very confused with BIRT.
Re: How to run BIRT reports using Java swing? [message #363072 is a reply to message #363069] Mon, 09 June 2008 15:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Mojtaba,

From an earlier post:


Attached is an example of calling BIRT through SWING. It uses a
JEditorPane, which is probably not the best for displaying HTML. To
create this class add the libs in the ReportEngine/lib jars to your
classpath and in the code set your birt home property to the location of
your report engine.

Jason

package birt.swing.example;


import java.io.ByteArrayOutputStream;


import javax.swing.JEditorPane;

import javax.swing.JFrame;

import javax.swing.JScrollPane;


import org.eclipse.birt.core.framework.Platform;

import org.eclipse.birt.report.engine.api.EngineConfig;

import org.eclipse.birt.report.engine.api.HTMLRenderOption;

import org.eclipse.birt.report.engine.api.IReportEngine;

import org.eclipse.birt.report.engine.api.IReportEngineFactory;

import org.eclipse.birt.report.engine.api.IReportRunnable;

import org.eclipse.birt.report.engine.api.IRunAndRenderTask;


public class HtmlReport

extends JFrame

{

JEditorPane myEditorPane = null;

IReportEngine engine=null;

EngineConfig config = null;




HtmlReport ()

{


myEditorPane = new JEditorPane ();

myEditorPane.setEditable(false);


JScrollPane scrollPane = new JScrollPane(myEditorPane);

JFrame myframe = new JFrame("BIRT Report");

myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

myframe.getContentPane().add(scrollPane);

myframe.setSize(600, 600);

myframe.setVisible(true);


}


public void runReport()

{

try{


IReportRunnable design = null;

//Open the report design

design = engine.openReportDesign("c:/xfer/TopNPercent.rptdesign");

//Create task to run and render the report,

IRunAndRenderTask task = engine.createRunAndRenderTask(design);

HTMLRenderOption options = new HTMLRenderOption();

ByteArrayOutputStream bos = new ByteArrayOutputStream();

options.setOutputStream(bos);

options.setOutputFormat("html");

options.setEmbeddable(true);

task.setRenderOption(options);

task.run();

task.close();

myEditorPane.setContentType("text/html");

myEditorPane.setText(bos.toString());

System.out.println("Finished Gen");


}catch( Exception ex){

ex.printStackTrace();

}


}


public void startPlatform(){

try{

config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_2_1\\ReportEngine ");

Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform

..createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );

engine = factory.createReportEngine( config );

}catch( Exception e){

e.printStackTrace();

}

}

public void stopPlatform(){

engine.destroy();

Platform.shutdown();

}


public static void main (String[] args)

{


HtmlReport html = new HtmlReport ();

html.startPlatform();

System.out.println("Started");

html.runReport();

html.stopPlatform();

System.out.println("Finished");


}

}


Mojtaba Yazdani wrote:
> I want to generate a PDF file to produce a report of my data within
> database. Home of my Birt runtime is C:\birt-runtime-2_2_2.
> I have a report at this path: C:\BIRT\MyReport.rptdesign So how to run
> and show this report when I click on myButton in my swing JFrame? I want
> to show the report within my Frame and also out of my Frame, what are my
> options to show my report? Could any one please provide me a sample code
> to do this?
> Help me please because I'm so very confused with BIRT.
>
Thanks but there is an error [message #363102 is a reply to message #363072] Tue, 10 June 2008 05:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yazdani.mojtaba.yahoo.com

Thanks, I add mysql-connector-java-5.1.5-bin.jar lib to my project and run
your code but I see this error message:

SEVERE: DriverClassLoader failed to load class: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Re: Thanks but there is an error [message #363117 is a reply to message #363102] Tue, 10 June 2008 16:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Mojtaba,

Either put the mysql jar in the the jdbc plugin drivers directory
underneath the birt runtime or add similar code to your program:
config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_2_1\\ReportEngine ");
HashMap context = new HashMap( );
context.put("OdaJDBCDriverClassPath",
"C:/test/mysql-connector-java-5.0.4-bin.jar");
config.setAppContext(context);

Jason

Mojtaba Yazdani wrote:
> Thanks, I add mysql-connector-java-5.1.5-bin.jar lib to my project and
> run your code but I see this error message:
>
> SEVERE: DriverClassLoader failed to load class: com.mysql.jdbc.Driver
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
>
Question [message #363143 is a reply to message #363117] Wed, 11 June 2008 04:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yazdani.mojtaba.yahoo.com

Thanks so very much dear Jason, you said that JEditorPane is not the best
for displaying HTML. What's the standard and popular way for display
reports to the end user? When produce reports as PDF format how I can
display them? How to deploy reports with my application?

kind Regards
Mojtaba
Re: Question [message #363161 is a reply to message #363143] Wed, 11 June 2008 15:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Mojtaba,

I said this because the JEditorPane is not the best browser :>
If you are using Java 1.6 you may want to look at the java.awt.Desktop
class, which offers some solutions for opening existing apps including
the browser. If you are using an earlier version there are alot of libs
available (google) that help.

Jason

Mojtaba Yazdani wrote:
> Thanks so very much dear Jason, you said that JEditorPane is not the
> best for displaying HTML. What's the standard and popular way for
> display reports to the end user? When produce reports as PDF format how
> I can display them? How to deploy reports with my application?
>
> kind Regards Mojtaba
>
Re: Question [message #363173 is a reply to message #363161] Thu, 12 June 2008 00:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m.n.com

There is a new open source Swing Browser component - (can't find it now)

Also -http://lobobrowser.org/index.jsp


If you are using Eclipse RCP, someone created a plugin for Mozilla -
http://www.eclipsemozilla.org/


I typically display BIRT reports as PDFS. I use a PDF viewer. Unless
your product is GPL then there is not an opensource one. I use
JPDFViewer - it's worth the money.

Jason Weathersby wrote:
> Mojtaba,
>
> I said this because the JEditorPane is not the best browser :>
> If you are using Java 1.6 you may want to look at the java.awt.Desktop
> class, which offers some solutions for opening existing apps including
> the browser. If you are using an earlier version there are alot of libs
> available (google) that help.
>
> Jason
>
> Mojtaba Yazdani wrote:
>> Thanks so very much dear Jason, you said that JEditorPane is not the
>> best for displaying HTML. What's the standard and popular way for
>> display reports to the end user? When produce reports as PDF format
>> how I can display them? How to deploy reports with my application?
>>
>> kind Regards Mojtaba
>>
Re: How to run BIRT reports using Java swing? [message #716487 is a reply to message #363069] Wed, 17 August 2011 14:35 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
I've tried to preview the report in the JEditorPane with the class posted in the previous post, the only thing that doesn't work is the chart in the report that doesn't appear in the JEditorPane even if it is present in the report, Why ?

I'm also interested in the generation of the pdf to display in the JEditorPane control, someone have sample code to post ?


Thanks.

(no subject) [message #716549 is a reply to message #716487] Wed, 17 August 2011 16:36 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Change the chart type from SVG to PNG. This can be done on the first
tab of the chart wizard.

I do not think a JEditorPane supports PDF.

You could render pdf to the Byte Array output stream and use something
like the following to display it.
http://today.java.net/article/2005/10/18/accessing-pdf-document-acrobat-viewer-javabean

Jason

On 8/17/2011 10:35 AM, Alessio Pollero wrote:
> I've tried to preview the report in the JEditorPane with the class
> posted in the previous post, the only thing that doesn't work is the
> chart in the report that doesn't appear in the JEditorPane even if it is
> present in the report, Why ?
> I'm also interested in the generation of the pdf to display in the
> JEditorPane control, someone have sample code to post ?
>
> Thanks.
>
>
Re: (no subject) [message #721021 is a reply to message #716549] Wed, 31 August 2011 17:50 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
I have another problem, when preview the HTML of the report in the JeditorPane using the code posted above :
the page generated if displayed in a browser is showed correctly and the size of the component of the page is exactly the same as the original, when i show the HTML code on the JeditoPane a get a page with different size ( seems that is shrunk horizontally and also the text is wrapped, i wanna to have the page shown as it is, without page shrink and wrapping of the text,
Is it Possible ?
Re: (no subject) [message #721117 is a reply to message #721021] Wed, 31 August 2011 22:40 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

This may be an issue with the JeditorPane or some of the styles we use.
You may want to try some of the other render options like:

options.setEmbeddable(false);
and
options.setEnableInlineStyle(true);

Jason

On 8/31/2011 1:50 PM, Alessio Pollero wrote:
> I have another problem, when preview the HTML of the report in the
> JeditorPane using the code posted above : the page generated if
> displayed in a browser is showed correctly and the size of the component
> of the page is exactly the same as the original, when i show the HTML
> code on the JeditoPane a get a page with different size ( seems that is
> shrunk horizontally and also the text is wrapped, i wanna to have the
> page shown as it is, without page shrink and wrapping of the text,
> Is it Possible ?
>
Re: (no subject) [message #721257 is a reply to message #721117] Thu, 01 September 2011 09:33 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 74
Registered: August 2011
Member
I've tried but it doesn't work, the only solution that i've found is change the width property of each report element from a fixed value (inches) to a relative value (%), the it worked correctly.

Re: How to run BIRT reports using Java swing? [message #834071 is a reply to message #363069] Sun, 01 April 2012 10:57 Go to previous messageGo to next message
swathi puttaraj is currently offline swathi puttarajFriend
Messages: 2
Registered: April 2012
Junior Member
Hi,
I av this foll code.. bt m nt able to get the pdf.. in the log it says.. running the report wit parameters..
i av js created one simple report with 2parameters.. setting it in java..
package com.swat;

import java.io.ByteArrayOutputStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.impl.RunAndRenderTask;
import org.eclipse.birt.report.engine.api.impl.RunTask;
import org.eclipse.datatools.connectivity.oda.IParameterRowSet;

public class CODE {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
EngineConfig config=new EngineConfig();
config.setEngineHome("C:\\birt-runtime-3_7_2\\ReportEngine");

config.setLogConfig("c:/temp", Level.FINE);


Platform.startup( config );

IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine engine = factory.createReportEngine( config );


System.out.println("HELLO");

IReportRunnable design=engine.openReportDesign("C:/Users/Raj/workspace/Report/new_report1.rptdesign");
IGetParameterDefinitionTask task=engine.createGetParameterDefinitionTask(design);
Collection params=task.getParameterDefns(true);

Iterator iter=params.iterator();

while(iter.hasNext())
{
IParameterDefnBase param=(IParameterDefnBase)iter.next();

if(param instanceof IParameterGroupDefn)
{
//get the group name
IParameterGroupDefn group=(IParameterGroupDefn)param;
System.out.println("parameter group name:"+group.getName());

//parameters inside the group
Iterator i2=group.getContents().iterator();
while(i2.hasNext())
{
IScalarParameterDefn scalar=(IScalarParameterDefn)i2.next();
System.out.println("parameters inside group:"+scalar.getName());
}
}
else
{
IScalarParameterDefn scalar1=(IScalarParameterDefn)param;
System.out.println("normal parameters:"+scalar1.getName());
}

}


IRunAndRenderTask task1=engine.createRunAndRenderTask(design);
task1.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,RunAndRenderTask.class.getClassLoader());
String number="123";
String studentId="1AT07I";
task1.setParameterValue("SID",number );
task1.setParameterValue("Student ID",studentId);
task1.validateParameters();

PDFRenderOption options=new PDFRenderOption();
options.setOutputFormat("pdf");

options.setOutputFileName("output/sample/GettingPDF.pdf");

task1.setRenderOption(options);
task1.run();
task1.close();

System.out.println(studentId);

}
catch (BirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

wn i print the studentid at the end.. its printin.. it means.. it is gettin set.. bt hw do i open it in pdf

[Updated on: Sun, 01 April 2012 11:02]

Report message to a moderator

Re: How to run BIRT reports using Java swing? [message #835711 is a reply to message #834071] Tue, 03 April 2012 15:23 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

If you have added all the pojo jars to your projects classpath you do
not need to set:
config.setEngineHome("C:\\birt-runtime-3_7_2\\ReportEngine");


Jason

On 4/1/2012 6:57 AM, swathi puttaraj wrote:
> Hi,
> I av this foll code.. bt m nt able to get the pdf.. in the log it says..
> running the report wit parameters.. i av js created one simple report
> with 2parameters.. setting it in java..
> package com.swat;
>
> import java.io.ByteArrayOutputStream;
> import java.util.Collection;
> import java.util.Iterator;
> import java.util.logging.Level;
>
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.report.engine.api.EngineConfig;
> import org.eclipse.birt.report.engine.api.EngineConstants;
> import org.eclipse.birt.report.engine.api.HTMLRenderOption;
> import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
> import org.eclipse.birt.report.engine.api.IParameterDefnBase;
> import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
> import org.eclipse.birt.report.engine.api.IRenderOption;
> import org.eclipse.birt.report.engine.api.IReportEngine;
> import org.eclipse.birt.report.engine.api.IReportEngineFactory;
> import org.eclipse.birt.report.engine.api.IReportRunnable;
> import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
> import org.eclipse.birt.report.engine.api.IRunTask;
> import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
> import org.eclipse.birt.report.engine.api.PDFRenderOption;
> import org.eclipse.birt.report.engine.api.RenderOption;
> import org.eclipse.birt.report.engine.api.impl.RunAndRenderTask;
> import org.eclipse.birt.report.engine.api.impl.RunTask;
> import org.eclipse.datatools.connectivity.oda.IParameterRowSet;
>
> public class CODE {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> try {
> EngineConfig config=new EngineConfig();
> config.setEngineHome("C:\\birt-runtime-3_7_2\\ReportEngine");
> config.setLogConfig("c:/temp", Level.FINE);
> Platform.startup( config );
> IReportEngineFactory factory = (IReportEngineFactory) Platform
> .createFactoryObject(
> IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
> IReportEngine engine = factory.createReportEngine( config );
>
>
> System.out.println("HELLO");
> IReportRunnable
> design=engine.openReportDesign("C:/Users/Raj/workspace/Report/new_report1.rptdesign");
>
> IGetParameterDefinitionTask
> task=engine.createGetParameterDefinitionTask(design);
> Collection params=task.getParameterDefns(true);
> Iterator iter=params.iterator();
> while(iter.hasNext())
> {
> IParameterDefnBase param=(IParameterDefnBase)iter.next();
>
> if(param instanceof IParameterGroupDefn)
> {
> //get the group name
> IParameterGroupDefn group=(IParameterGroupDefn)param;
> System.out.println("parameter group name:"+group.getName());
>
> //parameters inside the group
> Iterator i2=group.getContents().iterator();
> while(i2.hasNext())
> {
> IScalarParameterDefn scalar=(IScalarParameterDefn)i2.next();
> System.out.println("parameters inside group:"+scalar.getName());
> }
> }
> else
> {
> IScalarParameterDefn scalar1=(IScalarParameterDefn)param;
> System.out.println("normal parameters:"+scalar1.getName());
> }
>
> }
> IRunAndRenderTask task1=engine.createRunAndRenderTask(design);
> task1.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,RunAndRenderTask.class.getClassLoader());
>
> String number="123";
> String studentId="1AT07I";
> task1.setParameterValue("SID",number );
> task1.setParameterValue("Student ID",studentId);
> task1.validateParameters();
> PDFRenderOption options=new PDFRenderOption();
> options.setOutputFormat("pdf");
> options.setOutputFileName("output/sample/GettingPDF.pdf");
> task1.setRenderOption(options);
> task1.run();
> task1.close();
> System.out.println(studentId);
> }
> catch (BirtException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> }
>
>
Re: How to run BIRT reports using Java swing? [message #838738 is a reply to message #835711] Sat, 07 April 2012 15:06 Go to previous message
swathi puttaraj is currently offline swathi puttarajFriend
Messages: 2
Registered: April 2012
Junior Member
thnks:-)
Previous Topic:Crosstab style
Next Topic:Why not work? (DataTime)
Goto Forum:
  


Current Time: Thu Mar 28 21:46:40 GMT 2024

Powered by FUDForum. Page generated in 0.04274 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top