We’re trying to use ImageStamp to add a png image on PDF using .Net 6. It works on Windows, but got exception on Linux: System.Drawing.Common is not supported on non-Windows platforms.
We’re using Aspse.PDF 23.10.0, the program is written in .Net 6. Below is the code
using Aspose.Pdf;
using Aspose.Drawing;
namespace Aspose_Test
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
byte[] fileBytes = File.ReadAllBytes("1.pdf");
Image<Rgba32> image = SixLabors.ImageSharp.Image.Load<Rgba32>("Stamp.png");
using (var stream = new MemoryStream())
{
image.SaveAsPng(stream);
ImageStamp imageStamp = new ImageStamp(stream);
imageStamp.Background = true;
imageStamp.XIndent = 100;
imageStamp.YIndent = 100;
imageStamp.Height = 300;
imageStamp.Width = 300;
imageStamp.Rotate = Rotation.on270;
imageStamp.Opacity = 0.5;
Document doc = new Document(new MemoryStream(fileBytes));
doc.Pages[1].AddStamp(imageStamp);
MemoryStream ms = new MemoryStream();
doc.Save("Stamped.pdf");
}
}
}
}
Below is the exception on Linux
>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.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
at Aspose.Pdf.ImageStamp..ctor(Stream image)
at Aspose_Test.Program.Main(String[] args) in F:\Project\CSharp\Aspose Test\Aspose Test\Program.cs:line 18
Aborted (core dumped)
Any solution to fix this problem?