Generate Document Pages Preview

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

GroupDocs.Comparison can render thumbnail images of selected pages — useful for review dashboards, file browsers, and any UI that needs a quick visual reference without downloading the full document.

Example: Render PNG previews of selected pages

from groupdocs.comparison import Comparer
from groupdocs.comparison.options import PreviewOptions, PreviewFormats


def create_page_stream(page_number):
    # Return a writable stream — GroupDocs.Comparison writes the rendered page into it.
    return open(f"./page-{page_number}.png", "wb")


def release_page_stream(page_number):
    # The stream returned from create_page_stream has already been flushed and
    # closed by .NET. This hook is for any per-page bookkeeping you want to do.
    pass


def generate_document_pages_preview():
    with Comparer("./source.docx") as comparer:
        preview_options = PreviewOptions(create_page_stream, release_page_stream)
        preview_options.preview_format = PreviewFormats.PNG
        preview_options.page_numbers = [1, 2, 3]
        comparer.source.generate_preview(preview_options)

if __name__ == "__main__":
    generate_document_pages_preview()

source.docx is the document used in this example. Click here to download it.

Binary file (PNG, 163 KB)

Download full output

You can choose the output format (PNG / JPEG), control resolution, and render only selected pages.

Use case: generate thumbnails for a review dashboard without downloading full documents.