Render Outlook data files as HTML, PDF, and image files
Leave feedback
On this page
GroupDocs.Viewer for Node.js via Java 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 Node.js 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.
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Specify the HTML file name.
constviewOptions=groupdocs.viewer.HtmlViewOptions.forEmbeddedResources("output.html")viewer.view(viewOptions)
The following image demonstrates the result:
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.
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Create a PDF file.
constviewOptions=groupdocs.viewer.PdfViewOptions("output.pdf")viewer.view(viewOptions)
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Convert the PST file to PNG.
// {0} is replaced with the page numbers in the output image names.
constviewOptions=groupdocs.viewer.PngViewOptions("output_{0}.png")// Set width and height.
viewOptions.setWidth(950)viewOptions.setHeight(550)viewer.view(viewOptions)
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Convert the PST file to JPG.
// {0} is replaced with the page numbers in the output image names.
constviewOptions=groupdocs.viewer.JpgViewOptions("output_{0}.jpg")// Set width and height.
viewOptions.setWidth(950)viewOptions.setHeight(550)viewer.view(viewOptions)
Get information about folders in an Outlook data file
Follow the steps below to obtain information about folders contained in an Outlook data file.
Call the Viewer.getViewInfo method, pass the ViewInfoOptions instance to this method as a parameter, and cast the returned object to the OutlookViewInfo type.
functionreadFolders(viewer,viewInfoOptions,folder){constinnerInfoOptions=viewInfoOptions.forHtmlView()innerInfoOptions.getArchiveOptions().setFolder(folder)constarchiveViewInfo=viewer.getViewInfo(innerInfoOptions)constfolders=archiveViewInfo.getFolders()for(leti=0;i<folders.size();i++){console.log(" - ",folders.get(i).toString())readFolders(viewer,viewInfoOptions,folders.get(i).toString())}}constviewer=newgroupdocs.viewer.Viewer("sample.pst")constviewInfoOptions=groupdocs.viewer.ViewInfoOptions.forHtmlView()constviewInfo=viewer.getViewInfo(viewInfoOptions)// Display information about the PST file.
console.log("File type: "+viewInfo.getFileType())console.log("Pages count: "+viewInfo.getPages().size())// Display the list of folders that the PST file contains.
console.log("The file contains the following folders:")console.log(" - /")constrootFolder=""readFolders(viewer,viewInfoOptions,rootFolder)
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 setOutlookOptions method for one of the following classes (depending on the output file format):
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, use the OutlookOptions.setFolder method for a target view. Specify the folder name as follows: {Parent folder name}\\{Subfolder name}.
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Create an HTML file.
constviewOptions=groupdocs.viewer.HtmlViewOptions.forEmbeddedResources()// Render messages from the "Inbox" folder and its subfolders.
viewOptions.getOutlookOptions().setFolder("Inbox")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.setMaxItemsInFolder method 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:
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Create an HTML file.
constviewOptions=groupdocs.viewer.HtmlViewOptions.forEmbeddedResources()// Specify the maximum number of folder items.
viewOptions.getOutlookOptions().setMaxItemsInFolder(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.
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 methods:
OutlookOptions.setTextFilter—Allows you to render all messages that contain specific text in the subject or body.
OutlookOptions.setAddressFilter—Allows you to render all messages that contain specific text in the sender’s or recipient’s address.
The following code sample filters messages in a PST file before rendering this file to HTML:
constviewer=newgroupdocs.viewer.Viewer("sample.pst")// Create an HTML file.
constviewOptions=groupdocs.viewer.HtmlViewOptions.forEmbeddedResources("output.html")// Set filters.
viewOptions.getOutlookOptions().setTextFilter("Viewer")viewOptions.getOutlookOptions().setAddressFilter("groupdocs.com")viewer.view(viewOptions)
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.