Print a Project

Skip to end of metadata
Go to start of metadata
Aspose.Tasks provides 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.

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, 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.

Print to the Default Printer

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

C#
//Read the input Project file
Project project = new Project("NewProductDev.mpp");
project.Print();
Visual Basic
Dim project As New Project("NewProductDev.mpp")
project.Print()

Print the project to custom printer

C#
//Read the input Project file
Project project = new Project("NewProductDev.mpp");

string printerName = "pdf";
foreach (string printer in PrinterSettings.InstalledPrinters)
{
    if(printer.ToUpperInvariant().Contains(printerName.ToUpperInvariant()))
    {
        project.Print(printer);
        break;
    }
}
Visual Basic
'Read the input Project file
Dim project As New Project("NewProductDev.mpp")

Dim printerName As String = "pdf"
For Each printer As String In PrinterSettings.InstalledPrinters
	If printer.ToUpperInvariant().Contains(printerName.ToUpperInvariant()) Then
		project.Print(printer)
		Exit For
	End If
Next

Print Large Files

C#
//Read the input Project file
Project project = new Project("ST_AV_AF_DEV_AFT_EMP.mpp"); // ~ 8 MB file
PrintOptions options = new PrintOptions();
options.Timescale = Timescale.ThirdsOfMonths;
if(project.GetPageCount(Timescale.ThirdsOfMonths) <= 280)
    project.Print(options);
Visual Basic

'Read the input Project file
Dim project As New Project("ST_AV_AF_DEV_AFT_EMP.mpp") ' ~ 8 MB file
Dim options As New PrintOptions()
options.Timescale = Timescale.ThirdsOfMonths
If project.GetPageCount(Timescale.ThirdsOfMonths) <= 280 Then
	project.Print(options)
End If

Print with PrintOptions and PrinterSettings

C#
//Read the input Project file
Project project = new Project("ST_AV_AF_DEV_AFT_EMP.mpp"); // ~ 8 MB file

PrintOptions options = new PrintOptions();
options.Timescale = Timescale.Months;

// Print first ten pages
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrintRange = PrintRange.SomePages;
printerSettings.FromPage = 1;
printerSettings.ToPage = 10;

PageSettings pageSettings = printerSettings.DefaultPageSettings;
pageSettings.PaperSize = new PaperSize("Custom Size", 1000, 700);

project.Print(printerSettings, options);
Visual Basic
Dim project As New Project("ST_AV_AF_DEV_AFT_EMP.mpp")
' ~ 8 MB file
Dim options As New PrintOptions()
options.Timescale = Timescale.Months

' Print first ten pages
Dim printerSettings As New PrinterSettings()
printerSettings.PrintRange = PrintRange.SomePages
printerSettings.FromPage = 1
printerSettings.ToPage = 10

Dim pageSettings As PageSettings = printerSettings.DefaultPageSettings
pageSettings.PaperSize = New PaperSize("Custom Size", 1000, 700)

project.Print(printerSettings, options)
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.