Wednesday, February 12, 2014

Issues with Lines per page in BIRT PDF Report

   A normal BIRT report(not chart) generally have a table whose data is going to be spread over hundreds of pages. For example a sales report may have a table with columns like product name, price, count and purchase date. And that table may have thousands of rows that will take a lot number of pages when exported to PDF.

One problem with BIRT PDF report is that if report is not properly designed (table layout) then you may end of with blank spaces at the bottom or left due to the lines per page property of the report table. By defaults BIRT allocates 40 rows of  a report table in one page and then it move on to the next page. So if the table row data are less then the row height will be less and after 40 rows there will much space left on the page. On the other hand if your table rows have more data then increase in height of individual rows and eventually the page is not enough to adjust the 40 rows. In this case BIRT will squeeze the data to fit to the page(fit to page) and in this process it creates space in the left.

There are two ways this problem can be addressed. First configure BIRT to handle for you. Second, handle it yourself. I prefer the first one. Lets look both the approach.

Let BIRT Handle it - 
1. Make the report layout fixed (with auto layout this will not work). Go to report property and from the general tab select the radio Fixed Layout.
2. Select the table that will contain the report data and that you think will span over pages. Open the property editor for that table, and go to the Page Break tab.
3. There, leave the Before and Inside drop down choice.  For the After drop down select Always.
4. In the Page Break Interval provide 0. Do not leave it blank else it will default to 0.
5. Tick the Repeat Header choice if you want the table header on every page.
6. Make the width of the table 100%.
7. Make sure the width of the table, in the layout is fitting to the width of the report.
8. An additional check, select the table content row, open the property editor and make the Height blank.
 That is all, hope I have not missed any point. The report should come fine.

Handle It Yourself -
1. For this the report layout should be auto layout.
2. Create two Report Parameters LINES_PER_PAGE and ROW_HEIGHT.
3. From the property editor for the table, give a name to the table say "report_table".
4. Now select the report (can do this by clicking on the report not any component), open the script tab from the button. At the top you should see a Script drop down.
5. From the drop down, select beforeFactory and provide the following two lines of code
mytable = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("report_table");
mytable.setProperty("pageBreakInterval",params["LINES_PER_PAGE"].value);  
6. Now select the table content row and open the script tab. And select the onCreate from the drop down.
7. There provide the code this.height = params["ROW_HEIGHT"].value;
We are done with the dynamically setting of lines per page and row height. You can ask the user for these report parameter values or calculate it with some business logic.

Will improve this post if found some thing new on this topic.




Sunday, February 9, 2014

Dynamic page Orientation in BIRT report


In BIRT report and I guess in other reporting tools also, there are generally two different types of orientations. One is Portrait  and the other one is Landscape. The difference will be visible when  we export it to PDF format and take printout. Generally the Landscape orientation is preferred, when there is more number of columns i.e. we need more space in the horizontal direction.

Before we move on to see how to set orientation dynamically, lets first see how to do it statically. Here are the steps to follow.
1. The report is open and the eclipse IDE is in Report Design perspective.
2. Now select the Master Page tab from the tabs displaying at the bottom.
3. Open the Property Editor, which will be at right side top or bottom.
4. Choose Landscape from the Orientation drop down and save.
5. Its important that the report lay out must be fixed. If the report lay out is auto layout then the landscape orientation will not work.

The problem with Landscape orientation is that we will get less number of lines per page. So if we do not need more space in horizontal direction and choosing the landscape orientation then it may cause wastage of paper.

The orientation of BIRT report can be set dynamically through JavaScript. And the steps are
1. In the report design click on blank space in the report( to make sure that what we will do next is for the report, to avoid confusion what I mean is no other component of the report should be selected).
2. Then open the Script tab from the bottom.  At the top you should see a Script drop down with initialize default selected.
3. Select the beforeFactory from the drop down.
4. There add the code
     reportContext.getDesignHandle().getMasterPages().get(0).setProperty("orientation", "landscape"); 
 You can also put this code in side condition if you need.
5. You also needs to be sure that the report lay out is fixed.

Hope this will be helpful.