Create PowerPoint (PPTX) or PDF file in ASP.NET Core

GemBox.Presentation provides support for .NET Standard 2.0 which is why it can be used on various .NET platforms such as .NET Framework, .NET Core, Xamarin, and Universal Windows Platform (UWP).

Save to PowerPoint or PDF in .NET Core

To create a PowerPoint presentation or PDF file with an application that targets .NET Core 2.0 or above on Linux, macOS, or Windows using GemBox.Presentation, simply add the following package references in the project file.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="GemBox.Presentation" Version="*" />
    <PackageReference Include="System.Drawing.Common" Version="*" />
  </ItemGroup>

</Project>

GemBox.Presentation is ideal for web applications (like ASP.NET Core, ASP.NET MVC, and ASP.NET Web Forms) because of its fast performance and thread safety when working with multiple PresentationDocument objects.

The following example shows how you can create an ASP.NET Core application that generates a simple presentation of a specified format and downloads it to the client's browser.

Generated PPTX file from template PowerPoint presentation in ASP.NET Core demo application
Screenshot of created PowerPoint file of PPTX format in ASP.NET Core
<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Create PowerPoint file from ASP.NET Core</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <style>
        html { font-size: 14px; position: relative; min-height: 100%; }
        @@media (min-width: 768px) { html { font-size: 16px; } }
        body { margin-bottom: 60px; }
        a { color: #0366d6; }
        a.navbar-brand { white-space: normal; text-align: center; word-break: break-all; }
        .btn-primary { color: #fff; background-color: #1b6ec2; border-color: #1861ac; }
        .nav-pills .nav-link.active, .nav-pills .show > .nav-link { color: #fff; background-color: #1b6ec2; border-color: #1861ac; }
        .border-top { border-top: 1px solid #e5e5e5; }
        .border-bottom { border-bottom: 1px solid #e5e5e5; }
        .box-shadow { box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); }
        .footer { position: absolute; bottom: 0; width: 100%; white-space: nowrap; line-height: 60px; }
    </style>
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div class="container">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
                    <ul class="navbar-nav flex-grow-1">
                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <main role="main" class="text-center">
        <div class="container">
            <h1 class="display-4 mb-4">Presentation generator in ASP.NET Core</h1>
            <form class="mx-auto" style="max-width:12em" method="post">
                <div class="text-left">
                    <h4>Output format:</h4>
                    <div class="form-check">
                        <input id="PDF" name="format" type="radio" class="form-check-input" value="PDF" />
                        <label for="PDF" class="form-check-label">PDF</label>
                    </div>
                    <div class="form-check">
                        <input id="PPTX" name="format" type="radio" class="form-check-input" checked value="PPTX" />
                        <label for="PPTX" class="form-check-label">PPTX</label>
                    </div>
                    <fieldset disabled>
                        <div class="form-check">
                            <input id="XPS" name="format" type="radio" class="form-check-input" value="XPS" />
                            <label for="XPS" class="form-check-label">XPS</label>
                        </div>
                        <div class="form-check">
                            <input id="PNG" name="format" type="radio" class="form-check-input" value="PNG" />
                            <label for="PNG" class="form-check-label">PNG</label>
                        </div>
                        <div class="form-check">
                            <input id="JPG" name="format" type="radio" class="form-check-input" value="JPG" />
                            <label for="JPG" class="form-check-label">JPG</label>
                        </div>
                        <div class="form-check">
                            <input id="GIF" name="format" type="radio" class="form-check-input" value="GIF" />
                            <label for="GIF" class="form-check-label">GIF</label>
                        </div>
                        <div class="form-check">
                            <input id="TIF" name="format" type="radio" class="form-check-input" value="TIF" />
                            <label for="TIF" class="form-check-label">TIF</label>
                        </div>
                        <div class="form-check">
                            <input id="BMP" name="format" type="radio" class="form-check-input" value="BMP" />
                            <label for="BMP" class="form-check-label">BMP</label>
                        </div>
                        <div class="form-check">
                            <input id="WMP" name="format" type="radio" class="form-check-input" value="WMP" />
                            <label for="WMP" class="form-check-label">WMP</label>
                        </div>
                    </fieldset>
                </div>
                <hr />
                <button class="btn btn-primary btn-block" asp-controller="Home" asp-action="Download">Download</button>
            </form>
        </div>
    </main>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; GemBox d.o.o. — All rights reserved.
        </div>
    </footer>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
using System;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using GemBox.Presentation;

namespace PresentationCore.Controllers
{
    public class HomeController : Controller
    {
        static HomeController()
        {
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
        }

        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public IActionResult Download(string format)
        {
            // Create new presentation.
            var presentation = new PresentationDocument();

            // Add slide.
            var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

            // Add textbox.
            var textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 2, 2, 5, 4, LengthUnit.Centimeter);

            // Add paragraph.
            var paragraph = textBox.AddParagraph();

            // Add text.
            paragraph.AddRun("Hello World!");

            using (var stream = new MemoryStream())
            {
                // Save presentation to stream in specified format.
                SaveOptions options = GetSaveOptions(format);
                presentation.Save(stream, options);

                // Download presentation to client's browser.
                return File(stream.ToArray(), options.ContentType, "Hello World." + format.ToLower());
            }
        }

        private static SaveOptions GetSaveOptions(string format)
        {
            switch (format.ToUpper())
            {
                case "PPTX":
                    return SaveOptions.Pptx;
                case "PDF":
                    return SaveOptions.Pdf;

                case "XPS":
                case "PNG":
                case "JPG":
                case "GIF":
                case "TIF":
                case "BMP":
                case "WMP":
                    throw new InvalidOperationException("To enable saving to XPS or image format, add 'Microsoft.WindowsDesktop.App' framework reference.");

                default:
                    throw new NotSupportedException();
            }
        }
    }
}

GemBox.Presentation is only licensed per developer and the licenses include a royalty-free deployment. There are no server or OEM licenses, there are no additional costs for anything (like building, testing and deploying).

So, you're free to build an unlimited number of applications and deploy or distribute them to an unlimited number of servers or end user machines with no extra cost.

Print and Save to XPS or image in .NET Core

The .NET Standard version of GemBox.Spreadsheet has the full functionality of the .NET Framework version, but with a few rendering limitations:

However, GemBox.Presentation provides a version for .NET Core 3.0 that has no rendering limitations. This version includes support for printing and saving to XPS or image formats, when used in a .NET Core 3.0 or above application running on Windows.

But when used on a non-Windows platform then the same .NET Standard limitations are applied. For more information see the Linux / macOS example.

To create an XPS or image file from ASP.NET Core 3.0 web application using GemBox.Presentation, you'll need to add Microsoft.WindowsDesktop.App framework reference in the project file as shown below.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="GemBox.Presentation" Version="*" />
  </ItemGroup>

</Project>

To create an XPS or image file from .NET Core 3.0 desktop application using GemBox.Presentation, you'll need to use Microsoft.NET.Sdk.WindowsDesktop SDK and add UseWPF property in the project file as shown below.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="GemBox.Presentation" Version="*" />
  </ItemGroup>

</Project>

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Presentation yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.