PDF to PNG conversion in .NET on Linux

Hi. There is a problem with a conversion of specific PDF files to any image format on Linux which results in an unhandled(uncatchable) exception which crashes the whole process.

: ** (process:1): WARNING **: 21:23:27.964: Path conversion requested 62302240 bytes (1144 x 13615). Maximum size is 8388608 bytes.
: ERROR:region.c:1155:GdipCombineRegionPath: assertion failed: (region->bitmap)

The issue is probably a result of high quality PDF and limitations of libgdiplus. I could not find PdfLoadOptions/ImageConvertOptions setting to overcome this issue. It would be great to have some quality optimization options in PdfLoadOptions(before actual conversion).

File: frist_page.pdf (1.0 MB)

Ubuntu 20, .NET 5, GroupDocs.Conversion 21.8.0/21.5.0.

1 Like

@IhorC

Could you please share the sample code? We’ll then look into this scenario.

Code is straight forward. Width = 150, Height = 180. Other PDFs are working fine.

        public byte[] ConvertToPng(byte[] source, int width, int height)
        {
            var options = new ImageConvertOptions
            {
                Format = ImageFileType.Png,
                Width = width,
                Height = height,
                PageNumber = 1,
                PagesCount = 1,
                Pages = new List<int> { 1 }
            };

            return Convert(source, options);
        }

        private byte[] Convert(byte[] source, ConvertOptions options)
        {
            using var sourceStream = new MemoryStream(source);
            using var outputStream = new MemoryStream();

            using var converter = new Converter(() => sourceStream);

            converter.Convert(() => new MemoryStream(), resultStream => 
 resultStream.CopyTo(outputStream), options);

            _logger.LogInformation("PngConverter has finished png file generation");

            outputStream.Seek(0, SeekOrigin.Begin);
            return outputStream.ToArray();
        }

@IhorC

This issue is under investigation with ticket ID CONVERSIONNET-4830. You’ll be notified in case of any update.

@IhorC

We couldn’t reproduce this particular exception when tested on Ubuntu 20.4. However, there was another issue - the resultant image was black and white (looking like 1bit). This is resolved in the latest API version 20.11 (the public release is expected by month end).
Pease note that libgdiplus should be installed on Ubuntu using sudo apt-get install libgdiplus.
If you still face this issue, we’d recommend you to share a working sample, so we can reproduce this issue at our end.

A post was split to a new topic: PDF to PNG conversion issue on CentOS 7

This issue can be fixed with updating libgdiplus to the latest version. See the related/split topic.

Do NOT use

sudo apt-get install libgdiplus

as stated in GroupDocs documentation. It will install v4.2-2 but v6.0.1+ is required.

Unfortunately, the default apt repository contains an outdated version of ibgdiplus package.

Documentation for GroupDocs should be updated.

1 Like

@IhorC

Glad to know that the issue is fixed. We’ll update it in the documentation as well.