Get the format family and the additional information

A format family is a group of several file types for which an application provides additional information. For example, archive files (.7z, .rar, .zip, etc.) or Outlook files (.ost, .pst) are format families.

You can get the format family and the additional information using the GetViewInfo method that returns a ViewInfo object.

GroupDocs.Viewer provides additional information for the following format families:

Get the file type and the pages count from a file

The following code snippet shows how to get the file type and the pages count from a file:

using System;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;
// ...

using (Viewer viewer = new Viewer("sample.pdf"))
{
    // Get file information.
    ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
    ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);

    // Display file type and pages count.
    Console.WriteLine("Document type is: " + viewInfo.FileType);
    Console.WriteLine("Pages count: " + viewInfo.Pages.Count);
}
Imports System
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.pdf")
            ' Get file information.
            Dim viewInfoOptions As ViewInfoOptions = ViewInfoOptions.ForHtmlView()
            Dim viewInfo As ViewInfo = viewer.GetViewInfo(viewInfoOptions)

            ' Display file type and pages count.
            Console.WriteLine("Document type is: " & viewInfo.FileType.ToString())
            Console.WriteLine("Pages count: " & viewInfo.Pages.Count.ToString())
        End Using
    End Sub
End Module

The following image shows a sample console output:

Get the file type and the pages count from a stream

The following code snippet shows how to get the file type and the pages count from a stream:

using System;
using System.IO;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;
// ...

using (Viewer viewer = new Viewer(File.OpenRead("sample.pdf")))
{
    ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
    ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);
 
    Console.WriteLine("Document type is: " + viewInfo.FileType);
    Console.WriteLine("Pages count: " + viewInfo.Pages.Count);
}
Imports System
Imports System.IO
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer(File.OpenRead("sample.pdf"))
            Dim viewInfoOptions As ViewInfoOptions = ViewInfoOptions.ForHtmlView()
            Dim viewInfo As ViewInfo = viewer.GetViewInfo(viewInfoOptions)

            Console.WriteLine("Document type is: " & viewInfo.FileType.ToString())
            Console.WriteLine("Pages count: " & viewInfo.Pages.Count.ToString())
        End Using
    End Sub
End Module

The following image shows a sample console output: