Aspose PDF without dependency on System.Drawing

I understand that Aspose.PDF for .NET requires System.Drawing, and as a result requires libgdiplus on Linux.

We see this as a risk since libgdiplus isn’t really officially maintained and even Microsoft doesn’t recommend it’s use (Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn).

Is there a near term plan to eliminate dependency on System.Drawing and instead use Aspose.Drawing or SkiaSharp?

@ILikeCranberries

We already logged a ticket to test Aspose.PDF functionality under .NET 6.0 in non-Windows environments as PDFNET-50918. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Thanks, Tahir.

What exactly is PDFNET-50918 about? I’m not sure how to view it, I just see it’s marked as Resolved.

Which release is it planned to be included into?

@ILikeCranberries

The issue PDFNET-50918 has been resolved and its fix will be available in the next version of Aspose.PDF for .NET i.e. 23.1. We will inform you via this forum thread once it is released.

Thank you, Tahir.

My question though is what does PDFNET-50918 achieve or what is it about? I’m not getting the impression that that ticket addresses my concern, which is running Aspose.NET on Linux free of dependency from libgdiplus.

@ILikeCranberries

Aspose.PDF.Drawing NuGet package has been released. The DLL in this package does not have System.Drawing.Common dependency.

Hi Tahir,

Sorry, but I’m not getting the full picture here. Does that mean that Aspose.PDF v23.1 also wouldn’t have any dependency on System.Drawing.Common?

@ILikeCranberries

Yes, your understanding is correct. We removed the dependency of System.Drawing.Common from Aspose.PDF for .NET 23.1.

Hi @tahir.manzoor

I just tried converting JPG to PDF using Aspose.PDF v23.1.0 with Aspose.Drawing as a dependency and received this error on Ubuntu with .NET 6.

Code is based on sample here Convert various Images formats to PDF in .NET|Aspose.PDF for .NET

    Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
 ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
   at System.Drawing.LibraryResolver.EnsureRegistered()
   at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   at System.Drawing.SafeNativeMethods.Gdip.GdipCreatePath(FillMode brushMode, IntPtr& path)
   at System.Drawing.Drawing2D.GraphicsPath..ctor(FillMode fillMode)
   at #=zsvLDtHYymYSUa8DU11ayP0AzVy2E.#=zbKquNXk=(#=zsODPSZ0YH7cYHfnSLvnnY4o= #=zw6Lhzwg=)
   at #=zS5SNRUbbtWTK6OAdX2NPHtOMhwNyXL5AP7h8SEc2Pdbf.#=zfboVgr39N8qD(#=zYGXb8CavM8_p3pY5PAB54opjvDBTGw0ddQ== #=zw6Lhzwg=, #=zVHNVSjvqzpPxmjjoUMDTLeb4c7WLX71lTL9KBeA= #=zK9mO3gBWYYCM)
   at #=zPkNwMxu1ye97RjWbr0ubC1pXYXnh40aLfmmm7Q7DZ7db..ctor(#=zf$LjgtDb7RTfB21nvJC49gMV0som #=zCluotbw=, #=zGuSEinf51GwaWgcLur1eBm3mrGF4wzzKWQ== #=zV1YhCCo=, #=zV71mTzZAOL89qaDq0fysgfzE$l19AzKf5NIzOBU= #=zz$tk4VrK1EvB)
   at #=zaxtMu44FIXVnUVGZw1CmesjKYdRl943m0ark4eY=.#=zONxzAUroN1nE(#=zf$LjgtDb7RTfB21nvJC49gMV0som #=zCluotbw=, #=zGuSEinf51GwaWgcLur1eBm3mrGF4wzzKWQ== #=zV1YhCCo=, #=zV71mTzZAOL89qaDq0fysgfzE$l19AzKf5NIzOBU= #=zz$tk4VrK1EvB)
   at Aspose.Pdf.Page.CalculateContentBBox()
   at Aspose.Pdf.Page.#=z4EVFdC0=(Page #=zV1YhCCo=)
   at Aspose.Pdf.Document.ProcessParagraphs()
   at Aspose.Pdf.Document.#=zg9hU84stvRSb(Stream #=z$$huN9A=, SaveOptions #=zKUavTA6dqtXQ)
   at Aspose.Pdf.Document.#=zhNNMKwgnXtgq(String #=zrjxxXxDi9NTq)
   at Aspose.Pdf.Document.Save(String outputFileName)
   at Program.<<Main>$>g__JpgToPdfA|0_1(String jpgFilename, String outputPdfFilename)
   at Program.<Main>$(String[] args)

Moreover, Aspose.PDF v23.x on Nuget still has dependency on System.Drawing.Common.
image.png (58.2 KB)

@ILikeCranberries

Please remove Aspose.PDF and install Aspose.Pdf.Drawing from NuGet instead. This does not have dependency on System.Drawing.Common.

@asad.ali Both Aspose.PDF and Aspose.PDF.Drawing have a dependency on System.Drawing.Common, are we missing something here?

Aspose.Pdf.Drawing only needs System.Drawing.Common while using specific features like printing. Other than that, it does not acquire it and works independently. We have successfully test it under Linux like environments. Could you please make sure that you have removed existing Aspose.PDF for .NET from your project and kept only Aspose.Pdf.Drawing? Also, please make sure to use the latest version.