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.
fromgroupdocs.metadataimportMetadatadefget_document_info():# Open the file (the context manager releases it on exit)withMetadata("input.xlsx")asmetadata:# Read basic information detected from the file's internal structureinfo=metadata.get_document_info()# Format, extension and MIME type come from the file_type descriptorprint(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 objectprint(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