asp.netcrystal-reports-2010

How to obtain number of pages in a Crystal Reports .NET report


I have a web application in which I render one or more Crystal Reports and then merge them into one PDF. What I'd like to do is obtain the number of pages from one CrystalDecisions.CrystalReports.Engine.ReportDocument object then then set that value as a parameter in the subsequent ReportDocuments in order to continue the page numbering correctly. Does the ReportDocument class expose a way of obtaining the number of pages? If not, are there other ways?

I am NOT using a Crystal Report Viewer.

I am using CrystalReports for Visual Studio 2010 and C# .NET 4.


Solution

  • The solution for me was to use the code below:

    reportDocument.FormatEngine.GetLastPageNumber(new CrystalDecisions.Shared.ReportPageRequestContext());
    

    Intellisense will not pick up the "FormatEngine" property of the ReportDocument, so you need to type it manually, then Intellisense will show "GetLastPageNumber" method and you can go from there.

    I had seen this solution before but the lack of Intellisense support caused me to think that perhaps I had the wrong version of the Crystal Report object to leverage the "FormatEngine" property.