Get document page preview

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.Redaction 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-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

In GroupDocs.Redaction, Redactor class supports rendering of the document preview in on of these image formats:

  • JPEG Image
  • Portable Network Graphics (PNG)
  • Bitmap Image File (BMP)

The following example demonstrates how to get a single page preview of the document.

// Take preview of the first page
int testPageNumber = 1;
// Preview file name
string previewFileName = string.Format("{0}_page{1}.png", "D:\\sample.docx", testPageNumber);
// Load the document to generate preview
using (Redactor redactor = new Redactor("D:\\sample.docx"))
{
    PreviewOptions options = new PreviewOptions(delegate(int pageNumber) 
    { 
        return File.OpenWrite(previewFileName); 
    });
    options.Width = 480;
    options.Height = 640;
    options.PageNumbers = new int[] { testPageNumber };
    options.PreviewFormat = PreviewOptions.PreviewFormats.PNG;
    redactor.GeneratePreview(options);
    Console.WriteLine("\nPreview for page {0} was saved to \"{1}\"", testPageNumber, previewFileName);
}