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 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 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:

using (Viewer viewer = new Viewer("sample.docx"))
{
    // Create an HTML file.
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    // Specify the page numbers.
    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 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:

// Create an array and specify page numbers.
 int[] pageNumbers = new int[] { 1, 2, 4 };
 
 using (Viewer viewer = new Viewer("sample.docx"))
 {
    // Create an HTML file.
    var viewOptions = HtmlViewOptions.ForEmbeddedResources();
    // Use array to render specific pages.
    viewer.View(viewOptions, pageNumbers);
 }