This simple how-to-topic is about how to convert PDF to Presentation using C# by following the detailed configuration steps to verify the working sample code. You can import PDF in PowerPoint using C# by following a very simple API interface and application can be used inside any of .NET supported environment including Windows, macOS and Linux.
Steps to Import PDF in PowerPoint using C#
- Configure your application project to install Aspose.Slides for .NET using the NuGet package manager
- Create an empty presentation using the Presentation class object to convert PDF to presentation
- Load the PDF from the disk and add to presentation slides collection using AddFromPdf method
- Using the Save method, convert PDF to PowerPoint using C#
By following the stated steps in C# PDF to Presentation converter application is developed where the process commences by creating an empty presentation using an instance of Presentation class. Then, by using AddFromPdf method which is exposed by SlideCollection class, add the PDF in slides by setting source PDF file path. Finally, the Save method will convert PDF to PPTX and save it on the disk.
Code to Convert PDF to Presentation using C#
using System; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace TestSlides | |
{ | |
public class PdfToPresentation | |
{ | |
public static void PdfToPresentationConverter() | |
{ | |
// Initialize a license to convert PPT to PDF | |
Aspose.Slides.License licensePresExport = new Aspose.Slides.License(); | |
licensePresExport.SetLicense("Aspose.Total.lic"); | |
// Create an empty Presentation class object to create the presentation | |
using (Presentation pres = new Presentation()) | |
{ | |
// Import the PDF file from the disk to slides collection | |
pres.Slides.AddFromPdf("SourcePDF.pdf"); | |
// Save the PPTX presentation on the disk | |
pres.Save("ImportedPdfPresentation.pptx", SaveFormat.Pptx); | |
} | |
} | |
} | |
} |
The above example is also useful to convert PDF to PPT using C# where you will have to choose different SaveFormat enumerator inside the Save method. The AddFromPdf method also provide the overload to load the PDF from memory stream as well and for every page inside the PDF, a new slide will be created inside the presentation. The API allows you to add multiple PDF files inside the presentation slides collection.
In this tutorial, we learnt that in order to add PDF to Presentation C# based API can be used without any dependency on MS PowerPoint. If you are interested in converting the presentation to PDF, refer to the article on how to convert PPT to PDF using C#.