Convert MS Project to PDF in C#

Are you looking for a way to convert MS Project files to PDF format without using Microsoft Project? If so, you’ve come to the right place. In this article, we’ll show you how to convert MS Project to PDF in C# by following just a few simple steps.

Microsoft Project is a software program that allows teams to organize their projects, track progress, and make sure people know what they are supposed to be doing. However, sometimes the need arises where you need to convert a Microsoft Project document into a PDF file - like when you want to submit it for a contract proposal or take it with you on-the-go for offsite meetings.

In the modern day, PDF is the most common format for storing and sharing documents. PDFs have been used to replace printed documents. Exporting project data from MS Project files to PDF documents allows sharing project tasks, resources, assignments, timelines, budgets, and different other project-related information in a portable format. This article will show you how to do this programmatically in C#. So let’s get started!

The following topics will be covered in this article:

  1. C# API to Create MS Project to PDF Converter
  2. Convert MS Project to PDF
  3. Export Specific MS Project View to PDF
  4. Fit Content to Cell and Convert MS Project to PDF
  5. Convert MS Project MPP to PDF without Legends
  6. Customize Text Style and MS Project Export to PDF
  7. Customize Date Format while Converting MS Project to PDF
  8. Convert MS Project to Multiple PDF Files

C# API to Create MS Project to PDF Converter

For convert MS Project to PDF, we will be using the Aspose.Tasks for .NET API. The API allows you to read and write supported file formats without having Microsoft Project installed. Additionally, it lets you convert and save MS Project files.

Aspose.Tasks for .NET is a class library and provides various classes to work with projects, formulas, calendars, calendar exceptions, tasks, task links, task baselines, project resources, resource assignments, currencies, handling exceptions, reporting services, and project risk analysis. Please read more about classes and methods in the API references.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Tasks

Convert MS Project to PDF using C#

We can easily convert all the project data from MS Project to a PDF by following the steps given below:

  1. Load the MS Project file using the Project class.
  2. Save as a PDF using the Save() method. It takes the output PDF file path and the SaveFileFormat.Pdf as arguments.

The following sample code shows how to convert MS Project to PDF in C#.

Convert MS Project to PDF using C#

Convert MS Project to PDF using C#.

Export Specific MS Project View to PDF in C#

In Microsoft Project, views display information that you enter in Microsoft Project, or Project calculates for you in calculated fields. MS Project provides different views to present project information in a variety of formats such as Gantt Chart, Task Usage, Resource Usage, etc. We can render any view and export it into PDF by following the steps given below:

  1. Firstly, load the MS Project file using the Project class.
  2. Next, create an instance of the PdfSaveOptions class.
  3. After that, specify the PresentationFormat.
  4. Finally, call the Save() method. It takes the output PDF file path and the PdfSaveOptions as arguments.

The following sample code shows how to export any specific MS Project View to PDF in C#.

Export Specific MS Project View to PDF in C#

Export Specific MS Project View to PDF in C#.

Fit Content to Cell and Convert MS Project to PDF in C#

A project view display truncates long text in fields such as name. We can set it to display full text to avoid truncation of task and resource names. We can fit content to the cell and then convert into PDF by following the steps given below:

  1. Firstly, load the MS Project file using the Project class.
  2. Next, create an instance of the PdfSaveOptions class.
  3. After that, specify the FitContent to true.
  4. Finally, call the Save() method. It takes the output PDF file path and the PdfSaveOptions as arguments.

The following sample code shows how to fit content to cells and convert MS Project to PDF in C#.

Fit Content to Cell and Convert MS Project to PDF in C#

Fit Content to Cell and Convert MS Project to PDF.

Convert MS Project to PDF without Legends in C#

In MS Project, the legend appears on all pages by default, but we can hide it by following the steps below:

  1. Firstly, load the MS Project file using the Project class.
  2. Next, create an instance of the PdfSaveOptions class.
  3. After that, specify the LegendOnEachPage to false.
  4. Finally, call the Save() method. It takes the output PDF file path and the PdfSaveOptions as arguments.

The following sample code shows how to convert MS Project MPP to PDF without legend in C#.

Convert MS Project to PDF without Legends in C#

Convert MS Project to PDF without Legends.

Customize Text Style and MS Project Export to PDF in C#

We can customize the text style when rendering MS Project into PDF by following the steps below:

  1. Firstly, load the MS Project file using the Project class.
  2. Next, create an instance of the PdfSaveOptions class.
  3. Then, instantiate the TextStyle class object.
  4. Meanwhile, specify the Color, Font, and ItemType properties.
  5. After that, add TextStyle to the TextStyles list.
  6. Finally, call the Save() method. It takes the output PDF file path and the PdfSaveOptions as arguments.

The following sample code shows how to customize the text style when converting MS Project to PDF in C#.

Customize Text Style and Convert MS Project to PDF in C#

Customize Text Style and Convert MS Project to PDF.

Customize Date Format while Converting MS Project to PDF

We can also customize the date format when rendering MS Project into PDF by following the steps below:

  1. Load the MS Project file using the Project class.
  2. Call the Set() method with Prj.DateFormat as key and DateFormat as value.
  3. Finally, call the Save() method. It takes the output PDF file path and the SaveFileFormat.Pdf as arguments.

The following sample code shows how to customize the date format and convert MS Project to PDF in C#.

Customize Date Format while Converting MS Project to PDF in C#

Customize Date Format while Converting MS Project to PDF.

Convert MS Project to Multiple PDF Files in C#

We can also convert MS Project to multiple PDF pages by following the steps below:

  1. Firstly, load the MS Project file using the Project class.
  2. Next, create an instance of the PdfSaveOptions class.
  3. Then, specify the SaveToSeparateFiles to true.
  4. After that, add page numbers to include in the Pages list.
  5. Finally, call the Save() method. It takes the output PDF file path and the PdfSaveOptions as arguments.

The following sample code shows how to convert MS Project to multiple PDF documents in C#.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • load MS Project file;
  • specify PDF saving options;
  • save the loaded MS Project as PDF in C#.

Besides converting MS Project to PDF in C#, you can learn more about Aspose.Note for .NET API using documentation. In case of any ambiguity, please feel free to contact us at our free support forum.

See Also