Working with Project Pages
Aspose.Tasks for .NET can retrieve the total number of pages in a project. The GetPageCount method offered by Aspose.Tasks.Visualization namespace returns the total page count in a project with options of rendering them based on Timescale.Days, Timescale.Months or Timescale.ThirdsOfMonths.
Get Number of Pages in Project
The Project class exposes the GetPageCount method.
You can specify different timescales:
Timescale.Days
– shows tasks/resources per dayTimescale.Months
– aggregates by monthsTimescale.ThirdsOfMonths
– splits each month into three equal parts
To save a project to PDF:
- Load a Microsoft Project file.
- Get the project’s total page count using the GetPageCount method with optional timescale settings.
Programming Sample: Get Number of Pages in Project
The following lines of code shows how to achieve this using C#.
1Project project = new Project("New Project.mpp");
2
3// Get number of pages, Timescale.Months, Timescale.ThirdsOfMonths
4int iPages = project.GetPageCount();
5iPages = project.GetPageCount(Timescale.Months);
6iPages = project.GetPageCount(Timescale.ThirdsOfMonths);
Getting Number of Pages for Different Views
Aspose.Tasks for .NET supports rendering Resource Usage, Resource Sheet, and Task Usage views to PDF. You can also calculate the number of pages for each view separately. This programming sample demonstrates rendering a projects’ usage view and getting the number of pages in the rendered output.
Example: Get Page Count for Views (C#)
1Project project = new Project("New Project.mpp");
2
3// Get number of pages, Months and ThirdsOfMonths
4Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Days)));
5Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.Months)));
6Console.WriteLine(string.Format("Number of Pages = '{0}'", project.GetPageCount(PresentationFormat.ResourceUsage, Timescale.ThirdsOfMonths)));
Filtering Page Count by Date Range
If you need to calculate the number of pages for a specific date range (Start–End),
Aspose.Tasks provides an overload of the GetPageCount
method that accepts DateTime
parameters.
Programming Sample: Get number of pages based on Start and End Dates
1Project project = new Project("New Project.mpp");
2
3ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.PNG)
4{
5 SaveToSeparateFiles = true,
6 PageSize = PageSize.A3,
7 Timescale = Timescale.Months,
8 StartDate = project.Get(Prj.StartDate) - TimeSpan.FromDays(10),
9 EndDate = project.Get(Prj.FinishDate) + TimeSpan.FromDays(30)
10};
11int pageCount = project.GetPageCount(
12 PageSize.A3,
13 Timescale.Months,
14 project.Get(Prj.StartDate) - TimeSpan.FromDays(10),
15 project.Get(Prj.FinishDate) + TimeSpan.FromDays(30));
16
17Console.WriteLine(pageCount);