Exemple #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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlGetDocumentInfoWithOptionsRequest"/> class.
 /// </summary>
 /// <param name="fileName">The file name.</param>
 /// <param name="documentInfoOptions">The rendering options.</param>
 /// <param name="folder">The folder which contains specified file in storage.</param>
 /// <param name="storage">The file storage which have to be used.</param>
 public HtmlGetDocumentInfoWithOptionsRequest(string fileName, DocumentInfoOptions documentInfoOptions = null, string folder = null, string storage = null)
 {
     this.FileName            = fileName;
     this.DocumentInfoOptions = documentInfoOptions;
     this.Folder  = folder;
     this.Storage = storage;
 }
        /// <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);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageGetDocumentInfoFromUrlWithOptionsRequest"/> class.
 /// </summary>
 /// <param name="url">The URL to retrieve document.</param>
 /// <param name="documentInfoOptions">The rendering options.</param>
 /// <param name="fileName">The file name.</param>
 /// <param name="folder">The folder which contains specified file in storage.</param>
 /// <param name="storage">The file storage which have to be used.</param>
 public ImageGetDocumentInfoFromUrlWithOptionsRequest(string url, DocumentInfoOptions documentInfoOptions = null, string fileName = null, string folder = null, string storage = null)
 {
     this.Url = url;
     this.DocumentInfoOptions = documentInfoOptions;
     this.FileName            = fileName;
     this.Folder  = folder;
     this.Storage = storage;
 }
Exemple #5
0
        public ActionResult GetDocumentPageImage(GetDocumentPageImageParameters parameters)
        {
            //parameters.IgnoreDocumentAbsence - not supported
            //parameters.InstanceIdToken - not supported

            string guid       = parameters.Path;
            int    pageIndex  = parameters.PageIndex;
            int    pageNumber = pageIndex + 1;

            /*
             * //NOTE: This feature is supported starting from version 3.2.0
             * CultureInfo cultureInfo = string.IsNullOrEmpty(parameters.Locale)
             *  ? new CultureInfo("en-Us")
             *  : new CultureInfo(parameters.Locale);
             *
             * ViewerImageHandler viewerImageHandler = new ViewerImageHandler(viewerConfig, cultureInfo);
             */

            var imageOptions = new ImageOptions
            {
                ConvertImageFileType = _convertImageFileType,
                Watermark            = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor,
                                                          parameters.WatermarkPosition, parameters.WatermarkWidth),
                Transformations = parameters.Rotate ? Transformation.Rotate : Transformation.None
            };

            if (parameters.Rotate && parameters.Width.HasValue)
            {
                DocumentInfoOptions   documentInfoOptions   = new DocumentInfoOptions(guid);
                DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions);

                int side = parameters.Width.Value;

                int pageAngle = documentInfoContainer.Pages[pageIndex].Angle;
                if (pageAngle == 90 || pageAngle == 270)
                {
                    imageOptions.Height = side;
                }
                else
                {
                    imageOptions.Width = side;
                }
            }

            /*
             * //NOTE: This feature is supported starting from version 3.2.0
             * if (parameters.Quality.HasValue)
             *  imageOptions.JpegQuality = parameters.Quality.Value;
             */

            using (new InterProcessLock(guid))
            {
                List <PageImage> pageImages = _imageHandler.GetPages(guid, imageOptions);
                PageImage        pageImage  = pageImages.Single(_ => _.PageNumber == pageNumber);
                return(File(pageImage.Stream, GetContentType(_convertImageFileType)));
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            SetLicense();

            string executionDirectory = Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location);

            ViewerConfig viewerConfig = new ViewerConfig();

            viewerConfig.StoragePath = executionDirectory;
            viewerConfig.UsePdf      = true;

            ViewerImageHandler viewerImageHandler = new ViewerImageHandler(viewerConfig);

            string guid = "Resources\\sample.pdf";

            DocumentInfoOptions documentInfoOptions =
                new DocumentInfoOptions(guid);
            DocumentInfoContainer documentInfoContainer =
                viewerImageHandler.GetDocumentInfo(documentInfoOptions);

            foreach (PageData pageData in documentInfoContainer.Pages)
            {
                Console.WriteLine("Page number: " + pageData.Number);

                for (int i = 0; i < pageData.Rows.Count; i++)
                {
                    RowData rowData = pageData.Rows[i];

                    Console.WriteLine("Row: " + (i + 1));
                    Console.WriteLine("Text: " + rowData.Text);
                    Console.WriteLine("Text width: " + rowData.LineWidth);
                    Console.WriteLine("Text height: " + rowData.LineHeight);
                    Console.WriteLine("Distance from left: " + rowData.LineLeft);
                    Console.WriteLine("Distance from top: " + rowData.LineTop);

                    string[] words = rowData.Text.Split(' ');

                    for (int j = 0; j < words.Length; j++)
                    {
                        int coordinateIndex = j == 0 ? 0 : j + 1;

                        Console.WriteLine(string.Empty);
                        Console.WriteLine("Word: '" + words[j] + "'");
                        Console.WriteLine("Word distance from left: " + rowData.TextCoordinates[coordinateIndex]);
                        Console.WriteLine("Word width: " + rowData.TextCoordinates[coordinateIndex + 1]);
                        Console.WriteLine(string.Empty);
                    }
                }

                Console.WriteLine(string.Empty);
            }

            Console.ReadKey();
        }
Exemple #7
0
        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
            {
                if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
                {
                    info = handler.GetDocumentInfo(file, new GroupDocs.Viewer.Domain.Options.DocumentInfoOptions()
                    {
                        CellsOptions = new GroupDocs.Viewer.Converter.Options.CellsOptions()
                        {
                            CountRowsPerPage = 150, OnePagePerSheet = false
                        }
                    });
                }
                else
                {
                    info = handler.GetDocumentInfo(file);
                }
            }
            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"));
        }
Exemple #8
0
        public static ReorderPageResponse ReorderPage(ReorderPageParameters parameters)
        {
            string guid = parameters.Path;

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

            int pageNumber  = documentInfoContainer.Pages[parameters.OldPosition].Number;
            int newPosition = parameters.NewPosition + 1;

            ReorderPageOptions reorderPageOptions = new ReorderPageOptions(guid, pageNumber, newPosition);

            _imageHandler.ReorderPage(reorderPageOptions);

            return(new ReorderPageResponse());
        }
        public static void Run()
        {
            //Initialize viewer config
            ViewerConfig viewerConfig = new ViewerConfig();
            viewerConfig.StoragePath = "c:\\storage";

            //Initialize viewer handler
            ViewerImageHandler viewerImageHandler = new ViewerImageHandler(viewerConfig);

            //Set encoding
            Encoding encoding = Encoding.GetEncoding("shift-jis");

            //Set image options
            ImageOptions imageOptions = new ImageOptions();
            imageOptions.WordsOptions.Encoding = encoding;
            imageOptions.CellsOptions.Encoding = encoding;
            imageOptions.EmailOptions.Encoding = encoding;

            //Get words document pages with encoding
            string wordsDocumentGuid = "document.txt";
            List<PageImage> wordsDocumentPages = viewerImageHandler.GetPages(wordsDocumentGuid, imageOptions);

            //Get cells document pages with encoding
            string cellsDocumentGuid = "document.csv";
            List<PageImage> cellsDocumentPages = viewerImageHandler.GetPages(cellsDocumentGuid, imageOptions);

            //Get email document pages with encoding
            string emailDocumentGuid = "document.msg";
            List<PageImage> emailDocumentPages = viewerImageHandler.GetPages(emailDocumentGuid, imageOptions);

            //Get words document info with encoding
            DocumentInfoOptions wordsDocumentInfoOptions = new DocumentInfoOptions(wordsDocumentGuid);
            wordsDocumentInfoOptions.WordsDocumentInfoOptions.Encoding = encoding;
            DocumentInfoContainer wordsDocumentInfoContainer = viewerImageHandler.GetDocumentInfo(wordsDocumentInfoOptions);

            //Get cells document info with encoding
            DocumentInfoOptions cellsDocumentInfoOptions = new DocumentInfoOptions(cellsDocumentGuid);
            cellsDocumentInfoOptions.CellsDocumentInfoOptions.Encoding = encoding;
            DocumentInfoContainer cellsDocumentInfoContainer = viewerImageHandler.GetDocumentInfo(cellsDocumentInfoOptions);

            //Get email document info with encoding
            DocumentInfoOptions emailDocumentInfoOptions = new DocumentInfoOptions(emailDocumentGuid);
            emailDocumentInfoOptions.EmailDocumentInfoOptions.Encoding = encoding;
            DocumentInfoContainer emailDocumentInfoContainer = viewerImageHandler.GetDocumentInfo(emailDocumentInfoOptions);
        }
        public void ImageGetDocumentInfoFromUrlWithOptionsTest()
        {
            var file = TestFiles.FromUrlOnePageDocx;
            var documentInfoOptions = new DocumentInfoOptions();

            var request = new ImageGetDocumentInfoFromUrlWithOptionsRequest
            {
                Url = file.Url,
                DocumentInfoOptions = documentInfoOptions,
                FileName            = null,
                Folder  = FromUrlFolder,
                Storage = null
            };

            var response = ViewerApi.ImageGetDocumentInfoFromUrlWithOptions(request);

            Assert.IsInstanceOf <DocumentInfo>(response, "Expected response type is DocumentInfo");
            Assert.AreEqual(".docx", response.Extension);
        }
Exemple #11
0
        public static RotatePageResponse RotatePage(RotatePageParameters parameters)
        {
            string guid      = parameters.Path;
            int    pageIndex = parameters.PageNumber;

            DocumentInfoOptions   documentInfoOptions   = new DocumentInfoOptions(guid);
            DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions);
            int pageNumber = documentInfoContainer.Pages[pageIndex].Number;

            RotatePageOptions   rotatePageOptions   = new RotatePageOptions(guid, pageNumber, parameters.RotationAmount);
            RotatePageContainer rotatePageContainer = _imageHandler.RotatePage(rotatePageOptions);

            RotatePageResponse response = new RotatePageResponse
            {
                resultAngle = rotatePageContainer.CurrentRotationAngle
            };

            return(response);
        }
Exemple #12
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);
        }
        /// <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);
            }
        }
        public void HtmlGetDocumentInfoFromUrlWithOptionsTest()
        {
            var file = TestFiles.FromUrlWithNotesPptx;
            var documentInfoOptions = new DocumentInfoOptions();

            var request = new HtmlGetDocumentInfoFromUrlWithOptionsRequest
            {
                Url = file.Url,

                DocumentInfoOptions = documentInfoOptions,
                FileName            = file.FileName,
                Folder  = FromUrlFolder,
                Storage = null
            };

            var response = ViewerApi.HtmlGetDocumentInfoFromUrlWithOptions(request);

            Assert.AreEqual("with-notes.pptx", response.FileName);
            Assert.AreEqual(".pptx", response.Extension);
            Assert.AreEqual(1, response.Pages.Count);
        }
        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 void ImageGetDocumentInfoFromContentTest()
        {
            var file = TestFiles.PasswordProtectedDocx;
            var documentInfoOptions = new DocumentInfoOptions
            {
                Password = file.Password
            };

            var request = new ImageGetDocumentInfoFromContentRequest
            {
                DocumentInfoOptions = this.SerializeObject(documentInfoOptions),
                File     = this.GetTestFileStream(file),
                FileName = null,
                Folder   = FromContentFolder,
                Storage  = null
            };

            var response = ViewerApi.ImageGetDocumentInfoFromContent(request);

            Assert.AreEqual(".docx", response.Extension);
            Assert.AreEqual(1, response.Pages.Count);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath    = _tempPath,
                UseCache    = true
            };

            _htmlHandler  = new ViewerHtmlHandler(_config);
            _imageHandler = new ViewerImageHandler(_config);
            GetDocumentPageImageParameters parameters = new GetDocumentPageImageParameters();


            foreach (String key in Request.QueryString.AllKeys)
            {
                if (!string.IsNullOrEmpty(Request.QueryString[key]))
                {
                    var propertyInfo = parameters.GetType().GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    propertyInfo.SetValue(parameters, ChangeType(Request.QueryString[key], propertyInfo.PropertyType), null);
                }
            }

            string guid        = parameters.Path;
            int    pageIndex   = parameters.PageIndex;
            int    pageNumber  = pageIndex + 1;
            var    displayName = parameters.Path;

            /*
             * //NOTE: This feature is supported starting from version 3.2.0
             * CultureInfo cultureInfo = string.IsNullOrEmpty(parameters.Locale)
             *  ? new CultureInfo("en-Us")
             *  : new CultureInfo(parameters.Locale);
             *
             * ViewerImageHandler viewerImageHandler = new ViewerImageHandler(viewerConfig, cultureInfo);
             */

            var imageOptions = new ImageOptions
            {
                //ConvertImageFileType = _convertImageFileType,
                ConvertImageFileType = ConvertImageFileType.JPG,
                JpegQuality          = 100,
                Watermark            = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor,
                                                          parameters.WatermarkPosition, parameters.WatermarkWidth),
                Transformations = parameters.Rotate ? Transformation.Rotate : Transformation.None
            };

            if (parameters.Rotate && parameters.Width.HasValue)
            {
                DocumentInfoOptions   documentInfoOptions   = new DocumentInfoOptions(guid);
                DocumentInfoContainer documentInfoContainer = _imageHandler.GetDocumentInfo(documentInfoOptions);

                int side = parameters.Width.Value;

                int pageAngle = documentInfoContainer.Pages[pageIndex].Angle;
                if (pageAngle == 90 || pageAngle == 270)
                {
                    imageOptions.Height = side;
                }
                else
                {
                    imageOptions.Width = side;
                }
            }

            /*
             * //NOTE: This feature is supported starting from version 3.2.0
             * if (parameters.Quality.HasValue)
             *  imageOptions.JpegQuality = parameters.Quality.Value;
             */

            using (new InterProcessLock(guid))
            {
                List <PageImage> pageImages = _imageHandler.GetPages(guid, imageOptions);
                PageImage        pageImage  = pageImages.Single(_ => _.PageNumber == pageNumber);
                var fileStream = pageImage.Stream;
                // return File(pageImage.Stream, GetContentType(_convertImageFileType));
                byte[] Bytes = new byte[fileStream.Length];
                fileStream.Read(Bytes, 0, Bytes.Length);
                string contentDispositionString = "attachment; filename=\"" + displayName + "\"";


                contentDispositionString = new ContentDisposition {
                    FileName = displayName, Inline = true
                }.ToString();



                HttpContext.Current.Response.ContentType = "image/jpeg";

                HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString);
                HttpContext.Current.Response.AddHeader("Content-Length", fileStream.Length.ToString());
                HttpContext.Current.Response.OutputStream.Write(Bytes, 0, Bytes.Length);
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.End();
            }
        }
        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));
            }
        }
Exemple #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageGetAttachmentInfoWithOptionsRequest"/> class.
 /// </summary>
 /// <param name="fileName">The file name.</param>
 /// <param name="attachmentName">The attachment name.</param>
 /// <param name="documentInfoOptions">The rendering options.</param>
 /// <param name="folder">The folder which contains specified file in storage.</param>
 /// <param name="storage">The file storage which have to be used.</param>
 public ImageGetAttachmentInfoWithOptionsRequest(string fileName, string attachmentName, DocumentInfoOptions documentInfoOptions = null, string folder = null, string storage = null)
 {
     this.FileName            = fileName;
     this.AttachmentName      = attachmentName;
     this.DocumentInfoOptions = documentInfoOptions;
     this.Folder  = folder;
     this.Storage = storage;
 }