How to Fetch Stream of a specific page from a document using GroupDocs.Viewer 20.8

Hello I am currently using GroupDocs.Viewer 19.6 Version in one of my utility and now I planned to upgrade it to GroupDocs.Viewer 20.8. I had a code where I am Fetching a page as a stream using GroupDocs.Viewer and I am working with that stream.

I am sharing my code for your reference.

ViewerConfig config = GetConfigurations();
ViewerImageHandler imageHandler = new ViewerImageHandler(config);


//using here
mStream.Seek(0, SeekOrigin.Begin);
imageOptions.PageNumber = pageIndex + 1;
var pages = imageHandler.GetPages(mStream, imageOptions);
pages[0].Stream.CopyTo(pageStream);

pageStream.Seek(0, SeekOrigin.Begin);

I am not able to find anything about how can I fetch a page in a stream.

@Niteen_Jadhav

Sure, please check the following code:

using System.IO;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Interfaces;
using GroupDocs.Viewer.Options;

internal class Program
{
    private static void Main(string[] args)
    {
        Stream stream = new MemoryStream();
        string fileName = "sample.docx";
        int pageNumber = 1;

        SavePageToStream(stream, fileName, pageNumber);
    }

    private static void SavePageToStream(Stream stream, string fileName, int pageNumber)
    {
        using (Viewer viewer = new Viewer(fileName))
        {
            OnePageStreamFactory streamFactory = new OnePageStreamFactory(stream);
            PngViewOptions viewOptions = new PngViewOptions(streamFactory);
            viewer.View(viewOptions, pageNumber);
        }
    }

    private class OnePageStreamFactory : IPageStreamFactory
    {   
        private readonly Stream _pageStream;

        public OnePageStreamFactory(Stream pageStream)
        {
            _pageStream = pageStream;
        }

        public Stream CreatePageStream(int pageNumber)
        {
            return _pageStream;
        }

        public void ReleasePageStream(int pageNumber, Stream pageStream)
        {
           //Do nothing
        }
    }
}

This is the sample application to do the same.

Document articles for reference: