/// <summary>
        /// Get Document Information
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("***** {0} *****", "Get Document Information");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

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

            string documentName = "word.doc";
            // Get document information
            DocumentInfoOptions options = new DocumentInfoOptions(documentName);
            DocumentInfoContainer documentInfo = htmlHandler.GetDocumentInfo(options);

            Console.WriteLine("DateCreated: {0}", documentInfo.DateCreated);
            Console.WriteLine("DocumentType: {0}", documentInfo.DocumentType);
            Console.WriteLine("Extension: {0}", documentInfo.Extension);
            Console.WriteLine("FileType: {0}", documentInfo.FileType);
            Console.WriteLine("Guid: {0}", documentInfo.Guid);
            Console.WriteLine("LastModificationDate: {0}", documentInfo.LastModificationDate);
            Console.WriteLine("Name: {0}", documentInfo.Name);
            Console.WriteLine("PageCount: {0}", documentInfo.Pages.Count);
            Console.WriteLine("Size: {0}", documentInfo.Size);

            foreach (PageData pageData in documentInfo.Pages)
            {
                Console.WriteLine("Page number: {0}", pageData.Number);
                Console.WriteLine("Page name: {0}", pageData.Name);
            }
        }
        public static void InHtmlRepresentation()
        {
            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "document.xlsx";

            // Set html options to show grid lines
            HtmlOptions options = new HtmlOptions();
            options.CellsOptions.ShowHiddenSheets = true;

            DocumentInfoContainer container = htmlHandler.GetDocumentInfo(new DocumentInfoOptions(guid));

            foreach (PageData page in container.Pages)
                Console.WriteLine("Page number: {0}, Page Name: {1}, IsVisible: {2}", page.Number, page.Name, page.IsVisible);

            List<PageHtml> pages = htmlHandler.GetPages(guid, options);

            foreach (PageHtml page in pages)
            {
                Console.WriteLine("Page number: {0}", page.PageNumber);
                //Console.WriteLine("Html content: {0}", page.HtmlContent);
            }
        }
        /// <summary>
        /// Get document information by stream
        /// </summary>
        /// <param name="DocumentName">Name of input document</param>
        public static void GetDocumentInfoByStream(String DocumentName)
        {
            try
            {
                //ExStart:GetDocumentInfoByStream
                // Setup GroupDocs.Viewer config
                ViewerConfig config = Utilities.GetConfigurations();

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

                // Get document stream
                Stream stream = Utilities.GetDocumentStream(DocumentName);
                // Get document information
                DocumentInfoOptions   options      = new DocumentInfoOptions();
                DocumentInfoContainer documentInfo = htmlHandler.GetDocumentInfo(stream, options);

                Console.WriteLine("DateCreated: {0}", documentInfo.DateCreated);
                Console.WriteLine("DocumentType: {0}", documentInfo.DocumentType);
                Console.WriteLine("DocumentTypeFormat: {0}", documentInfo.DocumentTypeFormat);
                Console.WriteLine("Extension: {0}", documentInfo.Extension);
                Console.WriteLine("FileType: {0}", documentInfo.FileType);
                Console.WriteLine("Guid: {0}", documentInfo.Guid);
                Console.WriteLine("LastModificationDate: {0}", documentInfo.LastModificationDate);
                Console.WriteLine("Name: {0}", documentInfo.Name);
                Console.WriteLine("PageCount: {0}", documentInfo.Pages.Count);
                Console.WriteLine("Size: {0}", documentInfo.Size);

                foreach (PageData pageData in documentInfo.Pages)
                {
                    Console.WriteLine("Page number: {0}", pageData.Number);
                    Console.WriteLine("Page name: {0}", pageData.Name);
                }
                stream.Close();
                //ExEnd:GetDocumentInfoByStream
            }
            catch (System.Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
        /// <summary>
        /// Get attached file's html representation
        /// </summary>
        /// <param name="DocumentName">Input document name</param>
        public static void GetEmailAttachmentHTMLRepresentation(String DocumentName)
        {
            try
            {
                //ExStart:GetEmailAttachmentHTMLRepresentation
                // Setup GroupDocs.Viewer config
                ViewerConfig config = Utilities.GetConfigurations();

                // Setup html conversion options
                HtmlOptions htmlOptions = new HtmlOptions();
                htmlOptions.IsResourcesEmbedded = false;

                // Init viewer html handler
                ViewerHtmlHandler handler = new ViewerHtmlHandler(config);

                DocumentInfoContainer info = handler.GetDocumentInfo(DocumentName);

                // Iterate over the attachments collection
                foreach (AttachmentBase attachment in info.Attachments)
                {
                    Console.WriteLine("Attach name: {0}, size: {1}", attachment.Name, attachment.FileType);

                    // Get attachment document html representation
                    List <PageHtml> pages = handler.GetPages(attachment, htmlOptions);
                    foreach (PageHtml page in pages)
                    {
                        Console.WriteLine("  Page: {0}, size: {1}", page.PageNumber, page.HtmlContent.Length);
                        foreach (HtmlResource htmlResource in page.HtmlResources)
                        {
                            Stream resourceStream = handler.GetResource(attachment, htmlResource);
                            Console.WriteLine("     Resource: {0}, size: {1}", htmlResource.ResourceName, resourceStream.Length);
                        }
                    }
                }
                //ExEnd:GetEmailAttachmentHTMLRepresentation
            }
            catch (System.Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
        public ActionResult Index(string file, string attachment, int page, string resource)
        {
            var attachmentPath                        = "cache\\" + Path.GetFileNameWithoutExtension(file) + Path.GetExtension(file).Replace(".", "_") + "\\attachments\\" + attachment;
            ViewerHtmlHandler     handler             = Utils.CreateViewerHtmlHandler();
            DocumentInfoContainer info                = handler.GetDocumentInfo(file);
            List <int>            pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o          = new HtmlOptions();
            int         pageNumber = page;

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            List <PageHtml>     pages         = handler.GetPages(attachmentPath, o);
            List <HtmlResource> htmlResources = pages.Where(x => x.PageNumber == page).Select(x => x.HtmlResources).FirstOrDefault();
            var    fileResource = htmlResources.Where(x => x.ResourceName == resource).FirstOrDefault();
            string type         = "";

            if (fileResource != null)
            {
                switch ((int)fileResource.ResourceType)
                {
                case 2:
                    type = "application/font-woff";
                    break;

                case 3:

                    type = "text/css";
                    break;

                case 1:
                    type = "image/jpeg";
                    break;
                }
                Stream stream = handler.GetResource(attachmentPath, fileResource);
                return(new FileStreamResult(stream, type));
            }
            return(null);
        }
        public ActionResult Get(string file)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler     handler = Utils.CreateViewerHtmlHandler();
            DocumentInfoContainer info    = null;
            ResultModel           model   = new ResultModel();
            DocumentInfoOptions   options = new DocumentInfoOptions(file);

            try
            {
                info = handler.GetDocumentInfo(file, options);
            }
            catch (Exception x)
            {
                throw x;
            }
            model.pages = info.Pages;
            List <Attachment> attachmentList = new List <Attachment>();

            foreach (AttachmentBase attachment in info.Attachments)
            {
                List <int>      count = new List <int>();
                List <PageHtml> pages = handler.GetPages(attachment);
                for (int i = 1; i <= pages.Count; i++)
                {
                    count.Add(i);
                }
                model.attachments.Add(new Attachment(attachment.Name, count));
            }
            return(Content(JsonConvert.SerializeObject(
                               model,
                               Formatting.Indented,
                               new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }
                               ), "application/json"));
        }
        public List <PageDataModel> Get(string file)
        {
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            DocumentInfoContainer info = null;

            try
            {
                info = handler.GetDocumentInfo(file);
            }
            catch (Exception x)
            {
                throw x;
            }

            List <PageData> result = new List <PageData>();

            foreach (PageData pageData in info.Pages)
            {
                result.Add(pageData);
            }

            return(Convert(result));
        }
        public ActionResult Get(string file, string attachment, int page)
        {
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            List <int> pageNumberstoRender = new List <int>();
            var        docInfo             = handler.GetDocumentInfo(file);

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));

            List <PageHtml> list     = Utils.LoadPageHtmlList(handler, file, o);
            string          fullHtml = "";

            foreach (AttachmentBase attachmentBase in docInfo.Attachments.Where(x => x.Name == attachment))
            {
                // Get attachment document html representation
                List <PageHtml> pages = handler.GetPages(attachmentBase, o);
                foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page))
                {
                    fullHtml += pageHtml.HtmlContent;
                }
                ;
            }


            return(Content(fullHtml));
        }
        public HttpResponseMessage LoadDocumentDescription(PostedDataWrapper postedData)
        {
            string password     = "";
            string documentGuid = "";
            bool   htmlMode     = false;

            try
            {
                // get request body
                if (postedData != null)
                {
                    // get/set parameters
                    documentGuid = postedData.guid;
                    htmlMode     = postedData.htmlMode;
                    password     = postedData.password;
                    // check if documentGuid contains path or only file name
                    if (!Path.IsPathRooted(documentGuid))
                    {
                        documentGuid = quickViewConfig.getApplication().getFilesDirectory() + "/" + documentGuid;
                    }
                }
                DocumentInfoContainer documentInfoContainer = new DocumentInfoContainer();
                // get document info options
                DocumentInfoOptions documentInfoOptions = new DocumentInfoOptions(documentGuid);
                // set password for protected document
                documentInfoOptions.Password = password;
                // get document info container
                if (htmlMode)
                {
                    documentInfoContainer = viewerHtmlHandler.GetDocumentInfo(documentGuid, documentInfoOptions);
                }
                else
                {
                    documentInfoContainer = viewerImageHandler.GetDocumentInfo(documentGuid, documentInfoOptions);
                }
                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, documentInfoContainer.Pages));
            }
            catch (InvalidPasswordException ex)
            {
                // Set exception message
                ErrorMsgWrapper errorMsgWrapper = new ErrorMsgWrapper();
                if (String.IsNullOrEmpty(password))
                {
                    errorMsgWrapper.message = "Password Required";
                }
                else if (!String.IsNullOrEmpty(password))
                {
                    errorMsgWrapper.message = "Incorrect password";
                }
                else
                {
                    errorMsgWrapper.message = ex.Message;
                }
                errorMsgWrapper.exception = ex;
                return(Request.CreateResponse(HttpStatusCode.OK, errorMsgWrapper));
            }
            catch (Exception ex)
            {
                // set exception message
                ErrorMsgWrapper errorMsgWrapper = new ErrorMsgWrapper();
                errorMsgWrapper.message   = ex.Message;
                errorMsgWrapper.exception = ex;
                return(Request.CreateResponse(HttpStatusCode.OK, errorMsgWrapper));
            }
        }
Exemplo n.º 10
0
        private static void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, string fileName)
        {
            var htmlHandler = (ViewerHtmlHandler)HttpContext.Current.Session["htmlHandler"];

            var docInfo = htmlHandler.GetDocumentInfo(request.Path);

            var maxWidth  = 0;
            var maxHeight = 0;

            foreach (var pageData in docInfo.Pages)
            {
                if (pageData.Height > maxHeight)
                {
                    maxHeight = pageData.Height;
                    maxWidth  = pageData.Width;
                }
            }
            var fileData = new FileData
            {
                DateCreated  = DateTime.Now,
                DateModified = docInfo.LastModificationDate,
                PageCount    = docInfo.Pages.Count,
                Pages        = docInfo.Pages,
                MaxWidth     = maxWidth,
                MaxHeight    = maxHeight
            };



            var htmlOptions = new HtmlOptions
            {
                // IsResourcesEmbedded = Utils.IsImage(fileName),
                IsResourcesEmbedded = false,
                HtmlResourcePrefix  = string.Format("/GetResourceForHtml.aspx?documentPath={0}", fileName) + "&pageNumber={page-number}&resourceName=",
            };

            if (request.PreloadPagesCount.HasValue && request.PreloadPagesCount.Value > 0)
            {
                htmlOptions.PageNumber         = 1;
                htmlOptions.CountPagesToRender = request.PreloadPagesCount.Value;
            }

            List <string> cssList;
            var           htmlPages = GetHtmlPages(fileName, fileName, htmlOptions, out cssList);

            foreach (AttachmentBase attachment in docInfo.Attachments)
            {
                var attachmentPath         = _tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name;
                var attachmentResourcePath = HttpUtility.UrlEncode(_tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name.Replace(".", "_"));
                var attachmentHtmlOptions  = new HtmlOptions()
                {
                    IsResourcesEmbedded = Utils.IsImage(fileName),
                    HtmlResourcePrefix  = string.Format("/GetResourceForHtml.aspx?documentPath={0}", HttpUtility.UrlEncode(attachmentPath)) + "&pageNumber={page-number}&resourceName=",
                };
                List <PageHtml> pages          = _htmlHandler.GetPages(attachment, attachmentHtmlOptions);
                var             attachmentInfo = _htmlHandler.GetDocumentInfo(attachmentPath);
                fileData.PageCount += attachmentInfo.Pages.Count;
                fileData.Pages.AddRange(attachmentInfo.Pages);
                List <string> attachmentCSSList;
                var           attachmentPages = GetHtmlPages(attachmentPath, attachmentResourcePath, attachmentHtmlOptions, out attachmentCSSList);
                cssList.AddRange(attachmentCSSList);
                htmlPages.AddRange(attachmentPages);
            }
            SerializationOptions serializationOptions = new SerializationOptions
            {
                UsePdf = request.UsePdf,
                SupportListOfBookmarks       = request.SupportListOfBookmarks,
                SupportListOfContentControls = request.SupportListOfContentControls
            };
            var documentInfoJson = new DocumentInfoJsonSerializer(docInfo, serializationOptions).Serialize();

            result.documentDescription = documentInfoJson;
            result.docType             = docInfo.DocumentType;
            result.fileType            = docInfo.FileType;
            result.pageHtml            = htmlPages.Select(_ => _.HtmlContent).ToArray();
            result.pageCss             = new[] { string.Join(" ", cssList) };
        }
        private void ViewDocumentAsHtml(ViewDocumentParameters request, ViewDocumentResponse result, string fileName)
        {
            var docInfo = _htmlHandler.GetDocumentInfo(request.Path);

            var maxWidth  = 0;
            var maxHeight = 0;

            foreach (var pageData in docInfo.Pages)
            {
                if (pageData.Height > maxHeight)
                {
                    maxHeight = pageData.Height;
                    maxWidth  = pageData.Width;
                }
            }
            var fileData = new FileData
            {
                DateCreated  = DateTime.Now,
                DateModified = docInfo.LastModificationDate,
                PageCount    = docInfo.Pages.Count,
                Pages        = docInfo.Pages,
                MaxWidth     = maxWidth,
                MaxHeight    = maxHeight
            };

            var htmlOptions = new HtmlOptions()
            {
                IsResourcesEmbedded = false,
                HtmlResourcePrefix  = string.Format(
                    "/document-viewer/GetResourceForHtml?documentPath={0}", HttpUtility.UrlEncode(fileName)) + "&pageNumber={page-number}&resourceName=",
                Watermark = Utils.GetWatermark(request.WatermarkText, request.WatermarkColor,
                                               request.WatermarkPosition, request.WatermarkWidth, request.WatermarkOpacity),
            };

            if (request.PreloadPagesCount.HasValue && request.PreloadPagesCount.Value > 0)
            {
                htmlOptions.PageNumber         = 1;
                htmlOptions.CountPagesToRender = request.PreloadPagesCount.Value;
            }
            /////
            List <string> cssList;
            var           htmlPages = GetHtmlPages(fileName, htmlOptions, out cssList);

            foreach (AttachmentBase attachment in docInfo.Attachments)
            {
                var attachmentPath        = _tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name;
                var attachmentHtmlOptions = new HtmlOptions()
                {
                    IsResourcesEmbedded = Utils.IsImage(fileName),
                    HtmlResourcePrefix  = string.Format("/document-viewer/GetResourceForHtml?documentPath={0}", HttpUtility.UrlEncode(attachmentPath)) + "&pageNumber={page-number}&resourceName=",
                };
                List <PageHtml> pages          = _htmlHandler.GetPages(attachment, attachmentHtmlOptions);
                var             attachmentInfo = _htmlHandler.GetDocumentInfo(attachmentPath);
                fileData.PageCount += attachmentInfo.Pages.Count;
                fileData.Pages.AddRange(attachmentInfo.Pages);
                List <string> attachmentCSSList;
                var           attachmentPages = GetHtmlPages(attachmentInfo.Guid, attachmentHtmlOptions, out attachmentCSSList);
                cssList.AddRange(attachmentCSSList);
                htmlPages.AddRange(attachmentPages);
            }
            /////
            result.documentDescription = new FileDataJsonSerializer(fileData, new FileDataOptions()).Serialize(false);
            result.docType             = docInfo.DocumentType;
            result.fileType            = docInfo.FileType;

            result.pageHtml = htmlPages.Select(_ => _.HtmlContent).ToArray();
            result.pageCss  = new[] { string.Join(" ", cssList) };
        }
Exemplo n.º 12
0
        private List <HtmlPageContent> GetHtmlPageContents(string guid, HtmlOptions htmlOptions)
        {
            var pageContents = new List <HtmlPageContent>();

            var documentInfo = _htmlHandler.GetDocumentInfo(guid);

            var htmlPages = _htmlHandler.GetPages(guid, htmlOptions);

            foreach (var page in htmlPages)
            {
                var html = page.HtmlContent;

                var indexOfBodyOpenTag = html.IndexOf("<body>", StringComparison.InvariantCultureIgnoreCase);
                if (indexOfBodyOpenTag > 0)
                {
                    html = html.Substring(indexOfBodyOpenTag + "<body>".Length);
                }

                var indexOfBodyCloseTag = html.IndexOf("</body>", StringComparison.InvariantCultureIgnoreCase);
                if (indexOfBodyCloseTag > 0)
                {
                    html = html.Substring(0, indexOfBodyCloseTag);
                }

                string css = string.Empty;
                foreach (var resource in page.HtmlResources.Where(_ => _.ResourceType == HtmlResourceType.Style))
                {
                    var resourceStream  = _htmlHandler.GetResource(guid, resource);
                    var resourceContent = new StreamReader(resourceStream).ReadToEnd();

                    if (!string.IsNullOrEmpty(css))
                    {
                        css += " ";
                    }

                    css += resourceContent;
                }

                // wrap single image tags
                var match = Regex.Match(html, "^<img.+?src=[\"'](.+?)[\"'].*?>$", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    var src      = match.Groups[1].Value;
                    var pageData = documentInfo.Pages.Single(_ => _.Number == page.PageNumber);

                    css = ".grpdx .ie .doc-page {font-size:0;}";
                    if (documentInfo.DocumentType == DocumentTypeName.DIAGRAM)
                    {
                        html = string.Format("<div style='width:{0}px;height:{1}px;font-size:0'>" +
                                             "<img style='width:{0}px;height:{1}px;font-size:0' src='{2}'/>" +
                                             "</div>",
                                             600,
                                             800,
                                             src);
                    }
                    else
                    {
                        html = string.Format("<div style='width:{0}px;height:{1}px;font-size:0'>" +
                                             "<img style='width:{0}px;height:{1}px;font-size:0' src='{2}'/>" +
                                             "</div>",
                                             pageData.Width,
                                             pageData.Height,
                                             src);
                    }
                }

                //wrap svg tags
                if (html.StartsWith("<svg"))
                {
                    html = "<div>" + html + "</div>";
                }

                pageContents.Add(new HtmlPageContent(html, css));
            }

            return(pageContents);
        }
        public static void RenderLargeDocumentAsHtml(String DocumentName, String DocumentPassword = null)
        {
            //ExStart:RenderAsHtml
            //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;
            }

            //ExEnd:RenderAsHtml
        }
        private void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result, string fileName)
        {
            var docInfo = _imageHandler.GetDocumentInfo(request.Path);

            var maxWidth  = 0;
            var maxHeight = 0;


            foreach (var pageData in docInfo.Pages)
            {
                if (pageData.Height > maxHeight)
                {
                    maxHeight = pageData.Height;
                    maxWidth  = pageData.Width;
                }
            }
            var fileData = new FileData
            {
                DateCreated  = DateTime.Now,
                DateModified = docInfo.LastModificationDate,
                PageCount    = docInfo.Pages.Count,
                Pages        = docInfo.Pages,
                MaxWidth     = maxWidth,
                MaxHeight    = maxHeight
            };

            int[] pageNumbers = new int[docInfo.Pages.Count];
            for (int i = 0; i < docInfo.Pages.Count; i++)
            {
                pageNumbers[i] = docInfo.Pages[i].Number;
            }
            string applicationHost = GetApplicationHost();
            var    documentUrls    = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, request);

            string[] attachmentUrls = new string[0];
            foreach (AttachmentBase attachment in docInfo.Attachments)
            {
                List <PageImage> pages = _imageHandler.GetPages(attachment);
                var attachmentInfo     = new DocumentInfoContainer();
                if (Path.GetExtension(attachment.Name.Trim()) != "")
                {
                    attachmentInfo = _htmlHandler.GetDocumentInfo(htmlConfig.CachePath + "\\" + fileName.Replace(".", "_") + "\\attachments\\" + Path.GetFileNameWithoutExtension(attachment.Name.Trim()) + Path.GetExtension(attachment.Name.Trim()));
                }
                else
                {
                    try
                    {
                        attachmentInfo = _htmlHandler.GetDocumentInfo(htmlConfig.CachePath + "\\" + fileName.Replace(".", "_") + "\\attachments\\" + attachment.Name.Replace(":", "_") + ".msg");
                    }
                    catch
                    {
                        attachmentInfo = _htmlHandler.GetDocumentInfo(htmlConfig.CachePath + "\\" + fileName.Replace(".", "_") + "\\attachments\\" + attachment.Name.Replace(":", "_") + ".eml");
                    }
                }
                fileData.PageCount += pages.Count;
                fileData.Pages.AddRange(attachmentInfo.Pages);

                ViewDocumentParameters attachmentResponse = request;
                attachmentResponse.Path = request.Path.Replace(".", "_") + "\\attachments\\" + attachment.Name.Trim();
                int[] attachmentPageNumbers = new int[pages.Count];
                for (int i = 0; i < pages.Count; i++)
                {
                    attachmentPageNumbers[i] = pages[i].PageNumber;
                }
                Array.Resize <string>(ref attachmentUrls, (attachmentUrls.Length + pages.Count));
                string[] attachmentImagesUrls = new string[pages.Count];
                attachmentImagesUrls = ImageUrlHelper.GetImageUrls(applicationHost, attachmentPageNumbers, attachmentResponse);
                attachmentImagesUrls.CopyTo(attachmentUrls, (attachmentUrls.Length - pages.Count));
            }

            SerializationOptions serializationOptions = new SerializationOptions
            {
                UsePdf = request.UsePdf,
                SupportListOfBookmarks       = request.SupportListOfBookmarks,
                SupportListOfContentControls = request.SupportListOfContentControls
            };
            var documentInfoJson = new DocumentInfoJsonSerializer(docInfo, serializationOptions).Serialize();

            result.documentDescription = documentInfoJson;
            result.docType             = docInfo.DocumentType;
            result.fileType            = docInfo.FileType;
            if (docInfo.Attachments.Count > 0)
            {
                var imagesUrls = new string[attachmentUrls.Length + documentUrls.Length];
                documentUrls.CopyTo(imagesUrls, 0);
                attachmentUrls.CopyTo(imagesUrls, documentUrls.Length);
                result.imageUrls = imagesUrls;
            }
            else
            {
                result.imageUrls = documentUrls;
            }
        }