Render Outlook data files as HTML, PDF, and image files

GroupDocs.Viewer for Python via .NET allows you to render Microsoft Outlook data files in HTML, PDF, PNG, and JPEG formats. Use this library to display the contents of OST and PST files within your .NET application (web or desktop).

To start with 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 Outlook files online View demos and examples on GitHub

Supported Outlook data file formats

GroupDocs.Viewer supports the following Outlook data file formats:

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

Render Outlook data files as HTML

To convert an OST or PST file to HTML, call the HtmlViewOptions.ForEmbeddedResources method to create an HtmlViewOptions class instance and pass this instance to the Viewer.View method.

with gv.Viewer("sample.pst") as viewer:
    # Create an HTML file.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources("output.html")
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a PST file to HTML

Render Outlook data files as PDF

Create a PdfViewOptions class instance and pass it to the Viewer.View method to convert an OST or PST 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("sample.pst") as viewer:
    # Create a PDF file.
    viewOptions = gvo.PdfViewOptions("output.pdf")
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a PST file to PDF

Render Outlook data files as PNG

Create a PngViewOptions class instance and pass it to the Viewer.View method to convert an OST or PST file to PNG. Use the PngViewOptions.Height and PngViewOptions.Width properties to specify the output image size in pixels.

with gv.Viewer("sample.pst") as viewer:
    # Convert the PST file to PNG.
    # {0} is replaced with the page numbers in the output image names.
    viewOptions = gvo.PngViewOptions("output_{0}.png")
    # Set width and height.
    viewOptions.width = 800
    viewOptions.height = 900
    viewer.view(viewOptions)

The following image demonstrates the result:

Render a PST file to PNG

Render Outlook data files as JPEG

Create a JpgViewOptions class instance and pass it to the Viewer.View method to convert an OST or PST file to JPEG. Use the JpgViewOptions.Height and JpgViewOptions.Width properties to specify the output image size in pixels.

with gv.Viewer("sample.pst") as viewer:
    # Convert the PST file to JPEG.
    # {0} is replaced with the page numbers in the output image names.
    viewOptions = gvo.JpgViewOptions("output_{0}.jpg")
    # Set width and height.
    viewOptions.width = 800
    viewOptions.height = 900
    viewer.view(viewOptions)

Specify rendering options

GroupDocs.Viewer supports the OutlookOptions class that allows you to specify different options for rendering Outlook data files. To access these options, use the OutlookOptions property for one of the following classes (depending on the output file format):

Render a specific folder

When you convert an OST or PST file to HTML, PDF, or image format, GroupDocs.Viewer renders messages from all folders contained in the file (including nested folders). If you want to render items from a specific folder, set the OutlookOptions.Folder property for a target view. Specify the folder name as follows: {Parent folder name}\\{Subfolder name}.

with gv.Viewer("sample.pst") as viewer:
    # Create an HTML file.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources("output.html")
    # Render messages from the "Inbox" folder and its subfolders.
    viewOptions.outlook_options.folder = "Inbox"
    # Render messages from a specific subfolder in the "Inbox" folder.
    # viewOptions.OutlookOptions.Folder = "Inbox\\Work\\Urgent";
    viewer.view(viewOptions)

Limit the number of folder items to render

When you load large Outlook data files, it may take a significant amount of time to retrieve and render file contents. To improve rendering performance, use the OutlookOptions.MaxItemsInFolder property to limit the number of rendered items (messages, contacts, or tasks) in each folder. The default property value is 50. Set this property to 0 to render all existing items.

The following example demonstrates how to specify the maximum number of folder items to render:

with gv.Viewer("sample.pst") as viewer:
    # Create an HTML file.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources()
    # Specify the maximum number of folder items.
    viewOptions.outlook_options.max_items_in_folder = 30
    viewer.view(viewOptions)

Filter messages

Microsoft Outlook allows you to filter messages by specific words in the message body or by part of the sender’s or recipient’s address.

Filter messages in Microsoft Outlook

With GroupDocs.Viewer, you can also filter messages before rendering an Outlook data file to HTML, PDF, or image format. To do this, use the following properties:

The following code sample filters messages in a PST file before rendering this file to HTML:

with gv.Viewer("sample.pst") as viewer:
    # Create an HTML file.
    viewOptions = gvo.HtmlViewOptions.for_embedded_resources()
    # Set filters.
    viewOptions.outlook_options.text_filter = "Viewer"
    viewOptions.outlook_options.address_filter = "groupdocs.com"
    viewer.view(viewOptions)