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 GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

using (Viewer viewer = new Viewer("sample.docx"))
{
    // Create view options.
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();

    // Specify the page numbers.
    viewer.View(viewOptions, 1, 3);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
    Using viewer As Viewer = New Viewer("sample.docx")
        ' Create view options.
        Dim viewOptions As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
    
        ' Specify the page numbers.
        viewer.View(viewOptions, 1, 3)
    End Using
    End Sub
End Module

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:

using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...

// Create an array and specify page numbers.
int[] pageNumbers = new int[] { 1, 2, 4 };

using (Viewer viewer = new Viewer("sample.docx"))
{
   // Create view options.
   var viewOptions = HtmlViewOptions.ForEmbeddedResources();

   // Use array to render specific pages.
   viewer.View(viewOptions, pageNumbers);
}
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
' ...

Module Program
    Sub Main(args As String())
        ' Create an array and specify page numbers.
        Dim pageNumbers = New Integer() {1, 2, 4}
    
        Using viewer As Viewer = New Viewer("sample.docx")
            ' Create view options.
            Dim viewOptions = HtmlViewOptions.ForEmbeddedResources()
    
            ' Use array to render specific pages.
            viewer.View(viewOptions, pageNumbers)
        End Using
    End Sub
End Module