Load Document from Local Disk

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.Merger 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-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

To load a source document from the local filesystem, pass a file path to the Merger class constructor. GroupDocs.Merger for Python via .NET provides several constructor overloads to cover different loading scenarios:

  • Merger(file_path) — open a document by path with default settings.
  • Merger(file_path, load_options) — open a document by path and supply additional loading options (e.g. a password for protected files).
  • Merger(file_path, load_options, settings) — open a document by path with load options and custom MergerSettings.

You can use either an absolute or a relative path. If the specified path does not exist, an exception is raised when the first operation is performed.

Tip
GroupDocs.Merger accesses the file only when an action (e.g. get_document_info(), join(), save()) is performed on the Merger instance.

The following example demonstrates loading a PDF document from a local path and inspecting its metadata:

from groupdocs.merger import Merger

def load_from_local_disk():
    # Provide a relative or absolute path to the source document
    with Merger("./input.pdf") as merger:
        # Retrieve document information to confirm the file loaded correctly
        info = merger.get_document_info()
        print("Format:", info.type.file_format)
        print("Pages:", info.page_count)
        print("Size:", info.size, "bytes")

if __name__ == "__main__":
    load_from_local_disk()

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

Format: Portable Document Format File
Pages: 2
Size: 86913 bytes

Download full output

Explanation

  • File Path: The Merger constructor accepts the path "./input.pdf" and stores it internally. The file is not opened until an action is performed.
  • Context Manager: The with statement ensures that all unmanaged resources (file handles, .NET objects) are released automatically when the block exits, even if an exception occurs.
  • Inspect Metadata: merger.get_document_info() opens the file, reads its metadata, and returns an IDocumentInfo object. The example prints the human-readable format name (info.type.file_format), total page count, and file size in bytes.
Warning
GroupDocs.Merger determines the file type by its extension. Make sure the source file has the correct extension; otherwise the library may misdetect the format.

Refer to the GroupDocs.Merger API Reference for full details on the Merger constructor overloads.

See also