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
- C# API to Create MS Project to PDF Converter
- Convert MS Project to PDF using C#
- Export Specific MS Project View to PDF
- Fit Content to Cell and Convert MS Project to PDF
- Convert MS Project to PDF without Legends
- Customize Text Style and MS Project Export to PDF
- Customize Date Format while Converting MS Project to PDF
- 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:
- Load the MS Project file using the Project class.
- 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#:
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:
- Load the MS Project file using the Project class.
- Create an instance of the PdfSaveOptions class.
- Specify the desired PresentationFormat.
- 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#:
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:
- Load the MS Project file using the Project class.
- Create an instance of the PdfSaveOptions class.
- Set FitContent to true.
- 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#:
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:
- Load the MS Project file using the Project class.
- Create an instance of the PdfSaveOptions class.
- Set LegendOnEachPage to false.
- 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#:
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:
- Load the MS Project file using the Project class.
- Create an instance of the PdfSaveOptions class.
- Instantiate the TextStyle class.
- Set the Color, Font, and ItemType properties.
- Add the TextStyle to the TextStyles list.
- 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 Date Format while Converting MS Project to PDF
To customize the date format during PDF conversion, follow these steps:
- Load the MS Project file using the Project class.
- Use the Set() method with Prj.DateFormat as the key and your desired DateFormat as the value.
- 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#:
Convert MS Project to Multiple PDF Files in C#
You can also convert an MS Project to multiple PDF pages. Here’s how:
- Load the MS Project file using the Project class.
- Create an instance of the PdfSaveOptions class.
- Set SaveToSeparateFiles to true.
- Add the page numbers you want to include in the Pages list.
- 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.