Render Project documents as HTML, PDF, and image files

GroupDocs.Viewer for Python via .NET allows you to render Project files in HTML, PDF, PNG, and JPEG formats. You do not need to use Microsoft Project or other project management software to load and view Project files within your .NET application (web or desktop).

To start using the GroupDocs.Viewer API, create a Viewer class instance. Pass a document you want to view to the class constructor. You can load the document from a file or stream. Call one of the Viewer.view method overloads to convert the document to HTML, PDF, or image format. These methods allow you to render the entire document or specific pages.

View Project files online View demos and examples on GitHub

Supported Project Management file formats

GroupDocs.Viewer supports the following Project Management file formats:

GroupDocs.Viewer can detect the document format automatically based on information in the file header.

Note
Family of the Project Management file formats (MPP, MPT, and MPX) currently is not supported by the GroupDocs.Viewer.CrossPlatform.

Render Project files as HTML

Create an HtmlViewOptions class instance and pass it to the [Viewer.view method to convert a Project file to HTML. The HtmlViewOptions class properties allow you to control the conversion process. For instance, you can embed all external resources in the generated HTML file, minify the output file, and optimize it for printing. Refer to the following documentation section for details: Rendering to HTML.

Create an HTML file with embedded resources

To save all elements of an HTML page (including text, graphics, and stylesheets) into a single file, call the HtmlViewOptions.for_embedded_resources method and specify the output file name.

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Render the project's active view as HTML.
    # {0} is replaced with the current page number in the output file names.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources("page_{0}.html")
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a Project file to HTML

Create an HTML file with external resources

If you want to store an HTML file and additional resource files (such as fonts, images, and stylesheets) separately, call the HtmlViewOptions.for_external_resources method and pass the following parameters:

  • The output file path format
  • The path format for the folder with external resources
  • The resource URL format
with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Render the project's active view as HTML.
    # Specify the HTML file names and location of external resources.
    # {0} and {1} are replaced with the page number and resource name, respectively.
    viewOptions = gvo.HtmlViewOptions.for_external_resources("page_{0}.html", "page_{0}/resource_{0}_{1}", "page_{0}/resource_{0}_{1}")
    viewer.view(viewOptions)

The image below demonstrates the result. External resources are placed in a separate folder.

Place HTML resources in a separate folder

Render Project files as PDF

Create a PdfViewOptions class instance and pass it to the [Viewer.view method to convert a Project file to PDF. The PdfViewOptions class properties allow you to control the conversion process. For instance, you can protect the output PDF file, reorder its pages, and specify the quality of document images. Refer to the following documentation section for details: Rendering to PDF.

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Create a PDF file for the project's active view.
    viewOptions = gvo.PdfViewOptions("output.pdf")
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a Project file to PDF

Render Project files as PNG

Create a PngViewOptions class instance and pass it to the [Viewer.view method to convert a Project file to PNG. Use the PngViewOptions.height and PngViewOptions.width properties to specify the output image size in pixels.

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Render the project's active view as PNG.
    # {0} is replaced with the current page number in the output file names.
    viewOptions = gvo.PngViewOptions("output_{0}.png")
    # Set width and height.
    viewOptions.width = 1600
    viewOptions.height = 650
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a Project file to PNG

Render Project files as JPEG

Create a JpgViewOptions class instance and pass it to the [Viewer.view method to convert a Project file to JPEG. Use the JpgViewOptions.height and JpgViewOptions.width properties to specify the output image size in pixels.

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Render the project's active view as JPEG.
    # {0} is replaced with the current page number in the output file names.
    viewOptions = gvo.JpgViewOptions("output_{0}.jpg")
    # Set width and height.
    viewOptions.width = 1600
    viewOptions.height = 650
    viewer.view(viewOptions)

Get information about a Project file

Follow the steps below to obtain information about a Project file (the file format, the number of pages, the project’s start and end dates):

  1. Create a ViewInfoOptions instance for a specific view.
  2. Call the Viewer.get_view_info method, pass the ViewInfoOptions instance to this method as a parameter, and cast the returned object to the ProjectManagementViewInfo type.
  3. Use the ProjectManagementViewInfo class properties to retrieve information about the Project file.
with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    viewOptions = gvo.ViewInfoOptions.for_html_view()
    view_info = viewer.get_view_info(viewOptions)       
    
    info = cast(gvr.ProjectManagementViewInfo, view_info)        
    print("File type: " + str(info.file_type))
    print("The number of pages: " + str(len(info.pages)))
    print("Project start date: {0}".format(info.start_date))
    print("Project end date: {0}".format(info.end_date))
    viewer.view(viewOptions)

The following image shows a sample console output:

Get information about a Project file

Specify the output page size

GroupDocs.Viewer allows you to specify page size for the output file when you convert your Project document to HTML, PDF, or image format. Assign a PageSize enumeration member to the project_management_options.page_size property to select one of the predefined page sizes (Letter, Ledger, A0, A1, A2, A3, or A4). You can access this property for the following classes (depending on the output file format):

The following example specifies page size for the output PDF file:

import groupdocs.viewer as gv
import groupdocs.viewer.options as gvo

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Convert the document to PDF.
    viewOptions = gvo.PdfViewOptions("output.pdf")
    # Specify the page size.
    viewerOptions.project_management_options.page_size = gvo.PageSize.A3
    viewer.view(viewOptions)

Adjust the time unit

When rendering a Project file, GroupDocs.Viewer selects the smallest time unit on a timescale based on the total length of the project. You can adjust the timescale to show smaller or greater time units (from days to months). To do this, set the ViewOptions.project_management_options.time_unit property for a target view to one of the following TimeUnit enumeration members:

  • Days displays days on the timescale.
  • ThirdsOfMonths displays the Beginning/Middle/End (B/M/E) of each month on the timescale.
  • Months displays months on the timescale.
  • Unspecified means that the timescale unit is not specified.

The following code sample demonstrates how to specify the timescale unit when rendering a Project file to HTML:

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Convert the document to HTML.
    # {0} is replaced with the current page number in the file name.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources("output_{0}.html")
    # Specify the time unit.
    viewerOptions.project_management_options.time_unit = gvo.TimeUnit.ThirdsOfMonths
    viewer.view(viewOptions)

The image below illustrates the result.

Render a Project with the timescale unit set to thirds of months

Render specific dates

With GroupDocs.Viewer, you can render only a portion of the project’s timeline when you convert your Project file to HTML, PDF, or image format. Set the ViewOptions.project_management_options.start_date and ViewOptions.project_management_options.end_date properties for a target view to specify a date range the timeline should display. If you set only the start_date property, the timeline displays information for tasks from the specified date to the project’s finish date. If you set only the end_date property, the timeline contains dates from the project’s start date to the specified date.

The example below demonstrates how to convert a Project file to PDF and set the timeline date range.

import datetime

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Convert the document to PDF.
    viewOptions = gvo.PdfViewOptions("output.pdf")
    # Specify the date range.
    viewOptions.project_management_options.start_date = datetime.datetime(2022, 08, 01)
    viewOptions.project_management_options.end_date = datetime.datetime(2022, 09, 01)
    viewer.view(viewOptions)

The following image illustrates the result:

Render tasks for a specific date range

Render notes

Microsoft Project allows you to add notes to tasks, resources, and assignments.

Speaker notes in Microsoft PowerPoint

If you need to display these notes in the output HTML, PDF, or image files, enable the ViewOptions.render_notes property for a target view.

The following code sample converts a Project file with task notes to PDF:

with gv.Viewer("SoftwareDevelopmentPlan.mpp") as viewer:
    # Convert the document to PDF.
    viewOptions = gvo.PdfViewOptions("output.pdf")
    # Enable notes rendering.
    viewOptions.render_notes = True
    viewer.view(viewOptions)

The image below demonstrates the result. Notes are rendered on a separate page.

Render a Project file with task notes