Open and save Presentation in .NET MAUI
13 Jun 20245 minutes to read
Syncfusion PowerPoint is a .NET MAUI PowerPoint library used to create, read, edit and convert PowerPoint documents programmatically without Microsoft PowerPoint or interop dependencies. Using this library, you can open and save a Presentation in .NET MAUI.
Prerequisites
To create .NET Multi-platform App UI (.NET MAUI) apps, you need the latest versions of Visual Studio 2022 and .NET 6. For more details, refer here.
Steps to open and save PowerPoint Presentation programmatically
Step 1: Create a new C# .NET MAUI app. Select .NET MAUI App (Preview) from the template and click the Next button.
Step 2: Enter the project name and click Create.
Step 3: Install the Syncfusion.Presentation.NET NuGet package as a reference to your project from NuGet.org.
NOTE
Starting with v16.2.0.x, if you reference Syncfusion 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 to know about registering Syncfusion license key in your application to use our components.
Step 4: Add a new button to the MainPage.xaml as shown below.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ReadPowerPoint.MainPage"
BackgroundColor="{DynamicResource SecondaryColor}">
<ScrollView>
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*"
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
<Button
Text="Open and Save Presentation"
FontAttributes="Bold"
Grid.Row="0"
SemanticProperties.Hint="Open and Save Presentation"
Clicked="OpenAndSavePresentation"
HorizontalOptions="Center" />
</Grid>
</ScrollView>
</ContentPage>
Step 5: Include the following namespaces in the MainPage.xaml.cs file.
using Syncfusion.Presentation;
Step 6: Add a new action method OpenAndSavePresentation in MainPage.xaml.cs and include the below code snippet to open an existing PowerPoint Presentation in .NET MAUI.
Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
//Opens an existing PowerPoint presentation.
using IPresentation pptxDoc = Presentation.Open(assembly.GetManifestResourceStream("ReadAndEditPowerPoint.Resources.Presentation.Sample.pptx"));
Step 7: Add below code snippet demonstrates accessing a shape from a slide and changing the text within it.
//Gets the first slide from the PowerPoint presentation.
ISlide slide = pptxDoc.Slides[0];
//Gets the first shape of the slide.
Syncfusion.Presentation.IShape shape = slide.Shapes[0] as Syncfusion.Presentation.IShape;
//Modifies the text of the shape.
if (shape.TextBody.Text == "Company History")
shape.TextBody.Text = "Company Profile";
Step 8: Add below code example to save the PowerPoint Presentation in .NET MAUI.
//Saves the presentation to the memory stream.
using MemoryStream stream = new();
pptxDoc.Save(stream);
stream.Position = 0;
//Saves the memory stream as file.
SaveService saveService = new();
saveService.SaveAndView("Output.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream);
You can download a complete working sample from GitHub.
By executing the program, you will get the PowerPoint document as follows.
Helper files for .NET MAUI
Refer the below helper files 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.
Folder Name | File Name | Summary |
Represent the base class for save operation. | ||
Save implementation for Windows. | ||
Save implementation for Android device. | ||
Save implementation for Mac Catalyst device. | ||
Save implementation for iOS device | ||
|
Helper classes for viewing the PowerPoint Presenatation in iOS device |
Click here to explore the rich set of Syncfusion PowerPoint Library (Presentation) features.