Get document info

GroupDocs.Metadata allows users to get document information which includes:

  • File format (detected by the internal structure)
  • File extension
  • MIME type
  • Number of pages
  • File size
  • A value indicating whether a file is encrypted

The following code sample demonstrates how to extract basic format information from a file.

from groupdocs.metadata import Metadata


def get_document_info():
    # Open the file (the context manager releases it on exit)
    with Metadata("input.xlsx") as metadata:
        # Read basic information detected from the file's internal structure
        info = metadata.get_document_info()
        # Format, extension and MIME type come from the file_type descriptor
        print(f"File format: {info.file_type.file_format}")
        print(f"File extension: {info.file_type.extension}")
        print(f"MIME Type: {info.file_type.mime_type}")
        # Page/size/encryption details are exposed directly on the info object
        print(f"Number of pages: {info.page_count}")
        print(f"Document size: {info.size} bytes")
        print(f"Is document encrypted: {info.is_encrypted}")


if __name__ == "__main__":
    get_document_info()

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

File format: 2
File extension: .xlsx
MIME Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Number of pages: 2
Document size: 1677676 bytes
Is document encrypted: False

Download full output

More resources

Advanced usage topics

To learn more about library features and get familiar how to manage metadata and more, please refer to the advanced usage section.

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.