Configure MS Project Page Settings with Aspose.Tasks

Introduction

In this tutorial, we’ll walk through the process of configuring Microsoft Project page settings using Aspose.Tasks for .NET. Aspose.Tasks is a powerful API that allows developers to manipulate Microsoft Project files programmatically.

Prerequisites

Before we begin, ensure you have the following prerequisites:

  1. Aspose.Tasks for .NET: Make sure you have installed Aspose.Tasks for .NET. You can download it from here.
  2. Development Environment: Have a development environment set up with Visual Studio or any other preferred IDE for .NET development.

Importing Namespaces

To get started, you need to import the necessary namespaces in your project. These namespaces provide access to the Aspose.Tasks classes and methods required for manipulating MS Project files.

using Aspose.Tasks;
using System.Linq;
    using System;
    
    using Aspose.Tasks.Saving;
    using Aspose.Tasks.Visualization;

Step 1: Load the Project File

First, you need to load the MS Project file that you want to configure the page settings for.

// The path to the documents directory.
string dataDir = "Your Document Directory";
var project = new Project(dataDir + "Project2.mpp");

Step 2: Access Page Settings

Next, you’ll access the page settings of the project file.

// Get the settings
var settings = project.DefaultView.PageInfo.PageSettings;

Step 3: Configure Page Settings

Now, let’s configure various properties of the page settings according to your requirements.

// Set page orientation to portrait
settings.IsPortrait = true;
// Set number of pages in width to be printed
settings.PagesInWidth = 5;
// Set number of pages in height to be printed
settings.PagesInHeight = 7;
// Set percentage of normal size to adjust printing to
settings.PercentOfNormalSize = 200;
// Set paper size
settings.PaperSize = PrinterPaperSize.PaperB4;
// Set first page number for printing
settings.FirstPageNumber = 3;

Step 4: Save the Project File

Finally, save the project file with the updated page settings.

SimpleSaveOptions options = new MPPSaveOptions
{
    WriteViewData = true
};
project.Save(dataDir + "TestCanWritePageSettings.mpp", options);

Conclusion

In this tutorial, we’ve learned how to configure Microsoft Project page settings using Aspose.Tasks for .NET. By following these steps, you can easily customize page orientation, size, and other printing options according to your requirements.

FAQ’s

Q: Can I configure page settings for multiple MS Project files simultaneously?

A: Yes, you can loop through multiple project files and apply the same page settings to each one.

Q: Is it possible to revert the page settings back to default?

A: Absolutely, you can simply omit the configuration steps or reset the settings to their default values.

Q: Are there any limitations on the paper sizes supported?

A: Aspose.Tasks supports a wide range of paper sizes, including standard and custom sizes.

Q: Can I automate the page settings configuration process?

A: Certainly, you can integrate this functionality into your application’s workflow to automate page settings configuration.

Q: Does Aspose.Tasks offer support for different file formats besides .mpp?

A: Yes, Aspose.Tasks supports various file formats such as XML, MPT, and HTML, among others.