[Aspose.PDF.Drawing] System.Drawing.Common is not supported on this platform

Hi!
I’m trying to use Aspose.PDF to run in linux, but I received an exception :System.Drawing.Common is not supported on this platform.
I’ve tried to use the recommended Aspose Drawing (Cross-Plataform compatibility) packages, but don’t work.

Below more details:

net7.0

Packages:

<PackageReference Include="Aspose.PDF" Version="23.12.0" />
<PackageReference Include="Aspose.PDF.Drawing" Version="23.12.0" />
<PackageReference Include="Aspose.Drawing" Version="23.12.0" / >

Code:

using var imageStream = new MemoryStream(); 
    var resolution = new Resolution(300);
    var pngDevice = new PngDevice(resolution);
    pngDevice.Process(pdfDocument.Pages[pageCount], imageStream); 

...

Exception:

System.Drawing.Common is not supported on this platform.

PlatformNotSupportedException
Stack Trace:    at System.Drawing.Drawing2D.Matrix..ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
   at #=z2GSAH2G0Qaj9qY6UL_G7H5FDFCd5ENCYBEe5$tM=..ctor(Single #=zEgmOj_4=, Single #=zduKAAcs=, Single #=zQPlRzOQ=, Single #=zO4H5Jws=, Single #=zO_5tCQA=, Single #=zJrFPpfU=)
   at #=zbl3SBT90TdOAO$oRLeX_Sn1PKp601xN$ig==.#=zMAQa_sQ=(Single #=zEgmOj_4=, Single #=zduKAAcs=, Single #=zQPlRzOQ=, Single #=zO4H5Jws=, Single #=zO_5tCQA=, Single #=zJrFPpfU=, #=ztQl0AOwIdDoSfBIdInSfk5AzajCpX46oUg== #=zKEWIuME=)
   at #=zAQxatDytNh8BOTUfBqM06qD2q5YCdhxM_bqKzj9DnLsO.#=zEUavANzbXFRO(#=z7bI4GhXHbP5a$tKtZ8fm0x0ejZLDnJdQXQ== #=z05yNtkA=, #=zyjslpCbCDUl12gW0LH_yBU8_1A$9yojmwiEP0v4= #=z3r_3pNHazxMY, #=zHtSysFQEWGv3ecyZVci14gqd5CTqQ$egUw== #=zrmX4ZuA=, Single #=zt4aDlbejXmEX, Single #=zRa2rXq0yvaeS, Boolean #=z9jw2WzYkFasjxD7HVw==, Int32 #=zT9H_jsjMT$UBv$dDGpLVKq4=, Boolean #=zc11nJmLKqIZ6, Double& #=z5WtUCLA=, Double& #=zKelZDJM=, #=z8scOvMShC1xEMFh$ErV9zgl_Nf__qHFKwg==& #=zECSUUJ8=)
   at #=zAQxatDytNh8BOTUfBqM06qD2q5YCdhxM_bqKzj9DnLsO..ctor(#=zhDiVB3pjHonKETa5jZcnNV4HPOrU #=zMZ2Dv3A=, #=z7bI4GhXHbP5a$tKtZ8fm0x0ejZLDnJdQXQ== #=z05yNtkA=, #=zyjslpCbCDUl12gW0LH_yBU8_1A$9yojmwiEP0v4= #=z3r_3pNHazxMY)
   at #=zVGBy2YEQzefSZsUGqcRlMTCIqfQc51NwUoWRa8I=.#=z0qTKX3ad0bXC(#=zhDiVB3pjHonKETa5jZcnNV4HPOrU #=zMZ2Dv3A=, #=z7bI4GhXHbP5a$tKtZ8fm0x0ejZLDnJdQXQ== #=z05yNtkA=, #=zyjslpCbCDUl12gW0LH_yBU8_1A$9yojmwiEP0v4= #=z3r_3pNHazxMY)
   at #=z9VcdlP$CMo_Jr4PQkkfK7rQeW2zsmmbIQRt47CIyPdI$.#=z7xtsFCo=(#=zhDiVB3pjHonKETa5jZcnNV4HPOrU #=zMZ2Dv3A=, #=z7bI4GhXHbP5a$tKtZ8fm0x0ejZLDnJdQXQ== #=z05yNtkA=, #=zyjslpCbCDUl12gW0LH_yBU8_1A$9yojmwiEP0v4= #=zgLT9OHk=, #=zAQxatDytNh8BOTUfBqM06qD2q5YCdhxM_bqKzj9DnLsO& #=zyIoQR4M=)
   at #=zYtH8dGyRdbjWDe$h6u2dzxvqxcXn.#=zB24$4eo=(#=zAQxatDytNh8BOTUfBqM06qD2q5YCdhxM_bqKzj9DnLsO& #=zyIoQR4M=)
   at #=zYtH8dGyRdbjWDe$h6u2dzxvqxcXn.#=zB24$4eo=()
   at Aspose.Pdf.Devices.ImageDevice.#=zB24$4eo=(Page #=z05yNtkA=)
   at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)
   at Printing.PrintService.GetPreviewImagesAsync(..., CancellationToken cancellationToken) in PrintService.cs:line 109
   at Apis.tcontroller.GetPrintPreviewImages(Dto dto, CancellationToken cancellationToken) in /src/Apis/tcontroller.cs:line 137
   at lambda_method815(Closure, Object)
..

Inner Exceptions: None available

Any suggestions?

@Adansk

You should not use both Aspose.PDF and Aspose.Pdf.Drawing in one project. You can remove Aspose.PDF package and then try again. Aspose.Pdf.Drawing does not have any dependency on System.Drawing.Common except it acquired it for printing features in Windows environments.

When you say that Aspose.Pdf and Aspose.Pdf.Drawing should not be use in one project.

  1. Does it means that both support same functionality ?
  2. How about if Aspose.Pdf and Aspose.Pdf.Drawing become part of same artifact via indirect reference.

Library1 reference Aspose.Pdf
Library2 reference Aspose.Pdf.Drawing

Now there is one Api or WebApi that reference both Library1 and Library2. Now Aspose.Pdf and Aspose.Pdf.Drawing become part of same artifact when WebApi project publish.

@jpatciv

Aspose.PDF and Aspose.Pdf.Drawing both support same functionality except Aspose.Pdf.Drawing does not acquire System.Drawing.Common dependency in order to provide features. We do not recommend using Aspose.Pdf.Drawing and Aspose.PDF in same project.

Furthermore, please allow us to gather technical details and explanations on why these both APIs should not be used in same project and what would happen if we do so. A ticket as PDFNET-56453 has been logged in our issue management system for this purpose, we will let you know as soon as it is closed.

Hi, I’ve removed the references but the package Aspose.PDF.Drawing has the reference of System.Drawing.Common. How can I avoid this to run on linux and cross-plataform?
image.png (6,5,KB)

@Adansk

Aspose.Pdf.Drawing only requires System.Drawing.Common while executing the printing operations. Other than that, it is already tested in the Linux platforms under .NET 6/7 and it worked without any issues. In case you are not using any printing feature of the API, you can use it in the Linux and let us know if you still face any issues.

Let me understand. When you say I can’t use the printing feature of the API, how can I know this call is using a printing feature?

This code below should works or this is a part of printing feature?

using var imageStream = new MemoryStream(); 
    var resolution = new Resolution(300);
    var pngDevice = new PngDevice(resolution);
    pngDevice.Process(pdfDocument.Pages[pageCount], imageStream); 

Thanks

@Adansk

Aspose.Pdf.Drawing helps to avoid numerous problems and bugs associated with using System.Drawing.Common on non-Windows platforms. Aspose.PDF.Drawing library successfully works on the Docker platform that allows you to package into a container your application.

(Aspose.PDF.Drawing contains the reference for System.Drawing.Common, but it is invoked only on Windows platforms and only for printing. Aspose.PDF.Drawing works with no error on Linux containers of Cloud and GroupDocs commands.)

When we say printing, it means printing the PDF document using virtual or physical printer. The code your shared should work without any issues using Aspose.Pdf.Drawing. Are you facing some issues? Have you installed all Windows fonts in your system as well? Please share some more details and we will update the ticket information associated here already.

Hi,
I continue having the same error.

Below I have removed the Aspose.PDF package.

image.png (3,9,KB)

I also have other projects that have reference to Aspose.PDF, should I change all to Aspose.PDF.Drawing?

The code continues the same.

I’ve added the libfontconfig1 in dockerfile.

The image is used: mcr.microsoft.com/dotnet/runtime

And if it is possible, could you share a project that I can compare with my project and try to find a solution.

I’ve created a new project to test Aspose.PDF.Drawing and I’m getting this error:
The code base is the same, but it is executing in a new project.

Unhandled exception. System.Exception: No suitable system fonts found
   at #=zC$kOZ0qXlceK1AjAEYX1y_gFhgwt.#=zw5zXFKD1rs07(#=zNlCP5lCGcgVO6MZ3AFKlRbxfZ1SoI3M77Q== #=z40Qu$Y8=)
   at #=zC$kOZ0qXlceK1AjAEYX1y_gFhgwt.#=z7Vr55lc=(#=zlHsjAMLpWrUiX3xwvXF_u1_sizxzZ13mqsKDfus8tLYv& #=zGDzR53k=)
   at #=zC$kOZ0qXlceK1AjAEYX1y_gFhgwt.#=z7Vr55lc=()
   at Aspose.Pdf.Devices.ImageDevice.#=z7Vr55lc=(Page #=zYyaXARg=)
   at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)
   at ConsoleApp1.Program.Main(String[] args) in /src/ConsoleApp1/Program.cs:line 25```

After changed all references packages Aspose.PDF to Aspose.PDF.Drawing it works.
Thansks

@Adansk

It is nice to know that your issue has been resolved. Please feel free to create a new topic in case you need further assistance.

1 Like

Hi,
Works on Windows:
image.png (17,9,KB)
But didn’t work on linux:
image.png (14,0,KB)

I’ve removed the libfontconfig1 and all the text was removed. So I think this is related to configure font in linux

image.png (4,1,KB)

Could you help me with this. Seems somenthing related to font.

@Adansk

Please try to install all windows fonts e.g. msttcorefonts package in your Linux environment. You can search on the internet further for the suitable packages for your environment. Also, you can simply copy all the fonts from your Windows environment and paste them in the fonts folder over Linux system. In case you still face any issues, please let us know.

1 Like

Ok, It worked now. Do I need install libfontconfig1 and ttf-mscorefonts-installer together?

@Adansk

Different Linux flavors support different packages. We recommend that you keep all Windows fonts (mostly msttcorefonts package has them). In case your PDF documents are expected to use some custom or non-Windows fonts, you can also install them as there is no harm in this.

1 Like

@landDownUnder

Aspose.Pdf.Drawing has same set of classes. You can access Page, TextSegment, etc. with Aspose.Pdf.Drawing as well. Therefore, we recommend you only use one API i.e. either Aspose.PDF for .NET or Aspose.Pdf.Drawing. Please let us know if you face any issues.