Пример #1
0
        public static GetImageUrlsResponse GetImageUrls(GetImageUrlsParameters parameters)
        {
            if (string.IsNullOrEmpty(parameters.Path))
            {
                var empty = new GetImageUrlsResponse {
                    imageUrls = new string[0]
                };
                return(empty);
            }

            DocumentInfoOptions   documentInfoOptions   = new DocumentInfoOptions(parameters.Path);
            DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions);

            int[] pageNumbers = new int[documentInfoContainer.Pages.Count];
            for (int i = 0; i < documentInfoContainer.Pages.Count; i++)
            {
                pageNumbers[i] = documentInfoContainer.Pages[i].Number;
            }

            var applicationHost = GetApplicationHost();

            string[] imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, parameters);

            var result = new GetImageUrlsResponse
            {
                imageUrls = imageUrls
            };

            return(result);
        }
Пример #2
0
        public ActionResult GetImageUrls(GetImageUrlsParameters parameters)
        {
            var guid = parameters.Path;

            // Get document info
            var documentInfoContainer = _imageHandler.GetDocumentInfo(guid);

            var pageNumbers     = documentInfoContainer.Pages.Select(_ => _.Number).ToArray();
            var applicationHost = GetApplicationHost();

            // Get image urls
            string[] imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, parameters);

            return(ToJsonResult(new GetImageUrlsResult(imageUrls)));
        }
Пример #3
0
        private static void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result, string fileName)
        {
            var docInfo = _imageHandler.GetDocumentInfo(new DocumentInfoOptions(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
            };

            result.documentDescription = new FileDataJsonSerializer(fileData, new FileDataOptions()).Serialize(true);
            result.docType             = docInfo.DocumentType;
            result.fileType            = docInfo.FileType;

            DocumentInfoOptions   documentInfoOptions   = new DocumentInfoOptions(request.Path);
            DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions);

            int[] pageNumbers = new int[documentInfoContainer.Pages.Count];
            for (int i = 0; i < documentInfoContainer.Pages.Count; i++)
            {
                pageNumbers[i] = documentInfoContainer.Pages[i].Number;
            }

            string applicationHost = GetApplicationHost();

            result.imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, request);
        }
Пример #4
0
        private void ViewDocumentAsImage(ViewDocumentParameters request, ViewDocumentResponse result)
        {
            var guid = request.Path;

            // Get document info
            var documentInfo = _imageHandler.GetDocumentInfo(guid);

            // Serialize document info
            SerializationOptions serializationOptions = new SerializationOptions
            {
                UsePdf = request.UsePdf,
                SupportListOfBookmarks       = request.SupportListOfBookmarks,
                SupportListOfContentControls = request.SupportListOfContentControls
            };
            var documentInfoJson = new DocumentInfoJsonSerializer(documentInfo, serializationOptions)
                                   .Serialize();

            // Build result
            result.documentDescription = documentInfoJson;
            result.docType             = documentInfo.DocumentType;
            result.fileType            = documentInfo.FileType;
            int[] pageNumbers = documentInfo.Pages.Select(_ => _.Number).ToArray();
            result.imageUrls = ImageUrlHelper.GetImageUrls(GetApplicationHost(), pageNumbers, request);
        }
Пример #5
0
        private static 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     = _imageHandler.GetDocumentInfo(_tempPath + "\\" + Path.GetFileNameWithoutExtension(docInfo.Guid) + Path.GetExtension(docInfo.Guid).Replace(".", "_") + "\\attachments\\" + attachment.Name);
                fileData.PageCount += pages.Count;
                fileData.Pages.AddRange(attachmentInfo.Pages);

                ViewDocumentParameters attachmentResponse = request;
                attachmentResponse.Path = attachmentInfo.Guid;
                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;
            }
        }
Пример #6
0
        public static GetImageUrlsResponse GetImageUrls(GetImageUrlsParameters parameters)
        {
            var docPath = parameters.Path;

            if (string.IsNullOrEmpty(parameters.Path))
            {
                var empty = new GetImageUrlsResponse {
                    imageUrls = new string[0]
                };
                return(empty);
            }

            DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(parameters.Path);

            int[] pageNumbers = new int[documentInfoContainer.Pages.Count];
            for (int i = 0; i < documentInfoContainer.Pages.Count; i++)
            {
                pageNumbers[i] = documentInfoContainer.Pages[i].Number;
            }

            var applicationHost = GetApplicationHost();

            string[] imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, parameters);

            string[] attachmentUrls = new string[0];
            foreach (AttachmentBase attachment in documentInfoContainer.Attachments)
            {
                List <PageImage> pages = _imageHandler.GetPages(attachment);
                var attachmentInfo     = _imageHandler.GetDocumentInfo(_tempPath + "\\" + Path.GetFileNameWithoutExtension(docPath) + Path.GetExtension(docPath).Replace(".", "_") + "\\attachments\\" + attachment.Name);

                GetImageUrlsParameters attachmentResponse = parameters;
                attachmentResponse.Path = attachmentInfo.Guid;
                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));
            }
            if (documentInfoContainer.Attachments.Count > 0)
            {
                var imagesUrls = new string[attachmentUrls.Length + imageUrls.Length];
                imageUrls.CopyTo(imagesUrls, 0);
                attachmentUrls.CopyTo(imagesUrls, imageUrls.Length);

                var result = new GetImageUrlsResponse
                {
                    imageUrls = imagesUrls
                };
                return(result);
            }
            else
            {
                var result = new GetImageUrlsResponse
                {
                    imageUrls = imageUrls
                };
                return(result);
            }
        }