GroupDocsGists
10/24/2017 - 7:07 AM

Examples-GroupDocs.Viewer.Examples.VisualBasic-ViewGenerator-RenderLargeDocumentAsHtml.cs

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

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);


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

            //Instantiate the HtmlOptions object
            HtmlOptions options = new HtmlOptions();

            //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;
            //Get Pre Render info
            int allPages = htmlHandler.GetDocumentInfo(new DocumentInfoOptions(guid)).Pages.Count;

            int pageNumber = 1;

            // Get total iterations and remainder
            int totalIterations = allPages / 5;
            int remainder = allPages % 5;

            for (int i = 1; i <= totalIterations; i++)
            {
                // Set range of the pages
                options.PageNumbersToConvert = Enumerable.Range(pageNumber, 5).ToList();
                // Get pages
                List<PageHtml> pages = htmlHandler.GetPages(guid, options);
                //Save each page at disk
                foreach (PageHtml page in pages)
                {
                    //Save each page at disk
                    Utilities.SaveAsHtml("it" + i + "_" + "p" + page.PageNumber + "_" + DocumentName, page.HtmlContent);
                }
                pageNumber += 5;

            }
            if (remainder > 0)
            {
                options.PageNumbersToConvert = Enumerable.Range(pageNumber, remainder).ToList();
                List<PageHtml> pages = htmlHandler.GetPages(guid, options);
                //Save each page at disk
                foreach (PageHtml page in pages)
                {
                    //Save each page at disk
                    Utilities.SaveAsHtml("it" + (totalIterations + 1) + "_" + "p" + page.PageNumber + "_" + DocumentName, page.HtmlContent);
                }
                pageNumber += 5;
            }