Converting PDF/PPT to image in .Net 7 on Linux - Getting error System.Drawing.Common is not supported on this platform

Hi

As part of a trial project I have, I’m trying to convert PDF, Word, Excel and PPT files into images using Aspose.

My project is based on ASP.NET core 7 and Linux (Amazon Linux 2).
When trying to convert WORD and Excel to image, it works as expected.

When trying to convert PDF and PPT, it doesn’t work.
I get this error:
System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.

We’re using code samples from your internet site.
We’re using Aspose.pdf version 23.9.0.

This is an example of our code:

    // Below "stream" is a MemoryStream to a file.
    var pdfDoc = new Aspose.Pdf.Document(stream);
    if (pdfDoc == null) return null;
    var pngImages = new List<byte[]>();
    var resolution = new Resolution(300);
    var renderer = new PngDevice(resolution);
    for (var p = 0; p < 3; p++)
    {
        var ms = new MemoryStream();
        renderer.Process(pdfDoc.Pages[p], ms);
        pngImages.Add(ms.ToArray());
    }
    return pngImages;

Can you help?
We need to successfully convert all the above file types before purchasing your Total license.
Thanks!

@orenco

To work on Linux, use the Aspose.Pdf.Drawing library. To do this, you only need to change the library (nuget package/dll links). If this doesn’t help, write about it here.

A post was split to a new topic: Converting PPT to image in .Net 7 on Linux - Getting error System.Drawing.Common is not supported on this platform

I’m using Aspose.PDF.Drawing 23.10.0
and running on my Amazon Linux 2 machine.
I’m using the above code but I fail with the following error:

Error converting page 1. Error: System.Exception: No suitable system fonts found
at #=zOhRMESFXb1kKtocOGVSjOLo$iajQ.#=zJxorysZoqAa2(#=zh2gh7BGs1_9elwbn0TGkyZ9nBs$2EWhgKA== #=zyc2rEi0=)
at #=zOhRMESFXb1kKtocOGVSjOLo$iajQ.#=zrP4Nwg0=(#=zJl6KqrvZft5fzdD8H6hlHNiPY6bEougXNIPU$FyzNRPH& #=ztjG86Q0=)
at #=zOhRMESFXb1kKtocOGVSjOLo$iajQ.#=zrP4Nwg0=()
at Aspose.Pdf.Devices.ImageDevice.#=zrP4Nwg0=(Page #=zPl$iB_c=)
at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)

I’ve installed the following libs in my machine:(using yum install):
harfbuzz-icu
fontconfig
freetype
dejavu-sans-fonts
dejavu-serif-fonts
libgdiplus

When I run “sudo fc-cache -f -v”
I get the following output:

/usr/share/fonts: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/dejavu: caching, new cache contents: 17 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts/dejavu: skipping, looped directory detected
/usr/lib/fontconfig/cache: cleaning cache directory
/root/.cache/fontconfig: not cleaning non-existent cache directory
/root/.fontconfig: not cleaning non-existent cache directory
/usr/bin/fc-cache-64: succeeded

Should I install more libs/fonts?
Should I add something in my .Net code?
Should I add a path in my code or in my csproj file, so that my .Net will know where to find the fonts?

@orenco
I apologize for the delay in response.
Yes, the library requires fonts.
The best option to add fonts in use by the library is to place the files of all the necessary fonts in some folder (for example Fonts) and add the statement:

FontRepository.Sources.Add(new FolderFontSource("Fonts"));

in the project before the operators using the Aspose.Pdf library.

There is no need to install the libgdiplus library - in .Net 7 it is not supported.
(Aspose.Pdf.Drawing works using the library Aspose.Drawing).

You can try installing the ttf-mscorefonts-installer package, (How to Install Aspose.PDF for .NET|Aspose.PDF for .NET) but I think the option above (indicating the folder with the font files) is better.