Convert Project File (MPP) to PDF Programmatically in Java

Convert MPP to PDF

Microsoft Project Files (MPP) are used for different project management tasks like tracking and organizing projects. You can convert MPP files to PDF documents programmatically using Java. The following sections explain MPP file conversion in detail:

MPP to PDF Converter – Java API Installation

Aspose.Tasks for Java can be used to manage projects in your Java applications. You can configure the API by downloading the JAR file from the Downloads section. Alternatively, you can specify the following Maven configurations in the pom.xml file of your Java project.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-tasks</artifactId>
    <version>21.2</version>
    <classifier>jdk18</classifier>
</dependency>

Convert MPP to PDF File Programmatically with Java

You can convert MPP file to PDF with the following steps:

  1. Load input file using Project class.
  2. Save output PDF file using Save() method and SaveFileFormat enumeration.

The following code shows how to convert MPP file to PDF programmatically using Java:

// Read the input Project file
Project project = new Project("Sample.mpp");
// Save the Project as PDF
project.save("Project.pdf", SaveFileFormat.PDF);
view raw MPP-to-PDF.java hosted with ❤ by GitHub

MPP to PDF Conversion with Advanced Options in Java

You can customize and control the MPP to PDF file conversion with several properties exposed by the PdfSaveOptions class. For instance, you can specify legends, time scale, row height, etc. The following steps show how to perform MPP file conversion to PDF format:

  1. Load input Microsoft Project File.
  2. Initialize SaveOptions class object.
  3. Specify different properties.
  4. Save output PDF document.

The following code shows how to convert MPP to PDF with advanced options programmatically using Java:

// Load input MPP file
Project project = new Project("project.mpp");
// Initilize SaveOptions class object
SaveOptions o = new PdfSaveOptions();
// Set the row height to fit cell content
o.setFitContent(true);
// Specify different properties
o.setTimescale(Timescale.Months);
o.setPresentationFormat(PresentationFormat.TaskUsage);
// Set the LegendOnEachPage property to false to hide legends
o.setLegendOnEachPage(false);
// Save output PDF document
project.save("result.pdf", o);

Convert MPP file to Encrypted and Password Protected PDF File using Java

Some projects may include sensitive data for an organization so you may prefer to protect the information in output PDF file. So you can encrypt and password protect the PDF document. Please follow the steps below to secure output PDF file after MPP conversion:

  1. Load input MPP file with Project class.
  2. Initialize PdfEncryptionDetails class object while specifying user and owner passwords.
  3. Initialize PdfSaveOptions class object.
  4. Save the output PDF file.

The code below explains how to convert MPP file to a password protected and encrypted PDF file programmatically using Java:

// Load input Project file
Project project = new Project(dataDir + "project.mpp");
// Initialize PdfEncryptionDetails class object
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("test", "password", PdfEncryptionAlgorithm.RC4_128);
// Set permissions for output PDF file
encryptionDetails.setPermissions(PdfPermissions.None);
// Initialize PdfSaveOptions class object
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setTimescale(Timescale.Months);
saveOptions.setPresentationFormat(PresentationFormat.TaskUsage);
saveOptions.setEncryptionDetails(encryptionDetails);
// Save output PDF file
project.save(dataDir + "Password_output.pdf", saveOptions);

Get Free API License

You can get free temporary license to evaluate the API in its full capacity.

Conclusion

In this article, you have explored how to convert MPP, Microsoft Project Files, to PDF programmatically using Java. You have learned how to save the output PDF files with advanced options or with encryption and password protection. You can explore further by visiting the Documentation or feel free to get in touch with us via the Free Support Forum.

See Also

Convert XML to MPP or Vice Versa Programmatically in Java