GroupDocs.Viewer for Python via .NET can load a source document from three kinds of sources: a local file path, a Python stream (file handle or BytesIO), or an HTTP URL. Pass any of them to the Viewer class — the engine auto-detects the format and keeps the source open only as long as necessary.
Viewer Class Constructor
The Viewer constructor accepts the source as its first positional argument. The remaining arguments are all optional and can be passed positionally or as keyword arguments:
source — a file path (str), raw bytes, or any file-like stream (open("file", "rb"), io.BytesIO(data)).
load_options — a LoadOptions instance. Use it to pass a password, override the detected file type, or tune resource-loading behaviour.
settings — a ViewerSettings instance. Holds the logger and cache, applied to the whole rendering pipeline. See Logging and Diagnostics.
leave_open — when True, the Viewer will not close the underlying stream after rendering. Handy when you want to keep reading from the same handle afterwards.
Always construct the Viewer inside a with block. The context manager releases the native handle and any cached render state as soon as the block exits.
Load Options
LoadOptions is a single class whose properties cover every format the Viewer supports. Only set the properties that apply to your source — the rest default sensibly.
Property
Type
Purpose
file_type
FileType
Override the detected format. Useful when a file has no extension or an ambiguous MIME type.
password
str
Password for an encrypted document (DOCX, XLSX, PDF, archive, Outlook, …).