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).
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();
}
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.