How to dynamically set page orientation?

anoopnai
edited February 11, 2022 in Analytics #1

Hello all BIRT experts,

I’m just a beginner in BIRT and need your help to achieve following requirements to design a layout with three pages.

Here are my requirements for the design.

  1. First page is a covering letter that contain static text – This page should be always on portrait orientation
  2. Second page has fixed number of rows – This page should be always on portrait orientation
  3. Third page has fixed number of columns – Number of columns need to be on the third page would differ based on the data. so requirement is to display the third page in portrait orientation if there are only 10 or less number of columns. If more than 10 columns, third page needs to be on landscape orientation.

I have three master pages in my layout and each of them are created for each pages. How do I dynamically change the orientation only for third page based on a condition? I can write a condition based on fields present in each of those columns .. but, i'm missing the line of code that i need to write to get this working.

-Thank you
Anoop

Answers

  • Could you clarify why the orientation needs to be dynamic based on number of columns? Is the report dynamically creating columns? If not, why not just hard code it to make the third page portrait or landscape?

    Warning No formatter is installed for the format ipb
  • Hi Chad, thanks for your response.

    Yes, report dynamically creating columns.

    Columns less than or equal to 10 would fit in the third page if orientation is portrait. If there are 10 columns or more, data won't be printed properly in portrait as some of the columns will get shrink. so requirement is to generate a landscape based layout in such cases.

    In this use case, each worker is supposed to get a layout with three pages. for example, it's possible that some worker has one column on the third page, some may have 5 columns, some may have 15 columns.. workers who are likely to have more than 10 columns are very less. so hard coding the page to be landscape would force third page of the layout to be always on landscape even if worker has less number of columns ( for e.g. worker has just one column will also get a landscape oriented third page instead of portrait oriented one)

  • 1,2: You can set the elements relevant to pages 1 and 2 by selecting the element and adjusting the master page in Page Break to use a master page that is in portrait.

    3: Create a second master page that is in landscape and dynamically set the master page of the element(s) relevant to the third page to use the landscape masterpage or the portrait masterpage using the below call:
    reportContext.getDesignHandle().getElementByID(ElementID).setProperty("masterPage",masterPageName);

    I'm assuming that, since you have script to adjust the number of columns, that you have the capacity to determine the number of columns are going to be on that third page.

    Here is the property I'm referring to in the GUI:

    Warning No formatter is installed for the format ipb
  • Hi Chad, thanks again for your help.

    I tried following the steps you given but unable to make that to work.

    In your point #3, Do you mean to create second master page or third master page?

    I have attached rptdesign that i created just for implementing the change you mentioned. Can you take a look at this and correct me what am i doing wrong here please?

    1. Rptdesign has three master pages
    2. First and second master pages are set to 'auto' orientation and they're being displayed in Portrait as expected
    3. Third master page contain a table(Body-Third Table-Detail-Row-second cell-grid-row-cell (8358)) which has two rows in it . so my requirement is something like if second row in third page has data in it, display entire third page in landscape and first and second page are in portrait otherwise display third page in portrait orientation as same as first and second pages.

    I called following in one of the cell(element id : 8358) in third master page after setting master page orientation to 'landscape'.

    reportContext.getDesignHandle().getElementByID(8358).setProperty("masterPage","SimpleMasterPageThirdPage")

    Thanks

  • Chad Montgomery
    edited August 15, 2018 #6

    Your third page needs 2 master pages it can switch between, one that's portrait and one that's landscape. Your other pages can use the same portrait master page as the third page, but that's up to you.

    You shouldn't be setting the master page of the grid cell, but the master page of the entire table. As it's the entire table that shows up on the third page, and you're dictating whether the master page that the table should be using is portrait or landscape based on certain factors.

    Lastly, you mentioned something about no data in the second column. Are you saying that, in your final report, the number of columns actually is static, but some just won't have data depending on the users, or that you have code that actually builds out a specific number of table columns at runtime? This is an important distinction, because it completely changes how you'll check for "number of columns."

    Warning No formatter is installed for the format ipb
  • I created a second master page for third table and set that to landscape and first master page for third table is set to portrait and called below at third table level. Updated reportdesign is attached.

    reportContext.getDesignHandle().getElementByID(ElementID).setProperty("masterPage",masterPageName);

    So my requirement is exactly like below.

    1. first page and second page are displaying the way i wanted - so no worries
    2. Solution is needed for third page - currently sample rptdesign has two columns. Let me call it Column 1 and Column 2

    Column 1 -

    I'll add a grid to column1 and that grid will contain 4 columns and one row - those columns are static i.e. 4. some users will have all four columns data filled in it and some may not have data in it .. i'll hide columns for which no data in it by setting visibility. atleast one column of data would be always present for a user.

    Column 2

    This column also will have a grid and that grid will contain 4 columns and one row - hose columns are static i.e. 4. some users will have all four columns data filled in it and some may not have data in it .. i'll hide columns for which no data in it by setting visibility.

    So what i'm trying to achieve is; If no data present for column2. Third page of the layout should be on portrait

    If column 2 has data in it, third page of the layout should be on landscape.

    Would you be able to take a look at my rptdesign and correct what i'm doing wrong?

  • Do you already have a report with grids in them and outputting data? The way to go about determining which orientation to use depends on how you make the report.

    From what I can see based on your description, you'll probably want to increment some counter for each column that you hide/don't hide, and use that to determine whether the page should be portrait or landscape.

    Warning No formatter is installed for the format ipb
  • Thanks Chad for follow-up. Yes, I already have a report which is outputting data.

    My requirement is to display landscape orientation page if column has any data in it in the previously attached rptdesign.