Free Support Forum - aspose.com

Error converting pdf to JPEG images on .NET Core 3.1 / Linux Ubuntu 20.04

I have a need to convert PDF files to a collection of images, one per page. I successfully used Aspose.PDF on Windows to convert to images - everything worked fine. However, our environment requires that I use Aspose.PDF on Linux, so I compiled and ran on Ubuntu 20.04, and I get the following thrown exception:

ArgumentNullException: Value cannot be null. (Parameter ‘key’)

This seems to be the exact same issue that was encountered in Feb 2019, on MacOS / Linux, on .NET Core 2.2:

I am awaiting resolution of this issue before purchasing. I am currently a happy user of Aspose.Words on Linux, with a Developer OEM license. If this issue is resolved and I am able to successfully run on Linux, I will purchase the same license for Aspose.PDF.

Here is the stack trace:

eric@eric-ubuntu:~/Documents/20-08-19-Aspose-Pdf-First$ dotnet run
/home/eric/Documents/ittl2/AVGL/13462649.pdf
13462649
.pdf
/home/eric/Documents/ittl2/AVGL/13462649image1_out.jpg
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at #=zwOlmJWC0f5xaBb03$4$O55e4hGtJNOHxbQ==.#=zdG5j0Q4=(#=z9YeI0io= #=zAMh25x0=)
   at #=zLqz12LYV$GPxQ6F56k7S1FQdrowBmJgDAg==.#=zOeJFTKwFsxFw.#=z3j8uTJ9FssxY(#=z9YeI0io= #=zAMh25x0=, #=zD_bqYRU=& #=zFGXr3$M=)
   at #=zi3TXwmokU72w_8_FToZ9wAzknVruVLUxTrlvJzg=.#=zVTCBAtGRgKyy(#=z2$0aIuTnlxZFBS39b42X$FF6D2iI #=znJ3LyUAgOGtv)
   at #=zVzWhE1DM4Ie1knWt6njKwsCHnQfh.#=zxuZ4ZGg=(#=zJRoqtKfEX723e63CZPklJ$i67_W1VnvqkWS2DOGUBU0$& #=zRBCY2gg=)
   at #=zVzWhE1DM4Ie1knWt6njKwsCHnQfh.#=zxuZ4ZGg=()
   at Aspose.Pdf.Devices.ImageDevice.#=zxuZ4ZGg=(Page #=zZPNcMZI=)
   at Aspose.Pdf.Devices.JpegDevice.Process(Page page, Stream output)
   at Program.ProcessPdf(FileInfo fi) in /home/eric/Documents/20-08-19-Aspose-Pdf-First/Program.cs:line 73
   at Program.ProcessDirectory(DirectoryInfo di) in /home/eric/Documents/20-08-19-Aspose-Pdf-First/Program.cs:line 19
   at Program.ProcessDirectory(DirectoryInfo di) in /home/eric/Documents/20-08-19-Aspose-Pdf-First/Program.cs:line 23
   at Program.Main(String[] args) in /home/eric/Documents/20-08-19-Aspose-Pdf-First/Program.cs:line 12
eric@eric-ubuntu:~/Documents/20-08-19-Aspose-Pdf-First$

Here is the program:

using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Devices;
using Aspose.Pdf.Drawing;

class Program
{
    static void Main(string[] args)
    {
        DirectoryInfo di = new DirectoryInfo(@"/home/eric/Documents/ittl2");
        ProcessDirectory(di);
    }

    private static void ProcessDirectory(DirectoryInfo di)
    {
        foreach (var fi in di.GetFiles("*.pdf"))
        {
            ProcessPdf(fi);
        }
        foreach (var subDi in di.GetDirectories())
        {
            ProcessDirectory(subDi);
        }
    }

    private static void ProcessPdf(FileInfo fi)
    {
        Console.WriteLine(fi.FullName);

        var pdfDi = fi.Directory;
        var ext = fi.Extension;
        var baseName = fi.Name.Substring(0, fi.Name.Length - ext.Length);
        Console.WriteLine(baseName);
        Console.WriteLine(ext);

        Document pdfDocument = new Document(fi.FullName);
        for (int pageCount = 1; pageCount <= Math.Min(pdfDocument.Pages.Count, 4); pageCount++)
        {
            var imagePath = System.IO.Path.Combine(pdfDi.FullName, baseName + "image" + pageCount + "_out" + ".jpg");
            Console.WriteLine(imagePath);
            var fi2 = new FileInfo(imagePath);
            if (fi2.Exists)
                fi2.Delete();
            
            using (FileStream imageStream = new FileStream(System.IO.Path.Combine(pdfDi.FullName, baseName + "image" + pageCount + "_out" + ".jpg"), FileMode.Create))
            {
                // Create JPEG device with specified attributes
                // Width, Height, Resolution, Quality
                // Quality [0-100], 100 is Maximum
                // Create Resolution object
                Resolution resolution = new Resolution(300);

                // JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                // Convert a particular page and save the image to stream
                jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                // Close stream
                imageStream.Close();

            }
        }
    }
}

@Eric_White

Sadly, the ticket PDFNET-46048 is not yet resolved. However, we have updated its information and logged your concerns along with it. We have also associated it with your thread so that you will receive a notification once it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you for your response. Kindly let the triage folks know that it is super-important to fix this issue.

@Eric_White

We have recorded your concerns. However, please note that the issues under free support model have low priority and are resolved on first come first serve basis. We will surely consider your concerns and look into the issue by considering them. You can also check our priority support option in case the issue is a blocker for you and you need to get it resolved on an urgent basis. We will inform you as soon as we have some updates regarding its resolution.

Hi @asad.ali - thank you for your response. I understand that this is regarded as an issue submitted under the free support model. However, be aware that this does not exactly describe the situation. It is actually pre-sales support - we were contemplating purchasing Aspose.PDF, and given the situation with this bug, have decided against it. I feel sad to let you know that for now, we have decided to purchase a product that competes with Aspose.PDF. However, this is not set in stone. While we will be using a competing product for the next six months or a year, if this bug were fixed, it very well would be possible to revisit the decision. I would not expect that if we purchase a priority support option, that Aspose would be able to fix this bug in a timeframe that would suit us. I’ll watch this space, and if the bug is fixed, will raise it with my manager and others, and we will revisit the decision. Kind regards, Eric

@Eric_White

We really regret to see you choosing a product other than Aspose.PDF. However, we have noted your comments and will surely inform you as soon as the logged ticket is resolved. We apologize for your inconvenience.

Hi,
We are evaluating Aspose.pdf and we have the same trouble with CentOS8/Core.net 5.0.
I notice priority support option and we uderstand why the ticket is not resolved.
By the way, we won’t buy anything (product/support) without an assurance of résolution.

How can you help ?

Christophe

@BOURY, @Eric_White

We would like to share with you that we investigated the earlier logged ticket and found that the encrypted stack trace information was about fonts initialization problem. We could not reproduce the ArgumentNullException exception and successfully converted PDF to JPEG using Aspose.PDF 19.1 and .NET Core 2.2 on MacOS 10.15 and Ubuntu 20.10.

For Aspose.PDF 21.4 the conversion works too.

Make sure that libgdiplus and mscorefonts are installed and the fonts are placed in the correct path.

For Mac we used the NuGet package runtime.osx.10.10-x64.CoreCompat.System.Drawing (instead of installing libgdiplus) and added MS font path to FontRepository

var fontPath = "/System/Library/Fonts/Supplemental"; // may differ for other Mac versions
Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource(fontPath));

For Linux we used libgdiplus 6.4 and MS font path /usr/share/fonts/truetype/msttcorefonts without further adding it to the FontRepository.Sources.

sample_app.zip in Docker works fine.

Dockerfile.zip (800 Bytes)
sample.pdf (20.8 KB)
output.zip (1.5 MB)
sample_app.zip (1.5 MB)

Thanks for support.
font path seems to be the solution (after libgdiplus& mscorefonts )

@BOURY

It is good to know that your issue has been resolved. Please keep using our API and feel free to create a new topic in case you need more assistance.