Hi, we just purchased Aspose.Total and found out that it’s failing inside Azure Functions (v2 using .NET Core) with the following error - “System.Drawing is not supported on this platform”.
We are simply trying to convert PDFs uploaded to Azure storage to images.
It’s throwing an exception on this line:
tiffDevice.Process(document, i, i, imageStream);
Attaching the screenshot for reference.PDF to TIFF error.jpg (331.2 KB)
We know there is a limitation in Azure Function because your product uses System.Drawing classes, but we need to make this work.
Do you have any ETA on not relying on System.Drawing namespace?
Thanks!
@appdev.mmo
Thanks for contacting support.
The issue you facing has already been logged in our issue tracking system as PDFNET-45556. It is now associated with this forum thread so that you will receive notification once it is resolved. For your information, the issue is currently in suspended state as 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. Aspose.PDF plans to migrate to another graphics library developed by Aspose.Imaging and this task is currently under progress. We will surely inform you as soon as we have some definite updates in this regard. Please spare us little time.
We are sorry for the inconvenience.
I am encountering this issue too - can you direct me to how I can see PDFNET-45556 so that I can find out the status?
@bledbet
Regretfully, the issue is still pending for a fix due to the reasons mentioned in our previous response in this thread. We will surely update the progress in this forum thread as soon as we make some. Please spare us some time.
We are sorry for the inconvenience.
Hi Support.
Do you have any updates on this or any future plans?
Thank you,
Oleg
@Oleg_Sh
The following snippet has been successfully tested in the South Central US Data Center with Aspose.PDF v20.7 and later.
Code was 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}");
}
}
}
You may please use the latest available version of the API in Azure Function and let us know in case you face any issue.