SelectPdf for .NET 10 - Convert Pdf to PowerPoint - C# / .NET 10 Sample

This sample shows how to use the SelectPdf pdf to PowerPoint converter to convert a pdf document to a PowerPoint presentation. Every page becomes a slide: its text in editable text boxes, its tables as PowerPoint tables and its images and vector art as pictures, each where the page has it. The conversion runs in-process; no engine is launched.

The sample converts the following pdf, which Microsoft PowerPoint saved from the PowerPoint to Pdf sample's presentation, or a pdf you upload:
Test pdf document

Pdf document (optional):

Pages (empty for all, e.g. 1,3-5):


Tables as PowerPoint tables
Images and vector art
Page headers and footers
Links

Sample code · C#
using System;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SelectPdf.Universal;

namespace SelectPdf.Samples.Pages
{
    public class PdfToPowerPointModel : PageModel
    {
        public void OnGet()
        {
            TxtPageRanges = "";
            ChkTables = true;
            ChkImages = true;
            ChkHeadersAndFooters = true;
            ChkLinks = true;
        }

        // An uploaded pdf, or nothing - the shipped files/presentation.pdf is converted then.
        [BindProperty]
        public IFormFile FilePdf { get; set; }

        [BindProperty]
        public string TxtPageRanges { get; set; }

        [BindProperty]
        public bool ChkTables { get; set; }

        [BindProperty]
        public bool ChkImages { get; set; }

        [BindProperty]
        public bool ChkHeadersAndFooters { get; set; }

        [BindProperty]
        public bool ChkLinks { get; set; }

        public IActionResult OnPost()
        {
            // instantiate a pdf to powerpoint converter object
            PdfToPowerPoint converter = new PdfToPowerPoint();

            // set converter options: the pages converted, a slide each (empty for all), tables as
            // PowerPoint tables, the pictures, the page headers and footers and the links
            converter.Options.PageRanges = TxtPageRanges ?? string.Empty;
            converter.Options.Tables = ChkTables;
            converter.Options.Images = ChkImages;
            converter.Options.HeadersAndFooters = ChkHeadersAndFooters;
            converter.Options.Links = ChkLinks;

            // convert the uploaded pdf, or the sample one shipped with the application
            byte[] presentation;
            if (FilePdf != null && FilePdf.Length > 0)
            {
                using (Stream uploaded = FilePdf.OpenReadStream())
                {
                    presentation = converter.ConvertStream(uploaded);
                }
            }
            else
            {
                string pdfFile = Path.Combine(Startup.ServerPath, "wwwroot", "files", "presentation.pdf");
                presentation = converter.ConvertFile(pdfFile);
            }

            // return the converted presentation
            FileResult fileResult = new FileContentResult(presentation,
                "application/vnd.openxmlformats-officedocument.presentationml.presentation");
            fileResult.FileDownloadName = "Presentation.pptx";
            return fileResult;
        }
    }
}