Aspose.pdf Inside Azure Functions Platform not supported exception

I have a following code in my application

I am having the code inside azure functions.

[FunctionName(“DemoFunctions”)]
public static async Task Run([HttpTrigger(AuthorizationLevel.Function, “get”, “post”, Route = null)]HttpRequestMessage req, TraceWriter log)
{

MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(html));
Document doc = new Document(stream, objLoadOptions);
//some code here …
}
I am getting Platform not supported exception in the Document Creation line

Message = “System.Drawing is not supported on this platform.”

Please help me in this regard.

@jesusilvester

Thank you for contacting support.

We would like to request you to share if this error appears with each file you are working with or only with specific files. Kindly share a narrowed down sample application reproducing this issue along with a source file, so that we may try to reproduce and investigate it in our environment to help you out. Also mention the environment details for our reference. Please share requested resources as single ZIP file and prior to sharing this data, please ensure using Aspose.PDF for .NET 18.4 in your environment.

Hi Thanks for your reply

My question is Will this work inside azure functions.

code attached

@jesusilvester

We can not find requested sample application attached with your post. If size of data exceeds 3MB upload limit then please upload it to Google Drive, Dropbox etc. and share the download link with us. Please share it for our reference. We will investigate and share our findings regarding compatibility of our API with Azure functions.

Hi. Any news about this issue? I am also experiencing the same problem. You’ll need to implement other means to process PDF page to a Bitmap/jpeg image. System.Drawing is not supported.

I am using
var bmpDevice = new BmpDevice((int)(rect.Width * options.BasicImageRatioMagnification),
(int)(rect.Height * options.BasicImageRatioMagnification), new Resolution(options.ImageResolution));
page.SendTo(bmpDevice, docStream);

I get the exception above at SendTo call.

Any solutions?

@baterija

Would you please share your environment details while specifying if you are working with Native APIs or Rest APIs so that we may investigate further to help you out.

Hi. It’s Azure Function v2, which is .NET Core application. I have the latest Aspose.PDF Library (18.10) and Windows 10.

@baterija

Would you please create a narrowed down sample application as there are some undefined variables in your code snippet, we will try to reproduce and investigate it in our environment.

Hi.

Here it is:

using(var docStream = MemoryStream()) { var rect = page.GetPageRect(true); var bmpDevice = new BmpDevice((int)(rect.Width),(int)(rect.Height)), new Resolution(130)); page.SendTo(bmpDevice, docStream); }
The exception is thrown at the line page.SendTo.

Hope this helps?

@baterija

Thank you for sharing updated code snippet.

We have modified your code a little but the error did not reproduce in our environment.

Stream stream = File.OpenRead(@"D:\" + "Test.pdf");
// bytes of a PDF file
byte[] pdfBytes = new byte[stream.Length];
stream.Read(pdfBytes, 0, pdfBytes.Length);

// Load the stream into a new document object.
var document = new Document(stream);
// You can close the stream now, it is no longer needed because the document is in memory.
stream.Close();

FileStream outputStream = new FileStream(System.IO.Path.Combine(@"D:\", "bmp_stream_18.10.bmp"), FileMode.Create);
var page = document.Pages[1];
using (var docStream = stream)
{
    var rect = page.GetPageRect(true);
    var bmpDevice = new BmpDevice((int)(rect.Width), (int)(rect.Height), new Aspose.Pdf.Devices.Resolution(130));
    //page.SendTo(bmpDevice, docStream); 
    page.SendTo(bmpDevice, outputStream);
} 

Would you please create a sample application reproducing this problem so that we may proceed to help you efficiently.

Hi.

This is all I do. Convert page to an image and then process it further. The SendTo method throws an error:

System.Drawing is not supported on this platform.

at System.Drawing.Drawing2D.Matrix..ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy) at ​ .(Single , Single , Single , Single , Single , Single , ​ ) at ​ .( , , , Single , Single , Boolean , Int32 , Boolean , Double& , Double& , & ) at ​ ..ctor( , , ) at . ( , , , ​ & ) at ​ .(​ & ) at Aspose.Pdf.Devices.ImageDevice.(Page ) at Aspose.Pdf.Devices.BmpDevice.Process(Page page, Stream output) at Aspose.Pdf.Page.SendTo(PageDevice device, Stream output)

Do you run this as a Azure Function v2? The code works on v1, since it run on normal .NET framework.

On dev machine I have the Function Runtime Version: 2.0.12134.0

Regards, Miha

@baterija

Kindly create a sample project application so that we may execute it and reproduce the issue in our environment.

This is the whole function you can try. It only contains Aspose.Pdf nuget package.

[FunctionName("Function1")] public static void Run([BlobTrigger("%DropBlobStorageContainer%/{name}", Connection = "")]Byte[] pdfFile, string name, ILogger log) { using (Document pdf = new Document(new MemoryStream(pdfFile))) { using (var docStream = new MemoryStream()) { try { var rect = pdf.Pages[1].GetPageRect(true); var bmpDevice = new BmpDevice((int)(rect.Width), (int)(rect.Height), new Resolution(130)); pdf.Pages[1].SendTo(bmpDevice, docStream); } catch (Exception ex) { log.LogError(ex.Message); } } } }

@baterija

Thank you for clarifying that you are working with BlobTrigger. However, we will appreciate if you can share a sample project so that all respective settings and details may be included and will help us reproduce and investigate it in our environment.

BlobTrigger is just pointng to a Contaner, so you can instread %DropBlobStorageContainer% put pdf-in, like this:

BlobTrigger(“pdf-in/{name}”)

WHen a PDF is dropped in the container it is picked and processed as a Byte[]

@baterija

We are investigating the scenario and will get back to you soon.

@baterija

We have created a sample project application for your kind reference. Would you please try executing it in your environment and then update us if this issue reproduces or not. In case it does not reproduce it, then please create a sample application project for our reference so that we may proceed to replicate and resolve the issue in our environment.
TestReproduce.zip

You need to change license path, PDF file path or name and build the application, then share your findings for our reference.

Hi thank you, I do not have permissions to download it.

@baterija

Thank you for the update. Due to data security concerns, only thread owner and our staff can access attachments. Kindly download it from this Google Drive link and share requested feedback with us.