Render documents

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 →

Rendering turns a document into files that a browser or an app can display: HTML pages, a PDF file, or PNG and JPEG images. GroupDocs.Viewer renders more than 190 formats, and all of them the same way: open the document with a Viewer, create the view options of the output you need, and call Viewer.view.

A three-page DOCX rendered by GroupDocs.Viewer: three HTML files, three PNG images or three JPEG images, one per page, or one PDF file with all three pages

Choose the output

OutputView optionsFilesGood for
HTMLHtmlViewOptionsOne HTML file per page. Its fonts, images and styles are embedded in it or saved next to itShowing a document in a web page, with text that readers can select and search
PDFPdfViewOptionsOne PDF file with every pageDownloading, printing and archiving
PNGPngViewOptionsOne image per page, losslessPreviews and thumbnails with sharp text
JPEGJpgViewOptionsOne image per page, smaller than PNGPhotos and scans, where file size matters more

When an output has one file per page, put {0} in the file name: it is replaced with the page number, so page_{0}.png gives page_1.png, page_2.png and so on. A PDF needs no {0}, because every page goes into the one file.

Render a document

The following example renders each page of a Word document to a PNG image:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

def render_document_to_png():
    # Load the document
    with Viewer("sample.docx") as viewer:
        # Create a PNG image for each page.
        # {0} is replaced with the current page number in the file name.
        viewOptions = PngViewOptions("render_document_to_png/page_{0}.png")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_document_to_png()

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

render_document_to_png/page_1.png (287 KB)
render_document_to_png/page_2.png (33 KB)
render_document_to_png/page_3.png (33 KB)
render_document_to_png/page_4.png (430 KB)
render_document_to_png/page_5.png (21 KB)

Download full output

Replace PngViewOptions with JpgViewOptions, PdfViewOptions or HtmlViewOptions.for_embedded_resources to get the other outputs; the pages below describe each one.

Render specific pages

To render only some of the pages, pass their numbers to Viewer.view after the view options. The following example renders pages 1 and 3:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

def render_specific_pages():
    # Load the document
    with Viewer("sample.docx") as viewer:
        # {0} is replaced with the current page number in the file name.
        viewOptions = PngViewOptions("render_specific_pages/page_{0}.png")
        # Render pages 1 and 3 only.
        viewer.view(viewOptions, [1, 3])

if __name__ == "__main__":
    render_specific_pages()

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

render_specific_pages/page_1.png (287 KB)
render_specific_pages/page_3.png (33 KB)

Download full output

When you render to PDF, the order of the numbers is the order of the pages in the file: see Reorder pages.

More about rendering

Each format has options of its own, such as the hidden slides of a presentation, the layers of a CAD drawing or the folders of an archive. See Document rendering basics. The pages of this section cover the outputs, rendering to memory instead of files, and cancelling a render: