/// <summary>
        /// Gets document pages data, dimensions and rotation angles.
        /// </summary>
        /// <param name="postedData">Posted data with document guid.</param>
        /// <param name="loadAllPages">Flag to load all pages.</param>
        /// <returns>Document pages data, dimensions and rotation angles.</returns>
        private static LoadDocumentEntity GetDocumentPages(PostedDataEntity postedData, bool loadAllPages, bool printVersion = false)
        {
            // get/set parameters
            string documentGuid = postedData.guid;
            string password     = string.IsNullOrEmpty(postedData.password) ? null : postedData.password;

            var    fileFolderName     = Path.GetFileName(documentGuid).Replace(".", "_");
            string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName);

            if (!File.Exists(documentGuid))
            {
                throw new GroupDocsViewerException("File not found.");
            }

            IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder);

            LoadDocumentEntity loadDocumentEntity;

            if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode() && !printVersion)
            {
                using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password)))
                {
                    loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, htmlViewer, printVersion);
                }
            }
            else
            {
                using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password)))
                {
                    loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, pngViewer, printVersion);
                }
            }

            return(loadDocumentEntity);
        }
        public HttpResponseMessage RotateDocumentPages(PostedDataEntity postedData)
        {
            try
            {
                var    documentGuid = postedData.guid;
                var    pageNumber   = postedData.pages[0];
                string password     = string.IsNullOrEmpty(postedData.password) ? null : postedData.password;

                var    fileFolderName     = Path.GetFileName(documentGuid).Replace(".", "_");
                string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName);

                // Delete page cache-files before regenerating with another angle.
                var cacheFiles = Directory.GetFiles(fileCacheSubFolder).Where(f => Path.GetFileName(f).StartsWith($"p{pageNumber}"));
                cacheFiles.ForEach(f => File.Delete(f));

                // Getting new rotation angle value.
                var currentAngle = GetCurrentAngle(pageNumber, Path.Combine(fileCacheSubFolder, "PagesInfo.xml"));
                int newAngle     = GetNewAngleValue(currentAngle, postedData.angle);
                SaveChangedAngleInCache(fileCacheSubFolder, pageNumber, newAngle);

                IViewerCache          cache = new FileViewerCache(cachePath, fileCacheSubFolder);
                PageDescriptionEntity page;
                if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode())
                {
                    using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password), pageNumber, newAngle))
                    {
                        page = this.GetPageDescritpionEntity(htmlViewer, documentGuid, pageNumber, fileCacheSubFolder);
                    }
                }
                else
                {
                    using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password), pageNumber, newAngle))
                    {
                        page = this.GetPageDescritpionEntity(pngViewer, documentGuid, pageNumber, fileCacheSubFolder);
                    }
                }

                return(this.Request.CreateResponse(HttpStatusCode.OK, page));
            }
            catch (Exception ex)
            {
                // set exception message
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex)));
            }
        }
        public HttpResponseMessage GetDocumentPage(PostedDataEntity postedData)
        {
            string password = string.Empty;

            try
            {
                string documentGuid = postedData.guid;
                int    pageNumber   = postedData.page;
                password = string.IsNullOrEmpty(postedData.password) ? null : postedData.password;

                var    fileFolderName     = Path.GetFileName(documentGuid).Replace(".", "_");
                string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName);

                IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder);

                PageDescriptionEntity page;
                if (globalConfiguration.GetViewerConfiguration().GetIsHtmlMode())
                {
                    using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password)))
                    {
                        page = this.GetPageDescritpionEntity(htmlViewer, documentGuid, pageNumber, fileCacheSubFolder);
                    }
                }
                else
                {
                    using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password)))
                    {
                        page = this.GetPageDescritpionEntity(pngViewer, documentGuid, pageNumber, fileCacheSubFolder);
                    }
                }

                return(this.Request.CreateResponse(HttpStatusCode.OK, page));
            }
            catch (Exception ex)
            {
                // set exception message
                return(this.Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, password)));
            }
        }