Free Support Forum - aspose.com

Aspose.PDF dependend on system.drawing

I have the same wish as System.Drawing is not supported on this platform.
I would really like to use Aspose.PDF on dotnet core.

Please keep me up to date when this is possible.

Kind regards.

@Fred.Net

Thank you for contacting support.

We are working to remove the dependency on System.Drawing which is quite a task, so we are afraid any ETA may not be available yet. However, we have logged your concerns and have attached the ticket ID PDFNET-45556 with this thread so that you may be notified automatically as soon as the ticket is resloved.

Hi,
We use Aspose in web service and we have problems referring to System.Drawing.

We would like to know if this reference has been removed in any version.

Best regards

@rblasco76

At this moment, Aspose.PDF is delivered with a reference to System.Drawing Assembly. We have been trying to remove this dependency and replace it with our own component but that is still in raw production. As far as the API usage under .NET Core environment is concerned, we tested following code snippet with 20.7 and later versions of the API and did not face any issue.

The following snippet has been successfully tested in the South Central US Data Center with Aspose.PDF v20.7 and later. Code tested as Azure Functions v2 and also as v3.

public static class Function1
{
    [FunctionName("Function1")]
    public static void Run([BlobTrigger("pdf-in/{name}", Connection = "")] Stream myBlob, string name, ILogger log,
        [Blob("images-out/{rand-guid}.png", FileAccess.Write)] Stream imageStream)
    {
        log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        using var pdf = new Aspose.Pdf.Document(myBlob);
        var rect = pdf.Pages[1].GetPageRect(true);
        var pngDevice1 = new Aspose.Pdf.Devices.PngDevice((int)rect.Width, (int)rect.Height,
            new Aspose.Pdf.Devices.Resolution(300));
        var memoryStream = new MemoryStream();
        try
        {
            pdf.Pages[1].SendTo(pngDevice1, memoryStream);
            memoryStream.Position = 0;
            memoryStream.CopyTo(imageStream);
            log.LogInformation($"C# Blob trigger function. \n Copied to images-out");
        }
        catch (Exception ex)
        {
            log.LogError($"C# Queue trigger function processed: {ex.Message}");
        }
    }
}

Yet another snippet for TIFF:

[FunctionName("Function1")]
public static void Run(
    [BlobTrigger("pdf-in/{name}", Connection = "")] Stream myBlob,
    string name,
    ILogger log,
    [Blob("images-out/{rand-guid}.tiff", FileAccess.Write)] Stream imageStream)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");

    using (var pdf = new Aspose.Pdf.Document(myBlob))
    {
        var rect = pdf.Pages[1].GetPageRect(true);
        var tiffDevice = new Aspose.Pdf.Devices.TiffDevice((int)rect.Width, (int)rect.Height,
            new Aspose.Pdf.Devices.Resolution(300));
        var memoryStream = new MemoryStream();
        try
        {
            tiffDevice.Process(pdf, 1, 1, memoryStream);
            memoryStream.Position = 0;
            memoryStream.CopyTo(imageStream);
            log.LogInformation($"C# Blob trigger function. \n Copied to images-out");
        }
        catch (Exception ex)
        {
            log.LogError($"C# Queue trigger function processed: {ex.Message}");
        }
    }
}

Please let us know if you need further information.

@rblasco76

Adding more to our previous response, DRAWINGNET-331 is the ticket which was logged in order to integrate Aspose.Drawing with Aspose.PDF to remove System.Drawing dependency. The ticket has been linked with this post now and you will be notified once it is resolved.