static string DisplayPresentation(String presentationId = "1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc")
        {
            SlidesService service = GetSlideServiceClient();

            // Define request parameters.
            PresentationsResource.GetRequest request = service.Presentations.Get(presentationId);

            // Prints the number of slides and elements in a sample presentation:
            // https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit
            Presentation presentation = request.Execute();
            IList <Page> slides       = presentation.Slides;

            Console.WriteLine("The presentation contains {0} slides:", slides.Count);
            for (var i = 0; i < slides.Count; i++)
            {
                var slide = slides[i];
                Console.WriteLine("- Slide #{0} contains {1} elements.", i + 1, slide.PageElements.Count);
            }
            return(slides[0].ObjectId);
        }
        /// <summary>
        /// Converts source file with specified upload id and file name into target format.
        /// Returns details about resulted file.
        /// </summary>
        /// <param name="model">Request model.</param>
        /// <returns>Resulted file details.</returns>
        public FileSafeResult Conversion([FromBody] ConversionOptions model)
        {
            SlidesService slidesService = new SlidesService();

            var pathProcessor = new PathProcessor(model.id, model.FileName, model.FileName != null);
            var result        = slidesService.ConvertFile(
                pathProcessor.DefaultSourceFile,
                pathProcessor.OutFolder,
                model.Format.ParseEnum <SlidesConversionFormat>()
                );

            if (result == null)
            {
                return(pathProcessor.GetResultZipped());
            }
            else
            {
                return(pathProcessor.GetResult(Path.GetFileName(result)));
            }
        }
        private static void AddVideoBackground(string presentationId, string slideId)
        {
            SlidesService slidesService = GetSlideServiceClient();
            // Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout
            // and the ID "MyNewSlide_001".
            List <Request> requests = new List <Request>();
            Request        request  = new Request();

            var slideRequest = new UpdatePagePropertiesRequest();

            slideRequest.ObjectId       = (slideId);
            slideRequest.Fields         = "pageBackgroundFill";
            slideRequest.PageProperties = new PageProperties()
            {
                PageBackgroundFill = new PageBackgroundFill()
                {
                    StretchedPictureFill = new StretchedPictureFill()
                    {
                        ContentUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4gPTyRGSqYQoObgXWS9JRdsqBI7sQfJfgaAwQiZR43GxrR2hjWJE-Hg"
                    }
                }
            };
            request.UpdatePageProperties = slideRequest;
            //slideRequest.InsertionIndex = (1);
            //slideRequest.SlideLayoutReference = (new LayoutReference() { PredefinedLayout = "TITLE_AND_TWO_COLUMNS" });
            //request.UpdateShapeProperties = new UpdateShapePropertiesRequest()
            //    slideRequest.UpdatePageProperties = new UpdatePagePropertiesRequest() {Fields= "pageBackgroundFill" , PageProperties = new PageProperties() { PageBackgroundFill = new PageBackgroundFill() { StretchedPictureFill = new StretchedPictureFill() { ContentUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4gPTyRGSqYQoObgXWS9JRdsqBI7sQfJfgaAwQiZR43GxrR2hjWJE-Hg" } } } };
            requests.Add(request);

            // If you wish to populate the slide with elements, add create requests here,
            // using the slide ID specified above.

            // Execute the request.
            BatchUpdatePresentationRequest body =
                new BatchUpdatePresentationRequest()
            {
                Requests = requests
            };
            BatchUpdatePresentationResponse response =
                slidesService.Presentations.BatchUpdate(body, presentationId).Execute();
        }
        /// <summary>
        /// Merge source documents files with specified upload id into one file.
        /// Returns details about resulted file.
        /// </summary>
        /// <param name="model">Request model.</param>
        /// <returns>Resulted file details.</returns>

        public FileSafeResult Merger([FromBody] MergerOptions model)
        {
            SlidesService slidesService = new SlidesService();
            var           pathProcessor = new PathProcessor(model.idMain, null, false);

            PathProcessor pathProcessorStyleMaster = null;

            if (model.idStyleMaster != null && model.FileNameStyleMaster != null)
            {
                pathProcessorStyleMaster = new PathProcessor(model.idStyleMaster, model.FileNameStyleMaster, true);
            }

            var result = slidesService.Merger(
                pathProcessor.OutFolder,
                string.IsNullOrEmpty(model.Format)
                                                        ? SlidesConversionFormat.pptx
                                                        : model.Format.ParseEnum <SlidesConversionFormat>(),
                pathProcessorStyleMaster?.DefaultSourceFile,
                model.MainFiles.Select(fileName => Path.Combine(pathProcessor.SourceFolder, fileName)).ToArray()
                );

            return(pathProcessor.GetResult(Path.GetFileName(result)));
        }
        /// <summary>
        /// Removes password protection from file with specified upload id and file name.
        /// Method tries to remove readonly and view protection with specified password.
        /// </summary>
        /// <param name="model">Request model.</param>
        /// <returns>Resulted file details.</returns>

        public FileSafeResult Unlock([FromBody] UnProtectOptions model)
        {
            SlidesService slidesService = new SlidesService();
            var           pathProcessor = new PathProcessor(model.id, model.FileName, true);

            try
            {
                slidesService.UnlockFile(
                    pathProcessor.DefaultSourceFile,
                    pathProcessor.DefaultOutFile,
                    model.Password
                    );

                return(pathProcessor.GetResult());
            }
            catch (InvalidPasswordException)
            {
                return(new FileSafeResult
                {
                    IsSuccess = false,
                    idError = "InvalidPassword"
                });
            }
        }
Exemple #6
0
        public void Main()
        {
            UserCredential credential;


            var folderId = "";
            var fileId   = "";

            //string credPath = "token.json";
            //credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            //    credentialdriveSecrets,
            //    Scopes,
            //    "user",
            //    CancellationToken.None,
            //    new FileDataStore(credPath, true)).Result;
            //Console.WriteLine("Credential file saved to: " + credPath);

            using (var stream =
                       new FileStream(@"D:\Downloads\credentials (5).json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            var slidesService = new SlidesService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });


            var fileMetadata = new File()
            {
                Name    = "Tytul1",
                Parents = new List <string>
                {
                    folderId
                }
            };


            var createRequest = slidesService.Presentations.Create(new Presentation()
            {
                Title = "Tytul1",
            });
            var pres = createRequest.Execute();

            fileId = pres.PresentationId;


            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });


            // Retrieve the existing parents to remove
            var getRequest = service.Files.Get(fileId);

            getRequest.Fields = "parents";
            var file            = getRequest.Execute();
            var previousParents = String.Join(",", file.Parents);
            // Move the file to the new folder
            var updateRequest = service.Files.Update(new File(), fileId);

            updateRequest.Fields        = "id, parents";
            updateRequest.AddParents    = folderId;
            updateRequest.RemoveParents = previousParents;
            file = updateRequest.Execute();

            fileMetadata = new File()
            {
                Name    = "photo.pptx",
                Parents = new List <string>
                {
                    folderId
                }
            };
            FilesResource.CreateRequest request = service.Files.Create(fileMetadata);
            request.Fields = "id";
            var file1 = request.Execute();
            //= request.ResponseBody;

            // Define parameters of request.
            //FilesResource.ListRequest listRequest = service.Files.List();
            //listRequest.PageSize = 10;
            //listRequest.Fields = "nextPageToken, files(id, name)";

            //// List files.
            //IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
            //    .Files;
            //Console.WriteLine("Files:");
            //if (files != null && files.Count > 0)
            //{
            //    foreach (var file in files)
            //    {
            //        Console.WriteLine("{0} ({1})", file.Name, file.Id);
            //    }
            //}
            //else
            //{
            //    Console.WriteLine("No files found.");
            //}
            //Console.Read();
        }
Exemple #7
0
        public static void NewInstance(int lectureId)
        {
            _lectureId = lectureId;
            string         lectureAdress = Const.PresentationAdresses[lectureId];
            string         stringId      = lectureAdress.Split('/')[5];
            UserCredential credential    = null;

            try
            {
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    // The file token.json stores the user's access and refresh tokens, and is created
                    // automatically when the authorization flow completes for the first time.
                    string credPath = "token.json";
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }
            }
            catch (Exception ex)
            {
            }

            // Create Google Slides API service.
            var service = new SlidesService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            _slidesService = service;

            // Define request parameters.
            _presentationId = stringId;
            PresentationsResource.GetRequest request = service.Presentations.Get(_presentationId);

            // Prints the number of slides and elements in a sample presentation:
            // https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit
            Presentation presentation = request.Execute();
            IList <Page> slides       = presentation.Slides;

            _pages = slides;
            var       thumbnail = new PresentationsResource.PagesResource.GetThumbnailRequest(service, _presentationId, slides[0].ObjectId);
            Thumbnail v         = thumbnail.Execute();

            string imageUrl = v.ContentUrl;

            System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
            webRequest.AllowWriteStreamBuffering = true;
            webRequest.Timeout = 30000;

            System.Net.WebResponse webResponse = webRequest.GetResponse();

            System.IO.Stream streamI = webResponse.GetResponseStream();
            SendStream(streamI);
        }
        private static void AddTextToSlide(string presentationId, string slideId, String textBoxId)
        {
            SlidesService slidesService = GetSlideServiceClient();
            // Create a new square text box, using a supplied object ID.
            List <Request> requests = new List <Request>();
            Dimension      pt350    = new Dimension()
            {
                Magnitude = 350.0, Unit = "PT"
            };
            var afflineTransform = new AffineTransform()
            {
                ScaleX     = (1.0),
                ScaleY     = (1.0),
                TranslateX = (350.0),
                TranslateY = (100.0),
                Unit       = ("PT")
            };
            Size size = new Size()
            {
                Height = (pt350),
                Width  = (pt350)
            };
            var pageElementProperties = new PageElementProperties()
            {
                PageObjectId = slideId,
                Size         = size,
                Transform    = afflineTransform
            };

            requests.Add(new Request()
            {
                CreateShape = new CreateShapeRequest()
                {
                    ObjectId          = (textBoxId),
                    ShapeType         = ("TEXT_BOX"),
                    ElementProperties = pageElementProperties
                }
            });

            // Insert text into the box, using the object ID given to it.
            requests.Add(new Request()
            {
                InsertText = (new InsertTextRequest()
                {
                    ObjectId = (textBoxId),
                    InsertionIndex = (0),
                    Text = ("New Box Text Inserted")
                })
            });

            // Execute the requests.
            BatchUpdatePresentationRequest body =
                new BatchUpdatePresentationRequest()
            {
                Requests = requests
            };
            BatchUpdatePresentationResponse response =
                slidesService.Presentations.BatchUpdate(body, presentationId).Execute();
            CreateShapeResponse createShapeResponse = response.Replies.First().CreateShape;

            Console.WriteLine("Created textbox with ID: " + createShapeResponse.ObjectId);
        }
        private static void AddImageToSlide(string presentationId, string slideId, string textBoxId)
        {
            SlidesService slidesService = GetSlideServiceClient();
            // Create a new square text box, using a supplied object ID.
            List <Request> requests = new List <Request>();
            Dimension      pt350    = new Dimension()
            {
                Magnitude = 350.0, Unit = "PT"
            };
            var afflineTransform = new AffineTransform()
            {
                ScaleX     = (1.0),
                ScaleY     = (1.0),
                TranslateX = (350.0),
                TranslateY = (100.0),
                Unit       = ("PT")
            };
            Size size = new Size()
            {
                Height = (pt350),
                Width  = (pt350)
            };
            var pageElementProperties = new PageElementProperties()
            {
                PageObjectId = slideId,
                Size         = size,
                Transform    = afflineTransform
            };

            //requests.Add(new Request()
            //{
            //    CreateShape = new CreateShapeRequest()
            //    {
            //        ObjectId = textBoxId,
            //        ShapeType = "TEXT_BOX",
            //        ElementProperties = pageElementProperties
            //    }
            //});

            // Insert text into the box, using the object ID given to it.
            requests.Add(new Request()
            {
                CreateImage = new CreateImageRequest()
                {
                    ObjectId          = textBoxId,
                    Url               = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4gPTyRGSqYQoObgXWS9JRdsqBI7sQfJfgaAwQiZR43GxrR2hjWJE-Hg",
                    ElementProperties = pageElementProperties
                }
            });

            // Execute the requests.
            BatchUpdatePresentationRequest body =
                new BatchUpdatePresentationRequest()
            {
                Requests = requests
            };
            BatchUpdatePresentationResponse response =
                slidesService.Presentations.BatchUpdate(body, presentationId).Execute();
            CreateImageResponse createShapeResponse = response.Replies.First().CreateImage;

            Console.WriteLine("Created textbox with ID: " + createShapeResponse.ObjectId);
        }
 public GooglePresentationGenerator(SlidesService slidesService)
 {
     m_slidesService = slidesService ?? throw new ArgumentNullException(nameof(slidesService));
 }