Home
Analytics
pageNumber and totalPage in layout, conditional text depending on pageNumber (in pdf)
hex
Hi,<br />
<br />
for a special report we need pageNumber and totalPage in the layout, not in footer or header.<br />
First thing I tried was to copy the grid/autotext from the masterpage to the layout. This worked in the design view but was not looking so nice. So I tried something else: I created a onRender script on a text with this:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.text = "Page" + pageNumber + "/" + pageTotal</pre>
thjs also worked in the design view.<br />
But when I tried both with a pdf, pageNumber and totalPage are always 1. My second solution is also "Page 1/1" in the header or footer, the grid with autotext in header/footer works correct.<br />
If I export the pdf from Birt Report Viewer totalPage is showing the correct number of pages, pageNumber is still 1.<br />
<br />
I also need the pageNumber for another thing, where a text is only shown on page 1 and on page 2 ff another one. So I'm also using something like this:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>if (pageNumber == 1) { "this text" } else { "another text" }</pre>
which always shows "this text' cause pageNumber is always 1.<br />
<br />
If it is important, the structur of the report is:<br />
1x1 grid and in it all other stuff:<br />
- grid for address<br />
- a table with 4 groups (and every groupheader (not repeated) a different font size etc.)<br />
-- the header of the table (repeated): contains a grid with two columns, one row<br />
--- column 1: should contain the above text which differs if it is page1 or page2 ff <br />
--- column 2: should contain the pageNumber/pageTotal<br />
<br />
<br />
<br />
Does anybody have a solution which shows correct pageNumber/pageTotal (in layout) in a pdf?<br />
<br />
<br />
tried with Birt 2.6.1 (Eclipse 3.6.1) and 2.6.2 RC3 (Eclipse 3.6.2)<br />
jre 1.6.0_22
Find more posts tagged with
Comments
mwilliams
Have you deployed your report to see what it does? You may be running into the RunAndRender Task in the designer PDF output. If you run your report in the web viewer from the designer and then export to PDF, do you get the correct result?
hex
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="73835" data-time="1298551985" data-date="24 February 2011 - 05:53 AM"><p>
Have you deployed your report to see what it does?<br /></p></blockquote>
Tested with 6.1 and 6.2rc2: Still the same output, pageNumber and pageTotal both 1.<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="73835" data-time="1298551985" data-date="24 February 2011 - 05:53 AM"><p>
If you run your report in the web viewer from the designer and then export to PDF, do you get the correct result?<br /></p></blockquote>
Also not working correct: pageNumber is still 1, but pageTotal is correct.
mwilliams
Let me take a look and see if there is something that can be done.
So, you deployed 2.6 and had the same issue? Or you just tried it in 2.6 designer? Let me know.
hex
We tested both, designer and deploying, and got the same result.
mwilliams
If I use pageNumber from a dynamic text element from within BIRT, it prints the correct page in the report. totalPage does not though.
mwilliams
However, if I set the same in the onRender script in 2.6.1 in a dynamic text element, I get the correct page n of m if I run the viewer and then export to PDF, but not if I just run PDF.
hex
If I create a new report with a table (sample db) and a text with the onRender method before/after the table, pageNumber and totalPage are correct. The same text in the header/footer of the table and I get the pageNumber always = 1 and totalPage correct result.
mwilliams
I put it in the detail line of the table so that it for sure showed me the value for every page. I'll have to look at the others.
mwilliams
I put it in the table header, the group header, the detail row, and the group footer. I ran it in the web viewer and then exported it to PDF so that the Run task and render tasks were done separately. The only place it did not work was in the table header. This is because it is only made once. It's not dynamic. Again, this is in 2.6.1. My report is attached.
hex
Thanks for the help.
I then must think of something else, I have it with conditions in the repeated table header (so it shows on every page - depending on the conditions).
Can I have another variable which adds 1 to itself (and is shown instead of pageNumber) all times the header is repeated?
hex
In the "old" report, the pageNumber stays 1, wherever the text with the onRender script is. It is one in the header/footer of the masterpage, 1 in the layout outside the table, in detailRow, ...
When I create a new report, it's working except in the table header as you mentioned. But therefore I found another solution with two small grids: one in the page header and one in the layout, both with visibility settings. That works at least in a new report.
Tomorrow I'll try to get it work in the old one (or be fast in getting the old into a new one).
hex
I can't get it to work <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/public/style_emoticons/'>http://www.birt-exchange.org/org/forum/public/style_emoticons/</a><#EMO_DIR#>/confused.gif
<br />
<br />
I created a new report, with the text and onRender method in the header.<br />
Then I created a new 1x1 grid and inside it a new table with the groups I'd like to have. Group 1 till 3 have Item Expressions, Group 4 not.<br />
I tested and the pageNumber in the pdf was correct. <br />
After that I put more data into the table and tested again. PageNumber was always 1 then.<br />
<br />
So I tested more:<br />
I used the working report and just put one data field into the table<br />
- if this data was in the detail row, page numbering was odd: page 1-5 was page 1, page 6 was page 2, page 7-8 page 3, ... last page 23 was "Page 12 of 23"; totalPage was correct<br />
- if the data was in the header of group4, I got the same odd page numbering.<br />
- if i put data elsewhere in the table, page numbering is correct<br />
<br />
<br />
<strong class='bbc'>Edit:</strong><br />
Data in the detail row:<br />
the result before was with standard pageBreak interval (40). I changed it to 0 and pageNumber was always 1, same with 1000. When I changed it to 30, page numbering was still odd, but not so much as before. With pageBreak interval = 1 page numbering is working correct again, but then I get over 500 pages (instead of ca. 20) and just a few lines on one page. So not se desired output after all.<br />
<br />
So I guess it has something to do with pageBreak interval?<br />
<br />
<br />
<strong class='bbc'>Edit2:</strong><br />
I could reproduce this behavior with the sample db and attached the report and the pdf output (exported from birts web viewer).
mwilliams
There are issues with the page break in the way that if the page break is set to say, 40, and there are only 35 rows that fit on the page, the pageBreak methods don't seem to be called which means that the page numbers don't end up being correct. If you set it to a number that will definitely fit on a page, it will work as expected. I believe that there is an improvement in this in 2.6.2 when it is released so that the end of page events are called.
hex
Hi,
just to let you know: It works fine in Birt 2.6.2 final.
mwilliams
Excellent! That's good to hear. I've been working a lot with this lately with people having pagebreak issues! Let us know whenever you have questions!