コード例 #1
0
        public ActionResult RotatePage(RotatePageParameters parameters)
        {
            try
            {
                string guid      = parameters.Path;
                int    pageIndex = parameters.PageNumber;

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

                RotatePageOptions rotatePageOptions = new RotatePageOptions(pageNumber, parameters.RotationAmount);

                _imageHandler.RotatePage(guid, rotatePageOptions);
                DocumentInfoContainer container = _imageHandler.GetDocumentInfo(guid);

                PageData pageData = container.Pages.Single(_ => _.Number == pageNumber);

                RotatePageResponse response = new RotatePageResponse
                {
                    resultAngle = pageData.Angle
                };

                return(ToJsonResult(response));
            }
            catch (Exception e)
            {
                return(this.JsonOrJsonP(new FailedResponse {
                    Reason = e.Message
                }, null));
            }
        }
コード例 #2
0
 public HttpResponseMessage RotateDocumentPages(PostedDataWrapper postedData)
 {
     try
     {
         // get/set parameters
         String     documentGuid = postedData.guid;
         int        angle        = postedData.angle;
         List <int> pages        = postedData.pages;
         bool       htmlMode     = postedData.htmlMode;
         string     password     = postedData.password;
         // a list of the rotated pages info
         List <RotatedPageWrapper> rotatedPages = new List <RotatedPageWrapper>();
         // rotate pages
         for (int i = 0; i < pages.Count; i++)
         {
             // prepare rotated page info object
             RotatedPageWrapper rotatedPage = new RotatedPageWrapper();
             int pageNumber = pages[i];
             RotatePageOptions rotateOptions = new RotatePageOptions(pageNumber, angle);
             // perform page rotation
             String resultAngle = "0";
             // set password for protected document
             if (!String.IsNullOrEmpty(password))
             {
                 rotateOptions.Password = password;
             }
             if (htmlMode)
             {
                 viewerHtmlHandler.RotatePage(documentGuid, rotateOptions);
                 resultAngle = viewerHtmlHandler.GetDocumentInfo(documentGuid).Pages[pageNumber - 1].Angle.ToString();
             }
             else
             {
                 viewerImageHandler.RotatePage(documentGuid, rotateOptions);
                 resultAngle = viewerImageHandler.GetDocumentInfo(documentGuid).Pages[pageNumber - 1].Angle.ToString();
             }
             // add rotated page number
             rotatedPage.pageNumber = pageNumber;
             // add rotated page angle
             rotatedPage.angle = resultAngle;
             // add rotated page object into resulting list
             rotatedPages.Add(rotatedPage);
         }
         return(Request.CreateResponse(HttpStatusCode.OK, rotatedPages));
     }
     catch (Exception ex)
     {
         // set exception message
         ErrorMsgWrapper errorMsgWrapper = new ErrorMsgWrapper();
         errorMsgWrapper.message   = ex.Message;
         errorMsgWrapper.exception = ex;
         return(Request.CreateResponse(HttpStatusCode.OK, errorMsgWrapper));
     }
 }
        /// <summary>
        /// Perform multiple transformations in Image mode
        /// </summary>
        public static void Multiple_Transformations_For_Image()
        {
            Console.WriteLine("***** {0} *****", "Perform multiple transformations in Image mode");

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

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

            // Create image handler
            ViewerImageHandler imageHandler = new ViewerImageHandler(config);
            string guid = "word.doc";

            // Rotate first page 90 degrees
            imageHandler.RotatePage(new RotatePageOptions(guid, 1, 90));

            // Rotate second page 180 degrees
            imageHandler.RotatePage(new RotatePageOptions(guid, 2, 180));

            // Reorder first and second pages
            imageHandler.ReorderPage(new ReorderPageOptions(guid, 1, 2));

            // Set options to include rotate and reorder transformations
            ImageOptions options = new ImageOptions { Transformations = Transformation.Rotate | Transformation.Reorder };

            // Set watermark properties
            Watermark watermark = new Watermark("This is watermark text")
            {
                Color = System.Drawing.Color.Blue,
                Position = WatermarkPosition.Diagonal,
                Width = 100
            };

            options.Watermark = watermark;

            // Get document pages image representation with multiple transformations
            List<PageImage> pages = imageHandler.GetPages(guid, options);
        }
コード例 #4
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);
        }
コード例 #5
0
        public ActionResult RotatePage(RotatePageParameters parameters)
        {
            string guid      = parameters.Path;
            int    pageIndex = parameters.PageNumber;

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

            RotatePageOptions rotatePageOptions = new RotatePageOptions(pageNumber, parameters.RotationAmount);

            _imageHandler.RotatePage(guid, rotatePageOptions);

            documentInfoContainer = _imageHandler.GetDocumentInfo(guid);
            var resultAngle = documentInfoContainer.Pages[pageIndex].Angle;

            return(ToJsonResult(new RotatePageResponse {
                resultAngle = resultAngle
            }));
        }
コード例 #6
0
        public static RotatePageResponse RotatePage(RotatePageParameters parameters)
        {
            string guid      = parameters.Path;
            int    pageIndex = parameters.PageNumber;

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

            RotatePageOptions rotatePageOptions = new RotatePageOptions(pageNumber, parameters.RotationAmount);

            _imageHandler.RotatePage(guid, rotatePageOptions);
            DocumentInfoContainer container = _imageHandler.GetDocumentInfo(guid);

            PageData pageData = container.Pages.Single(_ => _.Number == pageNumber);

            RotatePageResponse response = new RotatePageResponse
            {
                resultAngle = pageData.Angle
            };

            return(response);
        }
        public ActionResult Get(int?width, int?height, string file, int page, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity, int?rotate, int?zoom)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerImageHandler handler = Utils.CreateViewerImageHandler();

            if (rotate.HasValue)
            {
                if (rotate.Value > 0)
                {
                    handler.ClearCache(file);
                }
            }

            ImageOptions options = new ImageOptions();

            options.PageNumbersToRender = new List <int>(new int[] { page });
            options.PageNumber          = page;
            options.CountPagesToRender  = 1;

            if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
            {
                options.CellsOptions.OnePagePerSheet  = false;
                options.CellsOptions.CountRowsPerPage = 150;
            }

            if (watermarkText != "")
            {
                options.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }

            if (width.HasValue)
            {
                int w = Convert.ToInt32(width);
                if (zoom.HasValue)
                {
                    w = w + zoom.Value;
                }
                options.Width = w;
            }

            if (height.HasValue)
            {
                if (zoom.HasValue)
                {
                    options.Height = options.Height + zoom.Value;
                }
            }

            if (rotate.HasValue)
            {
                if (rotate.Value > 0)
                {
                    if (width.HasValue)
                    {
                        int side = options.Width;

                        DocumentInfoContainer documentInfoContainer = handler.GetDocumentInfo(file);
                        int pageAngle = documentInfoContainer.Pages[page - 1].Angle;
                        if (pageAngle == 90 || pageAngle == 270)
                        {
                            options.Height = side;
                        }
                        else
                        {
                            options.Width = side;
                        }
                    }

                    options.Transformations = Transformation.Rotate;
                    handler.RotatePage(file, new RotatePageOptions(page, rotate.Value));
                }
            }
            else
            {
                options.Transformations = Transformation.None;
                handler.RotatePage(file, new RotatePageOptions(page, 0));
            }

            using (new InterProcessLock(file))
            {
                List <PageImage> list      = handler.GetPages(file, options);
                PageImage        pageImage = list.Single(_ => _.PageNumber == page);

                return(File(pageImage.Stream, "image/png"));
            }
        }
        public HttpResponseMessage Get(int?width, string file, int page, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity, int?rotate, int?zoom, int?height = null)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerImageHandler handler = Utils.CreateViewerImageHandler();

            if (rotate.HasValue)
            {
                if (rotate.Value > 0)
                {
                    handler.ClearCache(file);
                }
            }

            ImageOptions options = new ImageOptions();

            options.PageNumbersToRender = new List <int>(new int[] { page });
            options.PageNumber          = page;
            options.CountPagesToRender  = 1;

            if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
            {
                options.CellsOptions.OnePagePerSheet  = false;
                options.CellsOptions.CountRowsPerPage = 150;
            }

            if (watermarkText != "")
            {
                options.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }

            if (width.HasValue)
            {
                int w = Convert.ToInt32(width);
                if (zoom.HasValue)
                {
                    w = w + zoom.Value;
                }
                options.Width = w;
            }

            if (height.HasValue)
            {
                if (zoom.HasValue)
                {
                    options.Height = options.Height + zoom.Value;
                }
            }

            if (rotate.HasValue)
            {
                if (rotate.Value > 0)
                {
                    if (width.HasValue)
                    {
                        int side = options.Width;

                        DocumentInfoContainer documentInfoContainer = handler.GetDocumentInfo(file);
                        int pageAngle = documentInfoContainer.Pages[page - 1].Angle;
                        if (pageAngle == 90 || pageAngle == 270)
                        {
                            options.Height = side;
                        }
                        else
                        {
                            options.Width = side;
                        }
                    }

                    options.Transformations = Transformation.Rotate;
                    handler.RotatePage(file, new RotatePageOptions(page, rotate.Value));
                }
            }
            else
            {
                options.Transformations = Transformation.None;
                handler.RotatePage(file, new RotatePageOptions(page, 0));
            }

            List <PageImage> list      = handler.GetPages(file, options);
            PageImage        pageImage = list.Single(_ => _.PageNumber == page);

            Stream       stream       = pageImage.Stream;
            var          result       = new HttpResponseMessage(HttpStatusCode.OK);
            Image        image        = Image.FromStream(stream);
            MemoryStream memoryStream = new MemoryStream();

            image.Save(memoryStream, ImageFormat.Jpeg);
            result.Content = new ByteArrayContent(memoryStream.ToArray());
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Rotate page in Image mode
        /// </summary>
        public static void Rotate_page_in_Image_mode()
        {
            Console.WriteLine("***** {0} *****", "Rotate page in Image mode");

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

            string licensePath = @"D:\GroupDocs.Viewer.lic";

            // Setup license
            GroupDocs.Viewer.License lic = new GroupDocs.Viewer.License();
            lic.SetLicense(licensePath);


            /* ********************  SAMPLE BEGIN *********************** */
            /* ********************  Rotate 1st page of the document by 90 deg *********************** */
            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create image handler
            ViewerImageHandler imageHandler = new ViewerImageHandler(config);
            string guid = "word.doc";

            // Set rotation angle 90 for page number 1
            RotatePageOptions rotateOptions = new RotatePageOptions(guid, 1, 90);

            // Perform page rotation
            imageHandler.RotatePage(rotateOptions);


            /* ********************  Retrieve all document pages including transformation *********************** */
            // Set image options to include rotate transformations
            ImageOptions imageOptions = new ImageOptions
            {
                Transformations = Transformation.Rotate
            };

            // Get image representation of all document pages, including rotate transformations 
            List<PageImage> pages = imageHandler.GetPages(guid, imageOptions);


            /* ********************  Retrieve all document pages excluding transformation *********************** */
            // Set image options NOT to include ANY transformations
            ImageOptions noTransformationsOptions = new ImageOptions
            {
                Transformations = Transformation.None // This is by default
            };

            // Get image representation of all document pages, without transformations 
            List<PageImage> pagesWithoutTransformations = imageHandler.GetPages(guid, noTransformationsOptions);

            // Get image representation of all document pages, without transformations
            List<PageImage> pagesWithoutTransformations2 = imageHandler.GetPages(guid);


            /*********************  SAMPLE END *************************/

            //foreach (PageImage page in pages)
            //{
            //    // Page number
            //    Console.WriteLine("Page number: {0}", page.PageNumber);

            //    // Page image stream
            //    Stream imageContent = page.Stream;

            //    using (
            //        FileStream file = new FileStream(string.Format(@"C:\{0}.png", page.PageNumber),
            //            FileMode.Create, FileAccess.ReadWrite))
            //    {
            //        MemoryStream xxx = new MemoryStream();
            //        page.Stream.CopyTo(xxx);
            //        var arr = xxx.ToArray();
            //        file.Write(arr, 0, arr.Length);
            //    }
            //}
        }