GroupDocsGists
10/24/2017 - 7:09 AM

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

          //Get Configurations
            ViewerConfig config = Utilities.GetConfigurations();

            // Cast ViewerHtmlHandler class object to its base class(ViewerHandler).
            ViewerHandler<PageHtml> handler = new ViewerHtmlHandler(config);

            // Guid implies that unique document name 
            string guid = DocumentName;

            //Instantiate the HtmlOptions object with setting of Reorder Transformation
            HtmlOptions options = new HtmlOptions {  Transformations=Transformation.Reorder };

            //to get html representations of pages with embedded resources
            options.IsResourcesEmbedded = true;
            
            // 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
            ViewerHtmlHandler htmlHandler = (ViewerHtmlHandler)handler;

           //Get document pages in html form
            List<PageHtml> pages = htmlHandler.GetPages(guid, options);

            foreach (PageHtml page in pages)
            {
                //Save each page at disk
                Utilities.SaveAsHtml(page.PageNumber + "_" + DocumentName, page.HtmlContent);
            }