Aspose.pdf Inside Azure Functions Platform not supported exception

This is a .NET Core application which work fine. What we are developing is an Azure Function v2. Here is a demo solution from me: https://1drv.ms/u/s!Al0lcDVf1hMRgjtH9DBeEdV9VmBl

@baterija

Thank you for sharing sample application. Please also mention the steps to reproduce the exception because it is not occurring by simply executing the application. We will follow the steps and proceed further to help you out.

To test it locally you need to install Storage Explorer and Storage Driver and create a blob storage container with name “pdf-in” (local.settings.json). Then you need to run the app and put a PDF file to the pdf-in container, which will trigger the function to load the file.

@baterija

Thank you for elaborating it. We are working on the scenario and will get back to you with our findings soon.

@baterija

Thank you for being patient.

We have logged a ticket with ID PDFNET-45556 in our issue management system for further investigations. The ticket ID has been linked with this thread so that you will be notified as soon as some significant updates are available in this regard.

We are sorry for the inconvenience.

Hi there. Any news about this yet?

Thank you.

@baterija

We are afraid that logged ticket has not been investigated yet. We will let you know as soon as some information will be available, please spare us some time.

@Farhan.Raza any news on this front?

Regards

@baterija

Thank you for getting back to us.

We are afraid PDFNET-45556 has not been scheduled yet, owing to previously logged and critical tickets. We appreciate your patience and comprehension in this regard.

The same issue exists with Aspose.Cells

1 Like

@BennyM

Thank you for contacting support.

Would you please create a topic in Aspose.Cells forum while sharing all the details, sample application and respective files so that we may try to reproduce and investigate it in our environment.

@jesusilvester @baterija

Thank you for being patient.

We would like to inform you that we have investigated it further and have figured out that Azure Functions v2 work in sandbox, not in .NET Core CLR.

Due to sandbox limitations we can not run code which uses System.Drawing, so currently only Azure Function v1 will work correctly. We have also contacted with Microsoft Azure Evangelists and, we are afraid, they neither have any information about some other solution.

1 Like

Dear Team,

We are also experiencing similar issue while we are trying to convert HTML string to a PDF. Do you have any latest update or workaround on this issue.

Thanks & Regards
Anish

@Anishc

Thanks for contacting support.

We regret to share that earlier logged issue is still pending for resolution. After an initial investigation, we concluded that Aspose.PDF for .NET has a dependency on System.Drawing and the last is disabled in Azure Function runtime.

Unfortunately, Microsoft proposes to use ImageSharp for image handling in Azure Function but we cannot use it. Also, we could not find any news about when they plan to enable System.Drawing in the nearest future. We plan to migrate Aspose.PDF for .NET to another graphics library and as soon as we make some updates, we will let you know. Please spare us little time.

We are sorry for the inconvenience.

@asad.ali

Our company would like to use Aspose with Azure functions as well and are encountering this same issue. Is there any update on timelines? Thank you.

@ahammad

Thank you for your interest in Aspose APIs.

We are afraid any timeline is not available at the moment. It is quite a task and is in progress, so we will let you know as soon as some updates will be available in this regard.

Question: Does Aspose.PDF for .NET does not work in any Azure function version ? or it works in V1 and does not work in V2.

I have made a Azure function(v1) which is converting html to pdf using aspose.pdf library. It is only saving blank pdf for me in the blob storage.

@azamatali

We are afraid that we cannot comment further on this ticket until it is resolved. Please note that ticket is still under investigation process and as soon as we make any significant progress towards its resolution, we will surely share our feedback within this forum thread. Please spare us some time.

We are sorry for the inconvenience.

Hi - Is there any update on this issue? I would like to use Aspose PDF inside an Azure function.

@kbowling1993

Sure, you can use Aspose.PDF inside Azure Function. However, please make sure to use the latest version of the API. Furthermore, 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}");
        }
    }
}