Render specific pages

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);
}