Get file info

GroupDocs.Redaction provides general document information, which includes:

  • FileType
  • PageCount
  • FileSize

The following code examples demonstrate how to get document information.

Get file info for a file from local disk

from groupdocs.redaction import Redactor


def get_local_file_info():
    # Load the document from local disk
    with Redactor("./sample.docx") as redactor:
        # Retrieve general document information
        info = redactor.get_document_info()

        print(f"File type: {info.file_type}")
        print(f"Number of pages: {info.page_count}")
        print(f"Document size: {info.size} bytes")


if __name__ == "__main__":
    get_local_file_info()

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

File type: Microsoft Word Open XML Document (.docx)
Number of pages: 1
Document size: 19370 bytes

Download full output

Get file info for a file from Stream

from groupdocs.redaction import Redactor


def get_file_info_from_stream():
    # Open the document as a binary stream
    with open("./sample.docx", "rb") as stream:
        # Load the document from the stream
        with Redactor(stream) as redactor:
            # Retrieve general document information
            info = redactor.get_document_info()

            print(f"File type: {info.file_type}")
            print(f"Number of pages: {info.page_count}")
            print(f"Document size: {info.size} bytes")


if __name__ == "__main__":
    get_file_info_from_stream()

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

File type: Microsoft Word Open XML Document (.docx)
Number of pages: 1
Document size: 19370 bytes

Download full output