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 get_view_info 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:

from typing import cast
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import ViewInfoOptions
from groupdocs.viewer.results import PdfViewInfo

def get_file_type_and_pages_count():
    # Load PDF document
    with Viewer("sample.pdf") as viewer:
        options = ViewInfoOptions.for_html_view() 
        info = viewer.get_view_info(options)
        pdf_info = cast(PdfViewInfo, info)

        print("Document type is:", pdf_info.file_type)
        print("Pages count:", len(pdf_info.pages))

        print("\nView info retrieved successfully.")

if __name__ == "__main__":
    get_file_type_and_pages_count()

sample.pdf is the sample file used in this example. Click here to download it.

The following image shows a sample console output:

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.