PPT to PDF Conversion in C# Is Not Working in .NET 8 Runtime Docker Image

We are using “Aspose.Total.NET.lic”. We are trying to do ppt to pdf conversion using Aspose.Slides, it is throwing “PlatformNotSupportedException” exception in dotnet 8 runtime docker image mcr.microsoft.com/dotnet/aspnet:8.0, which is linux based image :

**System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.**
2024-10-22T08:03:40.691810834Z          at System.Drawing.StringFormat.get_GenericTypographic()
2024-10-22T08:03:40.691815834Z          at ..ctor(Bitmap , Boolean )
2024-10-22T08:03:40.691821334Z          at ..ctor(Bitmap )
2024-10-22T08:03:40.691826134Z          at ..ctor(Int32 , Int32 , Single , Single , Boolean ,  ,  , List`1 )
2024-10-22T08:03:40.691831735Z          at Aspose.Slides.Slide.(Boolean ,  ,  , List`1 , InterruptionToken )
2024-10-22T08:03:40.691837135Z          at .(Presentation , Stream , Int32[] , PdfOptions , InterruptionToken )
2024-10-22T08:03:40.691842235Z          at .(Presentation , Stream , PdfOptions , InterruptionToken )
2024-10-22T08:03:40.691847235Z          at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format, ISaveOptions options)
2024-10-22T08:03:40.691864636Z          at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format)
2024-10-22T08:03:40.691870036Z          at KPMG.DocProcessor.PowerPoint.PowerPointProcessorAsposeImpl.ConvertToPDF(Stream docStream) in /App/DocProcessor/src/PowerPoint/PowerPointProcessorAsposeImpl.cs:line 14
2024-10-22T08:03:40.691876237Z          at KPMG.DocProcessor.PowerPoint.PowerPointController.ConvertToPDF(IFormFile file) in /App/DocProcessor/src/PowerPoint/PowerPointController.cs:line 33
2024-10-22T08:03:40.691881137Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
2024-10-22T08:03:40.691886237Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
2024-10-22T08:03:40.691891337Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-10-22T08:03:40.691898638Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
2024-10-22T08:03:40.691903538Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-10-22T08:03:40.691908838Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-10-22T08:03:40.691913838Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-10-22T08:03:40.691918839Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
2024-10-22T08:03:40.691923539Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-10-22T08:03:40.691928539Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-10-22T08:03:40.691933539Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2024-10-22T08:03:40.691938439Z          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2024-10-22T08:03:40.691943640Z          at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
2024-10-22T08:03:40.691948440Z          at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2024-10-22T08:03:40.691958040Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

It is working fine in windows 10.

@dsom

The issue you are encountering with the PlatformNotSupportedException when trying to convert PPT to PDF using Aspose.Slides in a .NET 8 runtime Docker image is due to the fact that the System.Drawing.Common library, which Aspose.Slides relies on for certain graphics operations, is not supported on non-Windows platforms starting from .NET 6.

To resolve this issue, you should ensure that you are using the cross-platform version of Aspose.Slides. This version has been designed to work on Linux and macOS environments without relying on System.Drawing.Common. Here are the steps you can follow:

  1. Download the Cross-Platform Version: Obtain the cross-platform version of Aspose.Slides from the official release page. Make sure to download the appropriate ZIP package that contains the Aspose.Slides.dll for cross-platform use.

  2. Add References: Unpack the files and add a reference to Aspose.Slides.dll in your project. Ensure that all dependent libraries are also included in your output directory.

  3. Update Your Code: If you are using any types from System.Drawing.Common, you may need to adjust your code to use the types provided by the Aspose.Slides library instead, as it includes its own implementation for graphics operations.

  4. Check System Requirements: Ensure that your Linux environment meets the system requirements for running Aspose.Slides, specifically that it is using a compatible version of GLIBC (2.23 or higher).

By following these steps, you should be able to perform PPT to PDF conversions successfully in your Docker environment without encountering the PlatformNotSupportedException.

For more detailed guidance, you can refer to the official Aspose documentation on cross-platform support and installation instructions.

Sources:
[1]: Aspose.Slides for .NET 6 Cross Platform - Aspose Documentation
[2]: Installation|Aspose.Slides Documentation

We are using below basic code for ppt to pdf conversion:

using Presentation = Aspose.Slides.Presentation;
using SaveFormat = Aspose.Slides.Export.SaveFormat;

namespace DocProcessor.PowerPoint;

public class PowerPointProcessorAsposeImpl : PowerPointProcessor
{
    public Stream ConvertToPDF(Stream docStream)
    {
        using (Presentation presentation = new Presentation(docStream))
        {
            // Save the presentation as a PDF
            var outputStream = new MemoryStream();
            presentation.Save(outputStream, SaveFormat.Pdf);
            outputStream.Position = 0;
            return outputStream;
        }
    }
}

@dsom,
The error occurs because the version of Aspose.Slides you are using is not designed for use on non-Windows systems. Please note the following:

More details:
System Requirements|Aspose.Slides Documentation
Aspose.Slides for .NET 6 Cross Platform|Aspose.Slides Documentation

Ok, following the steps mentioned in this article worked.

Had to install “ttf-mscorefonts” as well otherwise the fonts were breaking.

Thanks!

@dsom,
We are glad that the issue has been resolved on your end. Thank you for using Aspose.Slides.