Get document info

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

GroupDocs.Watermark can obtain a document’s basic information — file type, page count, and size — before you process it. The get_document_info() method works on a Watermarker opened from either a file path or a stream.

Get document information from a file

from groupdocs.watermark import Watermarker

def get_document_info():
    with Watermarker("./sample.docx") as watermarker:
        info = watermarker.get_document_info()
        print("File type:", info.file_type)
        print("Pages:", info.page_count)
        print("Size, bytes:", info.size)

if __name__ == "__main__":
    get_document_info()

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

File type: Docx (.docx) - WordProcessing
Pages: 4
Size, bytes: 122480

Download full output

Get document information from a stream

A document can also be opened from any readable stream:

import io
from groupdocs.watermark import Watermarker

def get_document_info_from_stream():
    with open("./sample.docx", "rb") as f:
        stream = io.BytesIO(f.read())

    with Watermarker(stream) as watermarker:
        info = watermarker.get_document_info()
        print("File type:", info.file_type)
        print("Pages:", info.page_count)
        print("Size, bytes:", info.size)

if __name__ == "__main__":
    get_document_info_from_stream()

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

File type: Docx (.docx) - WordProcessing
Pages: 4
Size, bytes: 122480

Download full output

Note
Use case: Validate documents before processing — for example, reject unsupported file types or confirm page limits.