Fail to convert PDF to PNG [Process(pdfDocument.Pages[pageNo], imageStream) method fails]

Hi Im facing this same thing in linux container. Im converting PDF to image. It will work fine in Windows but sorry for linux. im using aspose Aspose.PDF 20.8.0

System.OutOfMemoryException: Out of memory.
at System.Drawing.Graphics.get_ClipBounds()
at #=zSK246xR0STLCCf_RpAEVwH0NEAig$Scziu7SfiM=.#=zZ2ut6Haa31O5(#=zVUQqnLiJKanv_2TqYJoDVxjRKtZhUwDFhA== #=zQVvbOr0=)
at #=z8JzRwMDnRYyPoUkGXOTktM9trhIXgYkw427agUEuJHAgR0sVFw==.#=zjh146I1ljGZI(#=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq #=zC6IqXOI=)
at #=zw34YIMWWW$i4N0k7rtWKKRUws3dYC_xU0nPAue8LRQtK.#=zHIU4q42Gxrmp(#=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq #=zC6IqXOI=)
at #=zw34YIMWWW$i4N0k7rtWKKRUws3dYC_xU0nPAue8LRQtK.#=z$Yg4egs=(#=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq #=zC6IqXOI=)
at #=zJRoqtKfEX723e63CZPklJ_$$uDoryYUCCnC57eCjxMuB.#=zdOb_qo3nnEeT(#=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq #=zC6IqXOI=, List`1 #=zu3zJp7EPvQVm)
at #=zJRoqtKfEX723e63CZPklJ_$$uDoryYUCCnC57eCjxMuB.#=zOVYCjv4=(#=zCu8FNLfeUBNURJFTmzd1xghAdCdS #=zzftdz3o=, #=zAoiaTHyEQCAStHFalUSLEr1YFcm5oC49Fw== #=zkNijddA=, #=zU9Vh7gAU4ZMIdpayEFMv6gxhqTuqYBtuz8Oe2ME= #=zxurZdh8=, #=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq& #=zC6IqXOI=)
at #=zYywSfhaJEevNXSPkTYIhcpTfdq2M.#=zRovHUxA=(#=zJ7mqFOeX8tyl7GEYBXHhtqrARUJU7FUlNWcI_rNzPOUq& #=zC6IqXOI=)
at #=zYywSfhaJEevNXSPkTYIhcpTfdq2M.#=zRovHUxA=()
at Aspose.Pdf.Devices.ImageDevice.#=zRovHUxA=(Page #=zkNijddA=)
at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)

** (process:1): WARNING **: Path conversion requested 34759680 bytes (2480 x 3504). Maximum size is 8388608 bytes.

Here is my code:

 public ImageData GenerateImage1(byte[] pdfData, int pageNo)
        {

            using (var imageStream = new MemoryStream())
            {
                using (var pdfDocument = new Document(new MemoryStream(pdfData), isManagedStream: true))
                {
                    
                    Resolution resolutionLow = new Resolution(300);
                    PngDevice pngDeviceTempTest = new PngDevice(resolutionLow);

                    //following will casing error
                    pngDeviceTempTest.Process(pdfDocument.Pages[pageNo], imageStream);


                    pdfDocument.Dispose();
                    var data = new ImageData()
                    {
                        MimeType = "image/png",
                        Size = imageStream.Length,
                        Data = imageStream.ToArray()
                    };
                    return data;
                }
            }
        }

If the PDF has an image which is stretched through the page this will trigger but if the image is a small one it will work.

Is there a limitation to image size ? Why am i getting this? Appreciate if any help on this.

Thanks !!!.

@AnushkaDSC

Would you please share your sample PDF and complete environment details i.e. OS name and version, Application type, etc. We will test the scenario in our environment and address it accordingly.

Doc1.pdf (493.8 KB)
We have our Rest service hosted in a linux container.

@asad.ali

Kernel Version: 4.4.180-94.100-default
Operating System: SUSE Linux Enterprise Server 12 SP3
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 31.05GiB

@AnushkaDSC

Thanks for sharing requested information.

We have logged an investigation ticket as PDFNET-48671 in our issue tracking system for this case. We will look into its details and keep you informed with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali Thanks you for the reply. Will be waiting for an update on this issue.

FYI: Im using .NET Core 2.1

@AnushkaDSC

We have logged this information as well along with the ticket and let you know as soon as it is resolved.

I have the same error.I want to know more

I have the same error.I want to know more about this problem

@Dango

We are afraid that the earlier logged ticket is not resolved due to other issues in the queue. We have however recorded your concerns and will surely inform you as soon as the issue is fixed. Please spare us some time.

We are sorry for the inconvenience.

Hello I’m also running into this issue. Is there a status update on PDFNET-48671?

I just found this blog post and this other forum post and I’ll try those options too.

@nchryslery

Sure, you can please try it and let us know in case you observe any issues. Furthermore, we will let you know once the earlier logged ticket is resolved.

Hi @asad.ali it’s still not working when I include both Aspose.PDF and Aspose.Drawing in a project. It works fine in VS2019, but in Linux running via dotnet command, I see the same Gdip error noted in the blog post:

Unhandled exception. System.Exception: Unable to process the PDF: The type initializer for 'Gdip' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies.

Does Aspose.PDF work with Aspose.Drawing? Can it?

Can I somehow omit the System.Drawing* DLL(s) to get this to work?

Please advise!

@nchryslery

It looks like that libgdiplus package is missing in your system. Please note that Aspose.PDF requries these two packages in order to run correctly in Linux like systems:

  • libgdiplus
  • msttcorefonts

Please try installing them and let us know in case you still notice any issues.

Hi @asad.ali I agree with you, however it is missing on purpose. Please refer to your blog post (linked above) about using Aspose.Drawing instead of System.Drawing.Common, and not needing libgdiplus. How do I get Aspose.PDF to work with Aspose.Drawing?

@nchryslery

You are right. We only suggested to install the packages so that you can run/test Aspose.PDF for .NET. As far as Aspose.Drawing and above linked post is concerned, we request you to create a topic in Aspose.Drawing forum category where the issue will be addressed accordingly.

Furthermore, we are in process to integrate Aspose.Drawing with Aspose.PDF for Linux/Docker environments and we will surely announce it as soon as the task is complete.