Render attachments

Render attachments in the same way as any other documents.

To view attachments, follow these steps:

  1. Instantiate the first Viewer object. Specify a file that contains attachments.
  2. Call the SaveAttachment method to save the attachment (to local disk, memory stream, etc).
  3. Instantiate the second Viewer object. Specify the previously saved attachment.
  4. Specify the view options depending on the output format - HtmlViewOptions/PngViewOptions/JpgViewOptions/PdfViewOptions.
  5. Call the View method.

The following code snippet shows how to render attachments from the MSG file:

Note
NOTE: provided code snippet suits all format families that support attachments: emails, Outlook data files, archives, and PDF documents.
// Specify attachment.
Attachment attachment = new Attachment("attachment-word.doc", @"C:\Output\attachment-word.doc"); 
// Create a stream for attachment.
MemoryStream attachmentStream = new MemoryStream();
//Save attachment
using (Viewer viewer = new Viewer("sample.msg"))
{
    viewer.SaveAttachment(attachment, attachmentStream); 
}
// Render attachment
using (Viewer viewer = new Viewer(attachmentStream))
{
    HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(options);
}