Skip to content

Commit fa8c09c

Browse files
committed
Added Powerpoint UG details
1 parent 159488c commit fa8c09c

5 files changed

Lines changed: 207 additions & 17 deletions

File tree

70.1 KB
Loading
33.4 KB
Loading
62 KB
Loading
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
---
2+
title: Create a PowerPoint Presentation in ASP.NET Core Web API | Syncfusion
3+
description: Create PowerPoint document in ASP.NET Core Web API applications using .NET PowerPoint library without Microsoft PowerPoint or interop dependencies.
4+
platform: document-processing
5+
control: PowerPoint
6+
documentation: UG
7+
---
8+
9+
# Create a PowerPoint file using ASP.NET Core Web API
10+
11+
Syncfusion<sup>&reg;</sup> PowerPoint is a [.NET PowerPoint library](https://www.syncfusion.com/document-processing/powerpoint-framework/net) used to create, read, edit and convert PowerPoint documents programmatically without **Microsoft PowerPoint** or interop dependencies. Using this library, you can **create PowerPoint document in ASP.NET Core Web API**.
12+
13+
## Steps to Create a PowerPoint file in ASP.NET Core Web API:
14+
15+
The below steps illustrate creating a simple PowerPoint Presentation in ASP.NET Core Web API.
16+
17+
Step 1: Create a new C# ASP.NET Core Web API project.
18+
19+
![Create ASP.NET Core Web API project in Visual Studio](ASP-NET-Core-WEB-API-images/ASP-NET-Core-Web-API-template.png)
20+
21+
Step 2: Install the [Syncfusion.Presentation.Net.Core](https://www.nuget.org/packages/Syncfusion.Presentation.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org).
22+
23+
![Install Syncfusion.Presentation.Net.Core NuGet Package](ASP-NET-Core-WEB-API-images/Nuget-Package-NET-Core.png)
24+
25+
N> Starting with v16.2.0.x, if you reference Syncfusion<sup>&reg;</sup> assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion<sup>&reg;</sup> license key in your application to use our components.
26+
27+
Step 3: Add a new API controller empty file in the project.
28+
29+
![Add empty API controller to the project](ASP-NET-Core-WEB-API-images/Empty-API-Controller.png)
30+
31+
Step 4: Include the following namespaces in the **ValuesController.cs** file.
32+
33+
{% tabs %}
34+
35+
{% highlight c# tabtitle="C#" %}
36+
37+
using Microsoft.AspNetCore.Mvc;
38+
using Syncfusion.Presentation;
39+
40+
{% endhighlight %}
41+
42+
{% endtabs %}
43+
44+
Step 5: Add a new action method CreatePresentation in **ValuesController.cs** and include the below code snippet to create an PowerPoint presentation and download it.
45+
46+
{% tabs %}
47+
48+
{% highlight c# tabtitle="C#" %}
49+
50+
[HttpGet]
51+
[Route("api/PowerPoint")]
52+
public IActionResult CreatePresentation()
53+
{
54+
try
55+
{
56+
var fileDownloadName = "Output.pptx";
57+
const string contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
58+
var stream = GeneratePresentation();
59+
stream.Position = 0;
60+
return File(stream, contentType, fileDownloadName);
61+
}
62+
catch (Exception ex)
63+
{
64+
return BadRequest("Error occurred while creating PowerPoint file: " + ex.Message);
65+
}
66+
}
67+
68+
{% endhighlight %}
69+
70+
{% endtabs %}
71+
72+
Step 6: Implement the `GeneratePresentation` method in `ValuesController.cs`.
73+
74+
{% tabs %}
75+
76+
{% highlight c# tabtitle="C#" %}
77+
78+
public static MemoryStream GeneratePresentation()
79+
{
80+
// Create a new instance of PowerPoint Presentation file
81+
IPresentation pptxDoc = Presentation.Create();
82+
// Add a new slide to file and apply background color
83+
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly);
84+
// Specify the fill type and fill color for the slide background
85+
slide.Background.Fill.FillType = FillType.Solid;
86+
slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229);
87+
// Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide
88+
IShape titleShape = slide.Shapes[0] as IShape;
89+
titleShape.TextBody.AddParagraph("Company History").HorizontalAlignment = HorizontalAlignmentType.Center;
90+
// Add description content to the slide by adding a new TextBox IShape
91+
IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70);
92+
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.";
93+
// Add bullet points to the slide
94+
IShape bulletPointsShape = slide.AddTextBox(53.22, 270, 437.90, 116.32);
95+
// Add a paragraph for a bullet point
96+
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.");
97+
// Format how the bullets should be displayed
98+
firstPara.ListFormat.Type = ListType.Bulleted;
99+
firstPara.LeftIndent = 35;
100+
firstPara.FirstLineIndent = -35;
101+
// Add another paragraph for the next bullet point
102+
IParagraph secondPara = bulletPointsShape.TextBody.AddParagraph("The company is participating in top open source projects in automation industry.");
103+
// Format how the bullets should be displayed
104+
secondPara.ListFormat.Type = ListType.Bulleted;
105+
secondPara.LeftIndent = 35;
106+
secondPara.FirstLineIndent = -35;
107+
// Add an auto-shape to the slide
108+
IShape stampShape = slide.Shapes.AddShape(AutoShapeType.Explosion1, 48.93, 430.71, 104.13, 80.54);
109+
// Format the auto-shape color by setting the fill type and text
110+
stampShape.Fill.FillType = FillType.None;
111+
stampShape.TextBody.AddParagraph("IMN").HorizontalAlignment = HorizontalAlignmentType.Center;
112+
// Save the PowerPoint Presentation as stream
113+
MemoryStream stream = new MemoryStream();
114+
pptxDoc.Save(stream);
115+
pptxDoc.Close();
116+
stream.Position = 0;
117+
return stream;
118+
}
119+
120+
{% endhighlight %}
121+
122+
{% endtabs %}
123+
124+
Step 7: Build the project.
125+
126+
Click on Build → Build Solution or press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build the project.
127+
128+
Step 8: Run the project.
129+
130+
Click the Start button (green arrow) or press <kbd>F5</kbd> to run the app.
131+
132+
A complete working sample is available on [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Getting-Started/ASP.NET-Core-Web-API/Create-Word-Document).
133+
134+
## Steps for accessing the Web API using HTTP requests
135+
136+
Step 1: Create a console application.
137+
![Create a Console application in Visual Studio](ASP-NET-Core-WEB-API-images/Console-Template-Net-Core.png)
138+
139+
N> Ensure your ASP.NET Core Web API is running on the specified port before running this client. Adjust the port number if your Web API runs on a different port (check the ASP.NET Core app's launch settings).
140+
141+
Step 2: Add the below code snippet in the **Program.cs** file for accessing the Web API using HTTP requests.
142+
143+
This method sends a GET request to the Web API endpoint to retrieve and save the generated Word document.
144+
145+
{% tabs %}
146+
147+
{% highlight c# tabtitle="C#" %}
148+
149+
// Create an HttpClient instance
150+
using (HttpClient client = new HttpClient())
151+
{
152+
try
153+
{
154+
// Send a GET request to a URL
155+
HttpResponseMessage response = await client.GetAsync("https://localhost:7073/api/Values/api/PowerPoint");
156+
157+
// Check if the response is successful
158+
if (response.IsSuccessStatusCode)
159+
{
160+
// Read the content as a string
161+
Stream responseBody = await response.Content.ReadAsStreamAsync();
162+
FileStream fileStream = File.Create("../../../Output/Output.pptx");
163+
responseBody.CopyTo(fileStream);
164+
fileStream.Close();
165+
}
166+
else
167+
{
168+
Console.WriteLine("HTTP error status code: " + response.StatusCode);
169+
}
170+
}
171+
catch (HttpRequestException e)
172+
{
173+
Console.WriteLine("Request exception: " + e.Message);
174+
}
175+
}
176+
177+
{% endhighlight %}
178+
179+
{% endtabs %}
180+
181+
Step 3: Build the project.
182+
183+
Click on Build → Build Solution or press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build the project.
184+
185+
Step 4: Run the project.
186+
187+
Click the Start button (green arrow) or press <kbd>F5</kbd> to run the app.
188+
189+
A complete working sample is available on [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Getting-Started/ASP.NET-Core-Web-API/Client%20Application).
190+
191+
Upon executing the program, the **PowerPoint Presentation** will be generated as follows.
192+
193+
![ASP .NET Core WEB API output Word document](ASP-NET-Core-WEB-API-images/ASP-NET-Core-Web-API-Output.png)
194+
195+
Click [here](https://www.syncfusion.com/document-processing/word-framework/net) to explore the rich set of Syncfusion<sup>&reg;</sup> Word library (DocIO) features.
196+
197+
An online sample link to [create a Word document](https://document.syncfusion.com/demos/word/helloworld#/tailwind) in ASP.NET Core.

Document-Processing/Word/Word-Library/NET/Create-Word-Document-in-ASP-NET-Core-WEB-API.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@ Step 1: Create a new C# ASP.NET Core Web API project.
1818

1919
![Create ASP.NET Core Web API project in Visual Studio](ASP-NET-Core-WEB-API-images/ASP-NET-Core-Web-API-template.png)
2020

21-
Step 2: Add a name for the project.
22-
23-
![Name the project](ASP-NET-Core-WEB-API-images/ASP-NET-Core-Web-API-Project-name.png)
24-
25-
Step 3: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org).
21+
Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org).
2622

2723
![Install Syncfusion.DocIO.Net.Core NuGet Package](ASP-NET-Core-WEB-API-images/Nuget-Package-NET-Core.png)
2824

2925
N> Starting with v16.2.0.x, if you reference Syncfusion<sup>&reg;</sup> assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion<sup>&reg;</sup> license key in your application to use our components.
3026

31-
Step 4: Add a new API controller empty file in the project.
27+
Step 3: Add a new API controller empty file in the project.
3228

3329
![Add empty API controller to the project](ASP-NET-Core-WEB-API-images/Empty-API-Controller.png)
3430

35-
Step 5: Include the following namespaces in the **ValuesController.cs** file.
31+
Step 4: Include the following namespaces in the **ValuesController.cs** file.
3632

3733
{% tabs %}
3834

@@ -46,7 +42,7 @@ using Syncfusion.DocIO.DLS;
4642

4743
{% endtabs %}
4844

49-
Step 6: Add a new action method CreateDocument in **ValuesController.cs** and include the below code snippet to create an Word file and download it.
45+
Step 5: Add a new action method CreateDocument in **ValuesController.cs** and include the below code snippet to create an Word file and download it.
5046

5147
{% tabs %}
5248

@@ -75,7 +71,7 @@ Step 6: Add a new action method CreateDocument in **ValuesController.cs** and in
7571

7672
{% endtabs %}
7773

78-
Step 7: Implement the `GenerateWordDocument` method in `ValuesController.cs`.
74+
Step 6: Implement the `GenerateWordDocument` method in `ValuesController.cs`.
7975

8076
{% tabs %}
8177

@@ -154,11 +150,11 @@ Step 7: Implement the `GenerateWordDocument` method in `ValuesController.cs`.
154150

155151
{% endtabs %}
156152

157-
Step 8: Build the project.
153+
Step 7: Build the project.
158154

159155
Click on Build → Build Solution or press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build the project.
160156

161-
Step 9: Run the project.
157+
Step 8: Run the project.
162158

163159
Click the Start button (green arrow) or press <kbd>F5</kbd> to run the app.
164160

@@ -169,12 +165,9 @@ A complete working sample is available on [GitHub](https://github.com/Syncfusion
169165
Step 1: Create a console application.
170166
![Create a Console application in Visual Studio](ASP-NET-Core-WEB-API-images/Console-Template-Net-Core.png)
171167

172-
Step 2: Add a name for the application.
173-
![Name the project](ASP-NET-Core-WEB-API-images/Client-Application-Project-Name.png)
174-
175168
N> Ensure your ASP.NET Core Web API is running on the specified port before running this client. Adjust the port number if your Web API runs on a different port (check the ASP.NET Core app's launch settings).
176169

177-
Step 3: Add the below code snippet in the **Program.cs** file for accessing the Web API using HTTP requests.
170+
Step 2: Add the below code snippet in the **Program.cs** file for accessing the Web API using HTTP requests.
178171

179172
This method sends a GET request to the Web API endpoint to retrieve and save the generated Word document.
180173

@@ -213,11 +206,11 @@ This method sends a GET request to the Web API endpoint to retrieve and save the
213206

214207
{% endtabs %}
215208

216-
Step 4: Build the project.
209+
Step 3: Build the project.
217210

218211
Click on Build → Build Solution or press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> to build the project.
219212

220-
Step 5: Run the project.
213+
Step 4: Run the project.
221214

222215
Click the Start button (green arrow) or press <kbd>F5</kbd> to run the app.
223216

0 commit comments

Comments
 (0)