Create PowerPoint (PPTX) or PDF in Docker container

GemBox.Presentation can be used inside docker containers that are running .NET Docker images.

To use Docker, you must first install Docker Desktop. After that, you can containerize your .NET application.

Visual Studio container tool for adding Docker to existing .NET Core project
Screenshot of Visual Studio container tool

The following is a project file for the .NET Core application with added Docker support.

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="GemBox.Presentation" Version="*" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="*" />
    <PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="*" />
  </ItemGroup>

</Project>

To configure or customize a Docker image, you'll need to edit the Dockerfile.

When creating PDF or image files, the font files must be present in the container. The official Linux images for .NET won't have any fonts installed. So, you'll need to copy the necessary font files to the Linux container, or install a font package like ttf-mscorefonts-installer, or add them as custom fonts.

The following example shows how to create PPTX and PDF files from Docker containers and configure Docker images with Dockerfile.

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["PresentationDocker.csproj", ""]
RUN dotnet restore "./PresentationDocker.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "PresentationDocker.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "PresentationDocker.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final

# Update package sources to include supplemental packages (contrib archive area).
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list.d/debian.sources

# Downloads the package lists from the repositories.
RUN apt-get update

# Install font configuration.
RUN apt-get install -y fontconfig

# Install Microsoft TrueType core fonts.
RUN apt-get install -y ttf-mscorefonts-installer

# Or install Liberation TrueType fonts.
# RUN apt-get install -y fonts-liberation

# Or some other font package...

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PresentationDocker.dll"]
using GemBox.Presentation;
using System.IO;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create new presentation.
        var presentation = new PresentationDocument();

        // Create new slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Blank);

        // Add sample text.
        var shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 120, 120, 250, 150);
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.Black));
        shape.Format.Fill.SetSolid(Color.FromHsl(0, 0, 240));

        var run = shape.Text.AddParagraph().AddRun("Lorem Ipsum");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Red));
        run.Format.Bold = true;

        run = shape.Text.AddParagraph().AddRun("Lorem Ipsum");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Green));
        run.Format.Italic = true;

        run = shape.Text.AddParagraph().AddRun("Lorem Ipsum");
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Blue));
        run.Format.UnderlineStyle = UnderlineStyle.Single;

        // Add sample image.
        using (var stream = File.OpenRead("%#Dices.png%"))
            slide.Content.AddPicture(PictureContentType.Png, stream, 480, 200, 240, 180);

        // Save presentation in PPTX and PDF format.
        presentation.Save("output.pptx");
        presentation.Save("output.pdf");
    }
}
Imports GemBox.Presentation
Imports System.IO

Module Program

    Sub Main()

        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' Create new presentation.
        Dim presentation As New PresentationDocument()

        ' Create new slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Blank)

        ' Add sample text.
        Dim shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 120, 120, 250, 150)
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.Black))
        shape.Format.Fill.SetSolid(Color.FromHsl(0, 0, 240))

        Dim run = shape.Text.AddParagraph().AddRun("Lorem Ipsum")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Red))
        run.Format.Bold = True

        run = shape.Text.AddParagraph().AddRun("Lorem Ipsum")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Green))
        run.Format.Italic = True

        run = shape.Text.AddParagraph().AddRun("Lorem Ipsum")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Blue))
        run.Format.UnderlineStyle = UnderlineStyle.Single

        ' Add sample image.
        Using stream = File.OpenRead("%#Dices.png%")
            slide.Content.AddPicture(PictureContentType.Png, stream, 480, 200, 240, 180)
        End Using

        ' Save presentation in PPTX and PDF format.
        presentation.Save("output.pptx")
        presentation.Save("output.pdf")
    End Sub
End Module
Generated PowerPoint presentation (PPTX format) and PDF file from Docker container
Screenshot of PowerPoint and PDF files created with Docker container

Using full functionality of GemBox.Presentation on a Linux host requires adjustments explained in detail on Supported Platforms help page.

See also


Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy