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

Free Support Forum - aspose.com

Error converting pdf to JPEG images on .NET Core 2.2 / Mac OS

I am trying to convert a pdf file to jpeg images. But I am getting the below error on the line jpegDevice.process.

“ArgumentNullException: Value cannot be null.Parameter name: key”

The conversion works fine on the Windows machine, But it fails on Mac. It also fails when deployed to Linux docker container.

Here is the link to download the sample app - https://www.dropbox.com/s/m8nw7x16dtnbzp2/AsposeTest.zip?dl=0

Below is the code from that which converts pdf to images.

private void GetImagesFromPdf()
    {
        // For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
        // The path to the documents directory.
        string dataDir = _hostingEnvironment.ContentRootPath + "//dataFiles//";

        // Open document
        Document pdfDocument = new Document(dataDir + "listing agreement.pdf");
        //pdfDocument.Flatten();

        for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
        {
            using (FileStream imageStream = new FileStream(dataDir + "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();

            }
        }
    }

@imamrazi

Thank you for contacting support.

We have investigated the scenario but we have faced different exception, TypeInitializationException, while reproducing it. Would you please share some more details about your environment. Please specify if you have libgdiplus and MS Core fonts installed. Please also share complete stack trace of the exception so that we may investigate further to help you out. Moreover, please ensure using Aspose.PDF for .NET 19.1 before sharing requested information.

Hi Farhan,

I have installed the libgdiplus and MS fonts and tried again, But got the same exception. I was already using Aspose PDF for .NET 19.1 and updated today to 19.2, Buts its same error - "ArgumentNullException: Value cannot be null.Parameter name: key”

I am using Visual Studio for Mac Community Edition 7.7.2 on MacBook Pro (macOS Mojave). Below is the stack trace.

“at System.Collections.Generic.Dictionary2.FindEntry(TKey key)\n at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)\n at #=zX9ao5ZAmBtSfRJVZha57DytTLSqREnpK0w==.#=zdJnrgtk=(#=zo1LX8F4= #=zSMrJg1s=)\n at #=zFagJRTymacgC6bdukMRGLv1wIH_a9h1oOA==.#=zXKQqjUD34xLQ.#=z6T8ZtswN4xkE(#=zo1LX8F4= #=zSMrJg1s=, #=zEtjIv5o=& #=zpWpruPU=)\n at #=zHs_NnNS80agusY_MUpwuxD8HR8f$OaoYdioHcTw=.#=zGRTs4Vw2Bryo(#=zy0eKz_haG2nZboKQiULPv6GLXgLZ #=zGFrw3OOWBUCU)\n at #=z_0eXijCbnDc9xPTRuVmH$rpkyMIt.#=zsvyrSws=(#=zGuSEinf51GwaWgcLur1eBnuvV4IW67glflpLC87c2X4L& #=zrOxRH4A=)\n at #=z_0eXijCbnDc9xPTRuVmH$rpkyMIt.#=zsvyrSws=()\n at Aspose.Pdf.Devices.ImageDevice.#=zsvyrSws=(Page #=zyEDetV4=)\n at Aspose.Pdf.Devices.JpegDevice.Process(Page page, Stream output)\n at AsposeTest.Controllers.HomeController.GetImagesFromPdf() in /Users/Imam/Documents/Test/AsposeTest/Controllers/HomeController.cs:line 68”

Thanks

@imamrazi

Thank you for further details.

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

@imamrazi

Thank you for being patient.

We have logged an investigation ticket with ID PDFNET-46048 in our issue management system for further investigations and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.