Printing a Microsoft Project (MPP/XML) files

Aspose.Tasks for .NET provides the facility to print projects to the default printer or any custom printer using the Project.Print function. It also provides advanced printing features like changing the printing options and settings.

Printing Project Data

The Project class exposes the Print function to print the project. The Print function uses PrintOptions to set different settings for printing like TimeScale, StartDate, EndDate, FitContent, LegendOnEachPage and more. Another class (from System.Drawing.Printing namespace), PrinterSettings is used to configure the printer to print all pages, page start (FromPage), page end (ToPage), PaperSize and so on. Both the objects of PrintOptions and PrinterSettings are passed to Project.Print() for final printing.

To print a project:

  1. Load a Microsoft Project file.
  2. Call the print function along with the specified arguments.

The following lines of code shows how to achieve this using C#.

1Project project = new Project("New Project.mpp");
2project.Print();
1Project project = new Project("New Project.mpp");
2foreach (string printer in PrinterSettings.InstalledPrinters)
3{
4    if (printer.ToUpperInvariant().Contains( "Microsoft Print to PDF".ToUpperInvariant()))
5    {
6        project.Print(printer);
7        break;
8    }
9}
1Project project = new Project("New Project.mpp");
2PrintOptions options = new PrintOptions();
3options.Timescale = Timescale.ThirdsOfMonths;
4if (project.GetPageCount(Timescale.ThirdsOfMonths) <= 280)
5    project.Print(options);
 1Project project = new Project("New Project.mpp");
 2
 3PrintOptions options = new PrintOptions();
 4options.Timescale = Timescale.Months;
 5
 6// Print first two pages
 7PrinterSettings printerSettings = new PrinterSettings();
 8printerSettings.PrintRange = PrintRange.SomePages;
 9printerSettings.FromPage = 1;
10printerSettings.ToPage = 2;
11
12System.Drawing.Printing.PageSettings pageSettings = printerSettings.DefaultPageSettings;
13pageSettings.PaperSize = new PaperSize("Custom Size", 1000, 700);
14project.Print(printerSettings, options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.