ststeiger/PdfSharpCore

Problem adding grayscale jpeg file to pdf document with ImageSharp 2.x

Edminsson opened this issue · 1 comments

I have a jpg image (JFIF) that uses grayscale (has one color component according to exiftool). Everything works well when I add my image to a pdf document with the current version of PdfSharpCore. But to fix the vulnerabilities in SixLabors.ImageSharp I've updated the ImageSharp nuget to version 2.1.8. When I add the same image to a pdf document the resulting pdf is not displayed correctly and Adobe Acrobat Reader says "Unsifficient data for an image". In version 1.0.4 of ImageSharp the grayscale image is converted to use 3 color components and then ColorSpace DeviceRGB seems to work, but in version 2.x.x the Image is not converted and it keeps the single color component and then ColorSpace DeviceRGB does not seem to work. I've manually changed the ColorSpace of my faulty pdf to DeviceGray and then it works.
As far as I understand JFIF images always use DeviceRGB when added to a pdfDocument in PdfSharpCore.

The latest version of SixLabors.ImageSharp behaves the same way.
Fortunately @TonyValenti has created a PR (#427) that handles this problem. In the .NET version of the class ImageSharpImageSourceImpl he calls ImageSharps SaveAsJpeg method asking for an image with the correct ColorType thus solving the problem.