Hello, World!

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

Introduction

A “Hello, World!” example is often the first step when exploring GroupDocs.Viewer for Python via .NET. It serves as a simple test to confirm that your development environment is correctly set up and that the library is functioning as expected.

Overview

GroupDocs.Viewer for Python via .NET renders documents to HTML, PDF, PNG, and JPEG without Microsoft Office or any other software. A wide range of supported formats makes it versatile for different use cases.

How to render a document

The following steps render a Word document to a PDF file:

  1. Import Viewer and the view options of the output you need, here PdfViewOptions.
  2. Instantiate a Viewer with the path to the sample document.
  3. Create the view options with the output file name.
  4. Call view() with the options.

Complete example

The example below renders the five pages of the sample annual report into one PDF file:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def hello_world():
    # Load the document
    with Viewer("sample.docx") as viewer:
        # Render every page into one PDF file
        viewer.view(PdfViewOptions("output.pdf"))

    print("Document rendered successfully. Output saved to output.pdf.")

if __name__ == "__main__":
    hello_world()

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

Binary file (PDF, 719 KB)

Download full output

To render to HTML pages or page images instead, replace PdfViewOptions with HtmlViewOptions.for_embedded_resources("page_{0}.html") or PngViewOptions("page_{0}.png"); {0} is replaced with the page number. The Quick Start Guide shows all three.

Without a license, the PDF has two pages, each with an evaluation notice. See Licensing and Evaluation.

Additional resources

This demo references the GroupDocs.Viewer for Python via .NET code samples.