How to create a PowerPoint presentation file in Xamarin.Forms?
PowerPoint presentation is a file format that allows you to create and show a series of slides containing text, shapes, charts, images and SmartArt diagrams with rich set of formatting options to make your presentation more attractive and memorable.
Syncfusion Essential Presentation is a .NET PowerPoint library used to create, open, read, and edit PowerPoint presentations. Using this library, you can start creating a PowerPoint file in Xamarin.
Steps to create a PowerPoint presentation file:
- Create a new C# Xamarin.Forms application project.
- Select a project template and required platforms to deploy the application. In this application the portable assemblies to be shared across multiple platforms, the .NET Standard code sharing strategy has been selected. For more details about code sharing refer here.
Install Syncfusion.Xamarin.Presentation NuGet package as a reference to the .NET Standard project in your Xamarin applications from NuGet.org.
- Add new Forms XAML page in portable project If there is no XAML page is defined in the App class. Otherwise proceed to the next step.
- To add the new XAML page, right click on the project and select Add > New Item and add a Forms XAML Page from the list. Name it as MainXamlPage.
- In App class of portable project (App.cs), replace the existing constructor of App class with the code snippet given below which invokes the MainXamlPage.
public App() { // The root page of your application MainPage = new MainXamlPage(); }
- In the MainXamlPage.xaml add new button as shown below.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="GettingStarted. MainXamlPage"> <StackLayout VerticalOptions="Center"> <Button Text="Generate Document" Clicked="OnButtonClicked" HorizontalOptions="Center"/> </StackLayout> </ContentPage>
- Include the following namespace in the MainXamlPage.xaml.cs file.
using Syncfusion.Presentation;
- Include the below code snippet in the click event of the button in MainXamlPage.xaml.cs, to create an PowerPoint file and save it in a stream.
//Create a new PowerPoint presentation IPresentation powerpointDoc = Presentation.Create(); //Add a blank slide to the presentation ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); //Add a textbox to the slide IShape shape = slide.AddTextBox(10, 10, 500, 100); //Add a text to the textbox. shape.TextBody.AddParagraph("Hello World!!!"); //Save the PowerPoint to stream in pptx format. MemoryStream stream = new MemoryStream(); powerpointDoc.Save(stream); powerpointDoc.Close(); //Save the stream as a file in the device and invoke it for viewing Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("GettingStared.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
Download the helper files from this link and add them into the mentioned project. These helper files allow you to save the stream as a physical file and open the file for viewing.
Project | File Name | Summary |
Protable project | ISave.cs | Represent the base interface for save operation |
iOS Project | SaveIOS.cs | Save implementation for iOS device |
PreviewControllerDS.cs | Helper class for viewing the PowerPoint file in iOS device | |
Android project | SaveAndroid.cs | Save implementation for Android device |
UWP project | SaveWindows.cs | Save implementation for UWP device. |
- Compile and execute the application.
By executing the program, you will get the PowerPoint document as follows.
A complete working sample can be downloaded from Create-PowerPoint-file.zip.
Take a moment to peruse the documentation, where you can find other options to format the text with code examples.
Refer here to explore the rich set of Syncfusion Essential Presentation features.
See Also:
Create a PowerPoint file in ASP.NET MVC
Create a PowerPoint file in ASP.NET
Create a PowerPoint file in Windows Forms
Create a PowerPoint file in WPF
Note:
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to create a PowerPoint presentation file in Xamarin.Forms.
You can refer to our Presentation featuretour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Presentation example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
Syncfusion.Xamarin.Presentation NuGet package as a reference to the .NET Standard project in your Xamarin applications from NuGet.org.