diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document.sln b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document.sln new file mode 100644 index 00000000..630a1814 --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34205.153 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open-PowerPoint-document", "Open-PowerPoint-document\Open-PowerPoint-document.csproj", "{93F4EA0D-FA3D-47FB-8DFC-204C609E856F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {024A6C01-116E-4483-9B82-338F6A791749} + EndGlobalSection +EndGlobal diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Open-PowerPoint-document.csproj b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Open-PowerPoint-document.csproj new file mode 100644 index 00000000..3588f78e --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Open-PowerPoint-document.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + Open_PowerPoint_document + enable + enable + + + + + + diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Program.cs b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Program.cs new file mode 100644 index 00000000..40397c7f --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Open-PowerPoint-document/Open-PowerPoint-document/Program.cs @@ -0,0 +1,51 @@ +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Services; +using Google.Apis.Util.Store; + +namespace Open_PowerPoint_document +{ + internal class Program + { + static void Main(string[] args) + { + UserCredential credential; + string[] Scopes = { DriveService.Scope.DriveReadonly }; + string ApplicationName = "YourAppName"; + // Step 1: Open Google Drive with credentials. + using (var cretendialStream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) + { + string credPath = "token.json"; + credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + GoogleClientSecrets.Load(cretendialStream).Secrets, + Scopes, + "user", + CancellationToken.None, + new FileDataStore(credPath, true)).Result; + } + + // Step 2: Create Drive API service. + var service = new DriveService(new BaseClientService.Initializer() + { + HttpClientInitializer = credential, + ApplicationName = ApplicationName, + }); + + // Step 3: Specify the file ID of the PowerPoint presentation you want to open. + string fileId = "YOUR_FILE_ID"; // Replace with the actual file ID YOUR_FILE_ID. + + // Step 4: Download the PowerPoint presentation from Google Drive. + var request = service.Files.Get(fileId); + var stream = new MemoryStream(); + request.Download(stream); + + // Step 5: Save the PowerPoint presentation locally. + using (FileStream fileStream = new FileStream("Output.pptx", FileMode.Create, FileAccess.Write)) + { + stream.WriteTo(fileStream); + } + //Dispose the memory stream. + stream.Dispose(); + } + } +} diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document.sln b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document.sln new file mode 100644 index 00000000..318bd7b6 --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34205.153 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Save-PowerPoint-document", "Save-PowerPoint-document\Save-PowerPoint-document.csproj", "{93F4EA0D-FA3D-47FB-8DFC-204C609E856F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {93F4EA0D-FA3D-47FB-8DFC-204C609E856F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {024A6C01-116E-4483-9B82-338F6A791749} + EndGlobalSection +EndGlobal diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Data/Image.jpg b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Data/Image.jpg new file mode 100644 index 00000000..62e1d53b Binary files /dev/null and b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Data/Image.jpg differ diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Program.cs b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Program.cs new file mode 100644 index 00000000..07c52ead --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Program.cs @@ -0,0 +1,106 @@ +using Google.Apis.Auth.OAuth2; +using Google.Apis.Drive.v3; +using Google.Apis.Services; +using Google.Apis.Util.Store; +using File = Google.Apis.Drive.v3.Data.File; +using Syncfusion.Presentation; + +namespace Save_PowerPoint_document +{ + internal class Program + { + static void Main(string[] args) + { + //Create a new instance of PowerPoint Presentation file. + IPresentation pptxDocument = Presentation.Create(); + + //Add a new slide to file and apply background color. + ISlide slide = pptxDocument.Slides.Add(SlideLayoutType.TitleOnly); + //Specify the fill type and fill color for the slide background. + slide.Background.Fill.FillType = FillType.Solid; + slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229); + + //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide. + IShape titleShape = slide.Shapes[0] as IShape; + titleShape.TextBody.AddParagraph("Company History").HorizontalAlignment = HorizontalAlignmentType.Center; + + //Add description content to the slide by adding a new TextBox. + IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); + descriptionShape.TextBody.Text = "IMN Solutions PVT LTD is the software company, established in 1987, by George Milton. The company has been listed as the trusted partner for many high-profile organizations since 1988 and got awards for quality products from reputed organizations."; + + //Add bullet points to the slide. + IShape bulletPointsShape = slide.AddTextBox(53.22, 270, 437.90, 116.32); + + //Add a paragraph for a bullet point. + IParagraph firstPara = bulletPointsShape.TextBody.AddParagraph("The company acquired the MCY corporation for 20 billion dollars and became the top revenue maker for the year 2015."); + //Format how the bullets should be displayed. + firstPara.ListFormat.Type = ListType.Bulleted; + firstPara.LeftIndent = 35; + firstPara.FirstLineIndent = -35; + + //Add another paragraph for the next bullet point. + IParagraph secondPara = bulletPointsShape.TextBody.AddParagraph("The company is participating in top open source projects in automation industry."); + //Format how the bullets should be displayed. + secondPara.ListFormat.Type = ListType.Bulleted; + secondPara.LeftIndent = 35; + secondPara.FirstLineIndent = -35; + + //Gets a picture as stream. + FileStream pictureStream = new FileStream(Path.GetFullPath("../../../Data/Image.jpg"), FileMode.Open); + //Adds the picture to a slide by specifying its size and position. + slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); + + //Add an auto-shape to the slide. + IShape stampShape = slide.Shapes.AddShape(AutoShapeType.Explosion1, 48.93, 430.71, 104.13, 80.54); + //Format the auto-shape color by setting the fill type and text. + stampShape.Fill.FillType = FillType.None; + stampShape.TextBody.AddParagraph("IMN").HorizontalAlignment = HorizontalAlignmentType.Center; + + //Saves the PowerPoint to MemoryStream. + MemoryStream stream = new MemoryStream(); + pptxDocument.Save(stream); + + // Load Google Drive API credentials from a file. + UserCredential credential; + string[] Scopes = { DriveService.Scope.Drive }; + string ApplicationName = "YourAppName"; + + using (var stream1 = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))//Replace with your actual credentials.json + { + string credPath = "token.json"; + // Authorize the Google Drive API access. + credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + GoogleClientSecrets.Load(stream1).Secrets, + Scopes, + "user", + CancellationToken.None, + new FileDataStore(credPath, true)).Result; + } + // Create a new instance of Google Drive service. + var service = new DriveService(new BaseClientService.Initializer() + { + HttpClientInitializer = credential, + ApplicationName = ApplicationName, + }); + + // Create metadata for the file to be uploaded. + var fileMetadata = new File() + { + Name = "Output.pptx", // Name of the file in Google Drive. + MimeType = "application/powerpoint", + }; + FilesResource.CreateMediaUpload request; + // Create a memory stream from the PowerPoint presentation. + using (var fs = new MemoryStream(stream.ToArray())) + { + // Create an upload request for Google Drive. + request = service.Files.Create(fileMetadata, fs, "application/powerpoint"); + // Upload the file. + request.Upload(); + } + //Dispose the memory stream. + stream.Dispose(); + pptxDocument.Close(); + } + } +} diff --git a/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Save-PowerPoint-document.csproj b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Save-PowerPoint-document.csproj new file mode 100644 index 00000000..f2dd8b57 --- /dev/null +++ b/Read-and-save-PowerPoint-presentation/Open-and-save-PowerPoint/Google-Drive/Save-PowerPoint-document/Save-PowerPoint-document/Save-PowerPoint-document.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Save_PowerPoint_document + enable + enable + + + + + + +