-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from SyncfusionExamples/PPT-Google
Add samples for opening and saving PowerPoint document in Google cloud storage
- Loading branch information
Showing
161 changed files
with
149,829 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ave-PowerPoint/Google-Cloud-Storage/Open-PowerPoint-document/Open-PowerPoint-document.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.10.34928.147 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open-PowerPoint-document", "Open-PowerPoint-document\Open-PowerPoint-document.csproj", "{32919A84-EEB2-44C9-90B0-6DE05C353817}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{32919A84-EEB2-44C9-90B0-6DE05C353817}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{32919A84-EEB2-44C9-90B0-6DE05C353817}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{32919A84-EEB2-44C9-90B0-6DE05C353817}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{32919A84-EEB2-44C9-90B0-6DE05C353817}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2F668BAA-6807-4025-AD13-15BD76F34901} | ||
EndGlobalSection | ||
EndGlobal |
99 changes: 99 additions & 0 deletions
99
...d-Storage/Open-PowerPoint-document/Open-PowerPoint-document/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Google.Apis.Auth.OAuth2; | ||
using Google.Cloud.Storage.V1; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Open_PowerPoint_document.Models; | ||
using Syncfusion.Presentation; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace Open_PowerPoint_document.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly ILogger<HomeController> _logger; | ||
|
||
public HomeController(ILogger<HomeController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
public async Task<IActionResult> EditDocument() | ||
{ | ||
//Download the file from Google | ||
MemoryStream memoryStream = await GetDocumentFromGoogle(); | ||
|
||
//Create an instance of PowerPoint Presentation file | ||
using (IPresentation pptxDocument = Presentation.Open(memoryStream)) | ||
{ | ||
//Get the first slide from the PowerPoint presentation | ||
ISlide slide = pptxDocument.Slides[0]; | ||
|
||
//Get the first shape of the slide | ||
IShape shape = slide.Shapes[0] as IShape; | ||
|
||
//Change the text of the shape | ||
if (shape.TextBody.Text == "Company History") | ||
shape.TextBody.Text = "Company Profile"; | ||
|
||
//Saving the PowerPoint to a MemoryStream | ||
MemoryStream outputStream = new MemoryStream(); | ||
pptxDocument.Save(outputStream); | ||
|
||
//Download the PowerPoint file in the browser | ||
FileStreamResult fileStreamResult = new FileStreamResult(outputStream, "application/powerpoint"); | ||
fileStreamResult.FileDownloadName = "EditPowerPoint.pptx"; | ||
return fileStreamResult; | ||
} | ||
} | ||
/// <summary> | ||
/// Download file from Google | ||
/// </summary> | ||
/// <returns></returns> | ||
public async Task<MemoryStream> GetDocumentFromGoogle() | ||
{ | ||
try | ||
{ | ||
//Your bucket name | ||
string bucketName = "Your_bucket_name"; | ||
|
||
//Your service account key file path | ||
string keyPath = "credentials.json"; | ||
|
||
//Name of the file to download from the Google Cloud Storage | ||
string fileName = "PowerPointTemplate.pptx"; | ||
|
||
//Create Google Credential from the service account key file | ||
GoogleCredential credential = GoogleCredential.FromFile(keyPath); | ||
|
||
//Instantiates a storage client to interact with Google Cloud Storage | ||
StorageClient storageClient = StorageClient.Create(credential); | ||
|
||
//Download a file from Google Cloud Storage | ||
MemoryStream memoryStream = new MemoryStream(); | ||
await storageClient.DownloadObjectAsync(bucketName, fileName, memoryStream); | ||
memoryStream.Position = 0; | ||
|
||
return memoryStream; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error retrieving document from Google Cloud Storage: {ex.Message}"); | ||
throw; // or handle the exception as needed | ||
} | ||
} | ||
public IActionResult Privacy() | ||
{ | ||
return View(); | ||
} | ||
|
||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...-Cloud-Storage/Open-PowerPoint-document/Open-PowerPoint-document/Models/ErrorViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Open_PowerPoint_document.Models | ||
{ | ||
public class ErrorViewModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} | ||
} |
Oops, something went wrong.