Page number expression not updated in dynamic text in header

Options
nickarls
edited February 11, 2022 in Analytics #1
<p>Hi,</p><p> </p><p>  I'm using the latest birt and trying to write a custom page number expression for my master page header with a dynamic text expression 'Page ' + pageNumber + ' (' + totalPage + ')' but for some reason it shows Page 1 (1) on all pages. Any suggestions or workarounds? I'd prefer not to have a grid with multiple autotext-items etc.</p><p> </p><p>Thanks in advance,</p><p>  Nik</p>

Comments

  • <p>pageNumber and totalPage need to be used in onRender() to get the correct values, not onCreate() can you check where you put this code?</p>
    Warning No formatter is installed for the format ipb
  • <p>Pardon my noobishness but how can I tell? I just dropped the dynamic text from the palette into the header of the master page. But yes, it looks like it is only evaluated once or something. Need to read up on the topic, I recall seeing (after my initial post) one thread with those phases mentioned in the context of page numbers...</p>
  • <p>In your master page, click on your dynamic text element, then click the script tab at the bottom.  At the top you should see a drop down with different methods.  You can choose onPrepare, onCreate, or onRender.  You might want to take a look at <a data-ipb='nomediaparse' href='http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php'>this page</a>, it has a pretty good explanation of when the methods are called.</p>
    Warning No formatter is installed for the format ipb
  • <p>Hi,</p><p> </p><p>     Thanks for the pointers, I tried to assign the string to this.text in the onRender but I still see the 1 (1) on all pages. If I do a this.text='foo'; it works so I guess the code works but it's still not being called when it should.</p><p> </p><p>--Nik</p>
  • <p>Strange. I noticed that it works for the web viewer but not when I render a PDF directly. It's starting to look like </p><p> </p><p><a data-ipb='nomediaparse' href='http://www.birt-exchange.org/forum/index.php?/topic/21679-pagenumber-and-totalpage-in-layout-conditional-text-depending-on-pagenumber-in-pdf/'>http://www.birt-exchange.org/forum/index.php?/topic/21679-pagenumber-and-totalpage-in-layout-conditional-text-depending-on-pagenumber-in-pdf/</a></p><p> </p><p>but that discussion goes into page breaks and I'm not sure I could distill information related to a simple solution from there.</p>
  • <p>Can you run it in the webviewer then export it to PDF and tell me if it works? </p>
    Warning No formatter is installed for the format ipb
  • <p>Nope, page number is always 1 (1) in both HTML and exported PDF (designer 4.3.0)</p>
  • <p>I used your code</p><pre class="_prettyXprint">this.text = 'Page ' + pageNumber + ' (' + totalPage + ')'</pre><p>In the onRender() of a dynamic text item in the header of my master page from 4.3.  And it works in the WebViewer and if I export the report to PDF from the WebViewer it works fine.  When getting the current and total pages the PDF needs to be ran with separate run and render tasks.</p><p> </p><p>Can you walk me through how you are rendering the PDF?  Also can you recreate this with the sample db and post your rptdesign so I can test it on my side?</p>
    Warning No formatter is installed for the format ipb
  • <p>And of course I couldn't reproduce the issue with a new report against the sample DB. My case involves modifying an old report perhaps I'll try copy&pasting stuff into a fresh report and see when it breaks.</p><p> </p><p>Thanks for the help in any case.</p>
  • <p>Let me know if it works for you! :)</p>
    Warning No formatter is installed for the format ipb