Skip to main content Skip to footer

Calculating Page Count of a PageReport

Page Based Reports have been a favorite of many developers due to the incredible control they offer over report layouts. This blog discusses how different scenarios demand for different kind of reports - Page based and Section based. Many a times, while working with PageReport we have wondered why we are unable to access the page collection of page based reports and do something as simple as find total number of pages in the report created. The answer lies in the fact that these reports are not only different in terms of designing and functionality offered, their reporting engines are also individually distinct. In this blog, we will discuss how to find the total pages in a PageReport document using our Winviewer programatically.

Img_PageCountImplementation

We will use the ToolStrip of our WinViewer and the value of it's 'Current Page' item to get the Total Page Count . 'CurrentPage' is 21st item in the Viewer Toolbar's ToolStripItem Collection, all we need to do is parse it's text and use it as required. The GetTotalPageCount() method will look like this:


private int GetTotalPageCount()  
{  
//Get textbox in viewer toolbar and abstarct the total page count.  
var pgtext = viewer1.Toolbar.ToolStrip.Items[21].Text;  
int totalPageNumber = 0;  
if (!string.IsNullOrEmpty(pgtext))  
{  
Int32.TryParse(pgtext.Split('/').Last(), out totalPageNumber);  
}  
return totalPageNumber;  
}  

How did we know that the Current Page item is at 21st position? WinViewer of ActiveReports is very flexible and highly customizable control. A list of all ToolStrip items with their position is available in the documentation to customize the viewer as per our needs. A sample application showcasing the above implementation can be downloaded from the links below: Download C# Sample Download VB.NET Sample

MESCIUS inc.

comments powered by Disqus