Render specific pages

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 →

You can render part of the document pages only. You can specify a list of the document pages in the following ways:

Specify pages as parameters

To specify pages as the View.view() method parameters, follow these steps:

  1. Instantiate the Viewer object.
  2. Instantiate the HtmlViewOptions (or the JpgViewOptions, or the PngViewOptions, or the PdfViewOptions) object.
  3. Call the View.view() method. Specify the page numbers as the last parameters.

The following code snippet shows how to render the first and third pages of a document:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
// ...

try (Viewer viewer = new Viewer("sample.docx")) {
    HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
    viewer.view(viewOptions, 1, 3);
}

Specify pages by using an array

To specify pages by using an array, follow these steps:

  1. Instantiate the Viewer object;
  2. Instantiate the HtmlViewOptions (or the JpgViewOptions, or the PngViewOptions, or the PdfViewOptions) object;
  3. Call the View.view() method. Specify the page numbers array as the second parameter.

The following code snippet shows how to render the 1st, 2nd, and 4th pages of a document:

import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.HtmlViewOptions;
// ...

int[] pageNumbers = new int[] { 1, 2, 4 };

try (Viewer viewer = new Viewer("sample.docx")) {
    HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
    viewer.view(viewOptions, pageNumbers);
}