Common conversion options

In this article we are going to describe options which are common for conversions of Microsoft Project MPP files to graphical formats (PDF, TIFF, PNG, SVG, HTML). Aspose.Tasks for .NET API can be used to convert project loaded from MS Project MPP, Primavera P6 XML, Primavera XER or other supported input formats to PDF or graphical formats. In this case a specific project’s view is rendered in specified format.

Specifying a View to save

Microsoft Project supports different view, such as ‘Gantt Chart’, ‘Task Usage’, ‘Resource Usage’, etc. Each view can be customized and these settings are stored in MPP file. Aspose.Tasks for .NET allows the user to examine and change these settings using Project.Views collection.

There are 3 ways to specify the View which will be exported when project is saved to graphical formats.

  1. Do not specify a View explicitly. In this case Project.DefaultView will be rendered. If default view is missing, Gantt Chart view will be rendered.
  2. Use SaveOptions.PresentationFormat to specify value of PresentationFormat enumeration. In this case the view with the correspondent Screen property will be selected from Project.Views collection. If View is missing, the default settings are used.
  3. Use SaveOptions.ViewSettings property to explicitly specify the View object to render. If View object is specified, the value of SaveOptions.PresentationFormat is ignored.

Specifying a page size

When project is rendered, the rendering routine needs to know page size to fit view’s elements properly.

Page size can be specified in the following ways:

  1. Do not specify page size. In this case PageSize.A4 will be used.
  2. Specify predefined PageSize via SaveOptions.PageSize property:
1Project project = new Project("Project.mpp");
2PdfSaveOptions saveOptions = new PdfSaveOptions()
3{
4    PresentationFormat = PresentationFormat.GanttChart,
5    PageSize = PageSize.A2
6};
7
8project.Save("OutputFitToA2.pdf", saveOptions);
  1. Specify custom PageSize via SaveOptions.CustomPageSize property:
1Project project = new Project("Project.mpp");
2PdfSaveOptions saveOptions = new PdfSaveOptions()
3{
4    PresentationFormat = PresentationFormat.GanttChart,
5    CustomPageSize = new SizeF(700, 900),
6};
7
8project.Save("OutputFitToCustomPage.pdf", saveOptions);
  1. Specify PageSize.DefinedInView to use page size saved in MS Project’s Page Setup dialog:

MS Project Page Setup dialog

The option is applicable when input file is in MS Project MPP format

 1Project project = new Project("Project.mpp");
 2
 3var taskUsageView= project.Views.FirstOrDefault(v => v.Screen == ViewScreen.TaskUsage);
 4taskUsageView.PageInfo.PageSettings.PaperSize = PrinterPaperSize.PaperEnvelope10;
 5
 6PdfSaveOptions saveOptions = new PdfSaveOptions()
 7{
 8    ViewSettings = taskUsageView,
 9    PageSize = PageSize.DefinedInView
10};
11
12project.Save("OutputToEnvelope.pdf", saveOptions);

Fitting Contents to Cell Size

Commonly, a task (or resource) name is so long that it is truncated when project views are rendered. Aspose.Tasks for .NET provides the FitContent property in the SaveOptions class to avoid truncation of task and resource names. The code example below renders a project to PDF format with the FitContent property set to true.

1Project project = new Project("New Project.mpp");
2SaveOptions options = new PdfSaveOptions();
3
4// Set option fit content to true
5options.FitContent = true;
6options.Timescale = Timescale.Months;
7options.PresentationFormat = PresentationFormat.TaskUsage;
8project.Save("FitContentsToCellSize_out.pdf", options);

Here is an examples of an output file without and with FitContent option:

Without FitContent With FitContent

Printing or Hiding Legends when Rendering

To let you print or hide the legends on each page, the SaveOptions class provides the LegendOnEachPage property. If this flag is set to true, legends are printed on each page in the output file.

1SaveOptions options = new PdfSaveOptions();
2
3// Set the LegendOnEachPage property to false to hide legends
4options.LegendOnEachPage = false;

Saving to Multiple PDF or graphical files

To save project data to multiple PDF files, set the SaveToSeparateFiles flag to true.

1Project project = new Project("New Project.mpp");
2PdfSaveOptions options = new PdfSaveOptions();
3options.SaveToSeparateFiles = true;
4options.Pages = new List<int>();
5options.Pages.Add(1);
6options.Pages.Add(4);
7project.Save("SaveToMultiplePDFFiles_out.pdf", (SaveOptions)options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.