We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert PDF to Image using Aspose.PDF for .NET in Azure - System.Drawing is not supported

Hi, is there an alternative to the following method for converting PDF to Image in Aspose that doesn’t use System.Drawing?

Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice();
jpegDevice.Process(pdfDoc.Pages[i], outputStream);

I see old forum posts that hint your are going to update the API because System.Drawing is not supported in Azure. Do you have a date when this might happen?

Thanks

Stuart

@stuart.moore

Thank you for contacting support.

We are working on this task and will try to remove dependency on System.Drawing soon. A related ticket, PDFNET-45556, has been linked with thread so that you may be notified automatically as soon as it will be resolved.

Unfortunately whilst you are looking for a solution, we are required to look for an alternate product that has already solved the issue.

@stuart.moore

We will be trying to resolve this soon and will notify you once resolved. We appreciate your patience and cooperation in this regard.

No problem Farhan, our renewal date is coming up in January. If the functionality is there for Azure, we will happily renew our license.

@stuart.moore

We understand your concerns and will inform you as soon as this ticket will be resolved.

Has this been resolved? We are looking for software that can do this for us on Azure Gembox PDF will do it but not all pdf file configurations. In testing your software it does not appear to work on Azure

@Schavez70

The following snippet has been successfully tested in the South Central US Data Center with Aspose.PDF for .NET 20.7 and later.

Code tested as Azure Functions v2 and also as v3. Please let us know if you need extra info.

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}");
        }
    }
} 

Hi, my company was planning to buy an Aspose licence, but this is a bit of a show-stopper for us. Is there any update on the progress on removing the dependency on System.Drawing? That code above may work temporarily if you install the required libraries in Linux, but it won’t work with .NET 6.

If it’s not going to happen any time soon, is there any chance that you can do half of the job without System.Drawing? That is, are you able to create a raw image byte array from a pdf without System.Drawing, similar to how Docnet does ? Then I could do the next bit of converting the byte array to different image formats myself with something like ImageSharp or SkiaSharp, while awaiting the total removal of System.Drawing from Aspose.PDF.

Does this first step of the functionality currently exist, or is it something you could add easily?

(I can’t actually get Docnet+ImageSharp to work; just using it as an example…)

Sorry if it’s not that simple, I just don’t know what I’m talking about when it comes to images.

Thanks a lot,
James

@jamesbrooke

The task to remove GDI+ and use Aspose.Drawing as Backend Graphics is still under the phase of investigation. The ticket ID for the task is PDFNET-50217. We are afraid that we cannot share any promising timeline as the task is quite complex. However, we will surely post an update in this forum thread as soon as the ticket is resolved. We appreciate your patience in this regard.

We apologize for your inconvenience.