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, he default GanttChart view with standard formatting will be 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 rendering Microsoft Project files to PDF, image, or XPS, it is important to specify the appropriate page size. This ensures correct chart scaling, reduces the risk of truncated data, and allows for better integration of the document into business processes. Aspose.Tasks allows you to specify both standard and custom page sizes, as well as use saved settings from an MPP file.

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:
1    Project project = new Project("Project.mpp");
2    PdfSaveOptions 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:
1    Project project = new Project("Project.mpp");
2    PdfSaveOptions saveOptions = new PdfSaveOptions()
3    {
4        PresentationFormat = PresentationFormat.GanttChart,
5        CustomPageSize = new SizeF(700, 900),
6    };
7
8    project.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

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

Note: The PageSize.DefinedInView option is only effective when the source file is an MPP file and contains a view with saved page setup settings. If the view does not contain page setup information or the input file format is not MPP (e.g., XML), this option will have no effect.

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 out

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

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.