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.
drrgfg
ReplyDeletenice.. really helpful..bro
ReplyDeleteThanks for this! I'm trying to put something like this inside a conditional but can't quite seem to get it working. On the last page we want a different master page all together.
ReplyDeleteI have the following:
if( pageNumber == totalPage ){
reportContext.getDesignHandle().getMasterPages().get(0).setProperty("masterPage","LastPage");
}else{
reportContext.getDesignHandle().getMasterPages().get(0).setProperty("masterPage","NotLastPage");
}
but can't quite seem to get this to work properly as each page seems to fall into the "else" statement.
Any input would be greatly appreciated.