Skip to content

Commit 263576b

Browse files
Merge pull request #127 from Karan-SF4772/master
989136 - Added Samples for Web API
2 parents 78b0b7d + eeb218c commit 263576b

File tree

46 files changed

+883
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+883
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client-Application", "Client-Application\Client-Application.csproj", "{CEB613E9-EA89-4348-AF24-3B26204D4A0F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CEB613E9-EA89-4348-AF24-3B26204D4A0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CEB613E9-EA89-4348-AF24-3B26204D4A0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CEB613E9-EA89-4348-AF24-3B26204D4A0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CEB613E9-EA89-4348-AF24-3B26204D4A0F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {9CA826F8-E557-46BD-AA73-48BD1D2542BD}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Client_Application</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Program
2+
{
3+
static async Task Main(string[] args)
4+
{
5+
// Create an HttpClient instance
6+
using (HttpClient client = new HttpClient())
7+
{
8+
try
9+
{
10+
// Send a GET request to a URL
11+
HttpResponseMessage response = await client.GetAsync("https://localhost:7260/api/Values/api/PPTXToImage");
12+
13+
// Check if the response is successful
14+
if (response.IsSuccessStatusCode)
15+
{
16+
// Read the content as a string
17+
Stream responseBody = await response.Content.ReadAsStreamAsync();
18+
FileStream fileStream = File.Create("../../../Output/Output.jpeg");
19+
responseBody.CopyTo(fileStream);
20+
fileStream.Close();
21+
}
22+
else
23+
{
24+
Console.WriteLine("HTTP error status code: " + response.StatusCode);
25+
}
26+
}
27+
catch (HttpRequestException e)
28+
{
29+
Console.WriteLine("Request exception: " + e.Message);
30+
}
31+
}
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-PowerPoint-Presentation-to-Image", "Convert-PowerPoint-Presentation-to-Image\Convert-PowerPoint-Presentation-to-Image.csproj", "{521B7DC4-9E4F-438C-A155-2F2AE56FFC13}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{521B7DC4-9E4F-438C-A155-2F2AE56FFC13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{521B7DC4-9E4F-438C-A155-2F2AE56FFC13}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{521B7DC4-9E4F-438C-A155-2F2AE56FFC13}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{521B7DC4-9E4F-438C-A155-2F2AE56FFC13}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {34CE10AF-EDB8-4A1D-9DB5-19A71EE82CE9}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.Presentation;
4+
using Syncfusion.PresentationRenderer;
5+
using System.IO;
6+
using static System.Runtime.InteropServices.JavaScript.JSType;
7+
8+
9+
namespace Convert_PowerPoint_Presentation_to_Image.Controllers
10+
{
11+
[Route("api/[controller]")]
12+
[ApiController]
13+
public class ValuesController : ControllerBase
14+
{
15+
[HttpGet]
16+
[Route("api/PPTXToImage")]
17+
public IActionResult ConvertPPTXToImage()
18+
{
19+
try
20+
{
21+
var fileDownloadName = "Output.jpeg";
22+
const string contentType = "image/jpeg";
23+
var stream = ConvertPresentationToImage();
24+
stream.Position = 0;
25+
return File(stream, contentType, fileDownloadName);
26+
}
27+
catch (Exception ex)
28+
{
29+
// Log or handle the exception
30+
return BadRequest("Error occurred while converting PowerPoint Presentation to Image: " + ex.Message);
31+
}
32+
}
33+
public static Stream ConvertPresentationToImage()
34+
{
35+
IPresentation pptxDoc = Presentation.Open("Data/Input.pptx");
36+
//Initialize the PresentationRenderer to perform image conversion.
37+
pptxDoc.PresentationRenderer = new PresentationRenderer();
38+
//Convert the first page of the Word document into an image.
39+
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
40+
//close the word document.
41+
pptxDoc.Close();
42+
//Reset the stream position.
43+
stream.Position = 0;
44+
//Save the image file.
45+
return stream;
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace Convert_PowerPoint_Presentation_to_Image.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>Convert_PowerPoint_Presentation_to_Image</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
12+
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@Convert_PowerPoint_Presentation_to_Image_HostAddress = http://localhost:5166
2+
3+
GET {{Convert_PowerPoint_Presentation_to_Image_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###

0 commit comments

Comments
 (0)