Convert MS Project to PDF in C#

Are you searching for a reliable method to convert MS Project files to PDF format without needing Microsoft Project? You’re in the right place! This article will guide you through the steps to convert MS Project to PDF in C# with ease.

Microsoft Project is a powerful tool that helps teams organize their projects, track progress, and clarify roles and responsibilities. However, there are times when you need to convert a Microsoft Project document into a PDF file—perhaps for contract proposals or convenient access during offsite meetings.

In today’s digital landscape, PDF has become the preferred format for sharing and storing documents. Exporting project data from MS Project files to PDF allows you to share vital information—like tasks, resources, assignments, timelines, and budgets—in a portable format. Let’s dive into how to accomplish this programmatically in C#.

Table of Contents

  1. C# API to Create MS Project to PDF Converter
  2. Convert MS Project to PDF using C#
  3. Export Specific MS Project View to PDF
  4. Fit Content to Cell and Convert MS Project to PDF
  5. Convert MS Project 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

To convert MS Project to PDF, we will utilize the Aspose.Tasks for .NET API. This powerful library allows you to read and write various file formats without requiring Microsoft Project to be installed. It also enables you to convert and save MS Project files seamlessly.

Aspose.Tasks for .NET is a comprehensive class library that provides a wide range of functionalities, including working with projects, formulas, calendars, tasks, and resource assignments. For an in-depth understanding of the available classes and methods, refer to the API references.

You can either download the DLL of the API or install it via NuGet:

PM> Install-Package Aspose.Tasks

Convert MS Project to PDF using C#

Converting all project data from MS Project to a PDF is straightforward. Follow these simple steps:

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

Here’s a sample code snippet demonstrating 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#

Microsoft Project offers various views to display project information, such as Gantt Chart and Resource Usage. To export a specific view to PDF, follow these steps:

  1. Load the MS Project file using the Project class.
  2. Create an instance of the PdfSaveOptions class.
  3. Specify the desired PresentationFormat.
  4. Finally, call the Save() method with the output PDF file path and the PdfSaveOptions.

Here’s 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#

To avoid truncation of long text in fields such as names, you can fit content to the cell before converting to PDF. Here’s how:

  1. Load the MS Project file using the Project class.
  2. Create an instance of the PdfSaveOptions class.
  3. Set FitContent to true.
  4. Call the Save() method with the output PDF file path and PdfSaveOptions.

Here’s a code example demonstrating 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#

By default, legends appear on all pages in MS Project. To hide them, follow these steps:

  1. Load the MS Project file using the Project class.
  2. Create an instance of the PdfSaveOptions class.
  3. Set LegendOnEachPage to false.
  4. Call the Save() method with the output PDF file path and PdfSaveOptions.

Here’s how to convert MS Project MPP to PDF without legends 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#

You can customize the text style when rendering MS Project into PDF by following these steps:

  1. Load the MS Project file using the Project class.
  2. Create an instance of the PdfSaveOptions class.
  3. Instantiate the TextStyle class.
  4. Set the Color, Font, and ItemType properties.
  5. Add the TextStyle to the TextStyles list.
  6. Finally, call the Save() method with the output PDF file path and PdfSaveOptions.

Here’s a code example for customizing 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

To customize the date format during PDF conversion, follow these steps:

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

Here’s 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#

You can also convert an MS Project to multiple PDF pages. Here’s how:

  1. Load the MS Project file using the Project class.
  2. Create an instance of the PdfSaveOptions class.
  3. Set SaveToSeparateFiles to true.
  4. Add the page numbers you want to include in the Pages list.
  5. Call the Save() method with the output PDF file path and PdfSaveOptions.

Here’s a code snippet showing 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 any evaluation limitations.

Conclusion

In this article, we covered how to:

  • Load an MS Project file.
  • Specify PDF saving options.
  • Save the loaded MS Project as a PDF in C#.

By utilizing Aspose.Tasks for .NET, you can easily convert Microsoft Project to PDF in C# .NET Core or any other .NET framework. If you have any questions or need assistance, feel free to reach out through our free support forum.

See Also

For more information on the best C# library for MSP to PDF conversion, check out the Aspose.Tasks documentation.