Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Migration from Jasper to BIRT
sowndharya
<p>Hi all,</p><p> </p><p>I need to migrate form Jasper to Birt report generation.</p><p> </p><p>currenty my java application generates dynamic reports using Jasper.</p><p> </p><p>In that ther is a functionality called Jasper Print, which generates empty document. I am passing a bean file, servletcontext and a service class as arguments</p><p> </p><p>Do anybody knows a similar function like Jasper Print- in BIRT????</p><p> </p><p>Please suggest me..</p><p> </p><p> </p><p>Thanks</p><p>Sowndharya</p><p> </p>
Find more posts tagged with
Comments
kclark
<p>Take a look at <a data-ipb='nomediaparse' href='
http://www.eclipse.org/birt/phoenix/deploy/designEngineAPI.php'>this
link</a> that shows how to use the design engine API. If you're just wanting to generate an empty rptdesign then you could do something like this.</p><pre class="_prettyXprint _lang-">public class MyBirtApplication { public static void newReport(String reportname) throws ContentException, NameException, IOException { SessionHandle session = DesignEngine.newSession( null ); ReportDesignHandle design = session.createDesign( ); ElementFactory factory = design.getElementFactory( ); DesignElementHandle element = factory.newSimpleMasterPage( "Page Master" ); design.getMasterPages( ).add( element ); design.saveAs( reportname ); design.close( ); } public static void main(String[] args) throws ContentException, NameException, IOException { System.out.print("Creating rptdesign..."); newReport("C:/Users/kclark/Desktop/test.rptdesign"); System.out.println("[DONE]"); }}</pre>
sowndharya
<p>Thanks Kclark...</p><p> </p><p>1.Can we add columns dynamically based on the user input in BIRT???</p><p> </p><p>In Jasper , FastReportBuilder has been used to add columns dynamically..</p><p> </p><p>For example, In my report 5 columns are mandatory and the next no. of columns differs based on user input.</p><p>Say for example, if the user gives two more additional inputs , after the 5 th column I should add 2 more columns etc..</p><p> </p><p>2. Can we add BIRT Reports without connecting to the datasource and datset??</p><p> </p><p>Pls help me out in this regard</p><p> </p><p>Sowndharya</p>
kclark
<p>You're welcome. In the link in my last post it shows how to build a grid in your code. It would look like this</p><pre class="_prettyXprint _lang-">GridHandle grid = factory.newGridItem( null, 2 /* cols */, 1 /* row */ );design.getBody( ).add( grid );grid.setWidth( "100%" );</pre><p>So if you want to add columns or rows based on user input just change that code to something like</p><pre class="_prettyXprint _lang-">int nRows;int nCols;// get rows and columns for the customerGridHandle grid = factory.newGridItem( null, nCols /* cols */, nRows /* row */ );design.getBody( ).add( grid );grid.setWidth( "100%" );</pre><p>You don't need to connect to a data source to create a report. Can you explain what you're trying to do a little more with this?</p>
sowndharya
<p>Thanks for the reply Kclark..</p><p> </p><p>My requirement is to generate a report for a particular project created by the user . In that report some columns are mandatory and some columns differs based on the user input.</p><p> </p><p>This report generation has already been done woth Jasper. But we want to migrate to BIRT and while exploring about BIRT I found that we should connect to Database and data source to generate the report.</p><p> </p><p>I generated the report by integrating with Datasource and Date Set. But all data from the database will be displayed in the report.</p><p> </p><p>But I want to generate the report for a particular project based on the user requirement and want to integrate with our application, So I thought of creating the Birt design itself dynamically and getting the data from the POJO Class to generate the report.</p><p>
</p><p> </p><p>I am using this Grid Handle .. But I couldnt add a image in the header of the page..</p><p> </p><p>SimpleMasterPageHandle masterPage = efactory.newSimpleMasterPage( "Page Master" ); </p><p>designHandle.getMasterPages( ).add( masterPage );</p><p> </p><p>ImageHandle imageHandle = designHandle.getElementFactory().newImage("Header");</p><p>imageHandle.setWidth("17.75cm");</p><p>imageHandle.setHeight("1.5cm");</p><p>imageHandle.setFile(servletContext.getRealPath("/images/boschLogo.png")</p><p>masterPage.getPageHeader().add(imageHandle);</p><p> </p><p> </p><p>Pls tell me wats wrong in this... Pls give me a example to add a image in the header of the page...</p><p> </p><p> </p><p>Thanks & Regards</p><p>Sowndharya V</p><p> </p><p> </p>
sowndharya
<p>I tried to align the label in a cell content to the center with this code</p><p> </p><p>labelSection.setProperty(IStyleModel.TEXT_ALIGN_PROP, DesignChoiceConstants.TEXT_ALIGN_CENTER);</p><p> </p><p>But If i give this i couldnt see the label itself.</p><p>Pls tell me how to give alignment to label or content in a cell</p><p> </p><p>Thanks</p><p>Sowndharya V</p>
kclark
<p>I wrote a simple example that I've attached, I used 4.3.1 for this example. Let me know if you have any questions.</p>
sowndharya
<p>Hi,</p><p> </p><p>If i i give border to my grid and cell , the borders are mismatching with each other .</p><p> </p><p>I did like this</p><p> </p><p>For example</p><p> GridHandle gridSample = efactory.newGridItem( null, 1 , 1 );
designHandle.getBody( ).add( gridSample );
RowHandle rowSample= (RowHandle)gridSample.getRows( ).get( 0 );
gridSample.setProperty(IStyleModel.BORDER_BOTTOM_COLOR_PROP, "#000000");
gridSample.setProperty(IStyleModel.BORDER_BOTTOM_STYLE_PROP, "solid");
gridSample.setProperty(IStyleModel.BORDER_BOTTOM_WIDTH_PROP, "thin");
gridSample.setProperty(IStyleModel.BORDER_LEFT_COLOR_PROP, "#000000");
gridSample.setProperty(IStyleModel.BORDER_LEFT_STYLE_PROP, "solid");
gridSample.setProperty(IStyleModel.BORDER_LEFT_WIDTH_PROP, "thin");</p><p> </p><p> gridSample.setProperty(IStyleModel.BORDER_RIGHT_COLOR_PROP, "#000000");
gridSample.setProperty(IStyleModel.BORDER_RIGHT_STYLE_PROP, "solid");
gridSample.setProperty(IStyleModel.BORDER_RIGHT_WIDTH_PROP, "thin");
gridSample.setProperty(IStyleModel.BORDER_TOP_COLOR_PROP, "#000000" );
gridSample.setProperty(IStyleModel.BORDER_TOP_STYLE_PROP, "solid" );
gridSample.setProperty(IStyleModel.BORDER_TOP_WIDTH_PROP, "thin" );
LabelHandle labelsample = efactory.newLabel( null );
CellHandle cellSample = (CellHandle)rowSample.getCells( ).get( 0 );
cellSample.getContent( ).add( labelsample );
labelsample.setText( "Sample" );</p><p> </p><p>I got output like this(Pls see the rounded part) . See the borders at the corners are mismatched.</p><p> </p><p>Pls help me in this regard</p><p> </p><p>Thanks,</p><p> </p><p>Sowndharya</p>
sowndharya
<p>Hi Kclark,</p><p> </p><p>I want to know the minimum no. of jars to create a BIRT report dynamically.</p><p> </p><p>As of now am using some 63 Jars, But I want to use the Jars only needed for my project.</p><p> </p><p>Please Help me.</p><p> </p><p>RequestContext context = org.springframework.webflow.execution.RequestContextHolder.<em class='bbc'>getRequestContext</em>();</p><p>ServletContext servletContext = ((HttpServletRequest)context.getExternalContext().getNativeRequest()).getSession().getServletContext(); </p><p>IReportEngine birtReportEngine = BirtEngine.<em class='bbc'>getBirtEngine</em>(servletContext);</p><p> </p><p><strong class='bbc'>try</strong> {</p><p> </p><p>//Configure the Engine and start the Platform </p><p>DesignConfig config = <strong class='bbc'>new</strong> DesignConfig( );</p><p>IDesignEngine engine = <strong class='bbc'>null</strong>;</p><p> </p><p><strong class='bbc'>try</strong>{</p><p>org.eclipse.birt.core.framework.Platform.<em class='bbc'>startup</em>( config );</p><p>IDesignEngineFactory factory = (IDesignEngineFactory) </p><p>org.eclipse.birt.core.framework.Platform.<em class='bbc'>createFactoryObject</em>( IDesignEngineFactory.<em class='bbc'>EXTENSION_DESIGN_ENGINE_FACTORY</em> );</p><p>engine = factory.createDesignEngine( config ); </p><p>}</p><p><strong class='bbc'>catch</strong>( Exception ex ){</p><p>ex.printStackTrace();</p><p>} </p><p> </p><p>SessionHandle session = engine.newSessionHandle( ULocale.<em class='bbc'>ENGLISH</em> );</p><p> </p><p>IReportRunnable design = <strong class='bbc'>null</strong>;</p><p> </p><p>// Create a new report design.</p><p>ReportDesignHandle designHandle = session.createDesign( );</p><p>getReportHelper().buildReport(userBean, boundaryConditionsCtgService, servletContext, designHandle);</p><p> </p><p>design = birtReportEngine.openReportDesign(designHandle);</p><p>IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask( design ); </p><p> </p><p> </p><p>
@SuppressWarnings("
;deprecation")</p><p><del class='bbc'>HTMLRenderContext</del> renderContext = <strong class='bbc'>new</strong> HTMLRenderContext();</p><p> </p><p>
@SuppressWarnings("
;deprecation")</p><p>HashMap<String, <del class='bbc'>HTMLRenderContext</del>> contextMap = <strong class='bbc'>new</strong> HashMap<String, <del class='bbc'>HTMLRenderContext</del>>();</p><p>//contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );</p><p>contextMap.put( EngineConstants.<em class='bbc'>APPCONTEXT_PDF_RENDER_CONTEXT</em>, renderContext );</p><p>task.setAppContext(contextMap);</p><p>HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getNativeResponse();</p><p> </p><p>ServletOutputStream servletOutputStream = response.getOutputStream();</p><p>HTMLRenderOption options = <strong class='bbc'>new</strong> HTMLRenderOption();</p><p>options.setImageHandler( <strong class='bbc'>new</strong> HTMLServerImageHandler() );</p><p>options.setImageDirectory( servletContext.getRealPath("WEB-INF/template/boschLogo.png"));</p><p>//options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);</p><p>options.setOutputFormat(HTMLRenderOption.<em class='bbc'>OUTPUT_FORMAT_PDF</em>);</p><p> </p><p>response.setContentType("application/pdf");</p><p>options.setOutputStream(response.getOutputStream());</p><p>task.setRenderOption(options);</p><p> </p><p>//run report</p><p>task.run();</p><p> </p><p> </p><p>servletOutputStream.flush();</p><p>servletOutputStream.close();</p><p>context.getExternalContext().recordResponseComplete();</p><p>task.close();</p><p>} <strong class='bbc'>catch</strong> (Exception e) {</p><p>// <strong class='bbc'>TODO</strong> Auto-generated catch block</p><p>e.printStackTrace();</p><p>}</p><p> </p><p>and also like this also</p><p> </p><p> </p><p>ElementFactory efactory = designHandle.getElementFactory( );</p><p> </p><p>// Create a simple master page that describes how the report will appear when printed.</p><p>SimpleMasterPageHandle masterPage = efactory.newSimpleMasterPage( "Page Master" ); </p><p>designHandle.getMasterPages( ).add( masterPage );</p><p>DateFormat dateFormat = <strong class='bbc'>new</strong> SimpleDateFormat("MM/dd/yyyy HH:mm:ss");</p><p>Date date = <strong class='bbc'>new</strong> Date();</p><p>System.<em class='bbc'>out</em>.println(dateFormat.format(date));</p><p>LabelHandle labelDate = efactory.newLabel( <strong class='bbc'>null</strong> );</p><p>labelDate.setText( dateFormat.format(date) ); </p><p>masterPage.getPageFooter().add(labelDate);</p><p>masterPage.setPageType(DesignChoiceConstants.<em class='bbc'>PAGE_SIZE_A4</em>);</p><p> </p><p> </p><p>ImageHandle imageHandle = designHandle.getElementFactory().newImage(<strong class='bbc'>null</strong>);</p><p>imageHandle.setWidth("2.5cm");</p><p>imageHandle.setHeight("1cm"); </p><p>Expression expression = <strong class='bbc'>new</strong> Expression(servletContext.getRealPath("/images/boschLogo.png"), ExpressionType.<em class='bbc'>CONSTANT</em>); </p><p>imageHandle.setSource("file");</p><p>imageHandle.setExpressionProperty("uri", expression);</p><p>masterPage.getPageHeader().add(imageHandle);</p><p> </p><p> </p><p> </p><p>// Create First Grid </p><p> </p><p>GridHandle grid1 = efactory.newGridItem( <strong class='bbc'>null</strong>, (3+platformBoundaryCat.size()) , segSecMap.size()+ projFilDtos.size() + 1 );</p><p>designHandle.getBody( ).add( grid1 );</p><p>grid1.setWidth("100%");</p><p>setBorder(grid1);</p><p> </p><p> </p><p>Thanks & Regards</p><p>Sowndharya V</p>