GroupDocsGists
10/24/2017 - 7:09 AM

Examples-GroupDocs.Viewer.Examples.CSharp-GroupDocs.Viewer.Examples-ViewGenerator-RenderAsImageAndReorderPage.cs

// For complete examples and data files, please go to https://github.com/groupdocsviewer/GroupDocs_Viewer_NET
//Get Configurations
ViewerConfig config = Utilities.GetConfigurations();

// Cast ViewerHtmlHandler class object to its base class(ViewerHandler).
ViewerHandler<PageImage> handler = new ViewerImageHandler(config);
            
// Guid implies that unique document name 
string guid = DocumentName;

//Initialize ImageOptions Object and setting Reorder Transformation
 ImageOptions options = new ImageOptions  {  Transformations=Transformation.Reorder  };

// Set password if document is password protected. 
if (!String.IsNullOrEmpty(DocumentPassword))
    options.Password = DocumentPassword;
           
//Call ReorderPage and pass the reference of ViewerHandler's class  parameter by reference. 
Utilities.PageTransformations.ReorderPage(ref handler,guid,CurrentPageNumber,NewPageNumber);
           
//down cast the handler(ViewerHandler) to viewerHtmlHandler
ViewerImageHandler imageHandler = (ViewerImageHandler)handler;

// Apply product license to image handler.
Utilities.ApplyLicense(ref imageHandler);

//Get document pages in image form
List<PageImage> Images = imageHandler.GetPages(guid, options);

foreach (PageImage image in Images)
{
    //Save each image at disk
    Utilities.SaveAsImage(image.PageNumber + "_" + DocumentName, image.Stream);
}