I'm investigating a problem in iText (tested with recent versions of iText Core 9.5.0+ and pdfSweep 5.0.5+ and java 21) when extracting a monochrome CCITT image from a PDF like this above:
<<
/BitsPerComponent 1
/BlackIs1 true
/ColorSpace /DeviceGray
/Decode [0 1]
/DecodeParms <<
/Columns 1205
/K 0
>>
/Filter /CCITTFaxDecode
/Height 1706
/Subtype /Image
/Width 1205
>>
Using iText:
PdfImageXObject image = ...;
BufferedImage img = image.getBufferedImage();
// or
byte[] png = image.getImageBytes(true);
the resulting image appears stretched/deformed.
This is the original image:
and this is the extracted image with the iText:
The result is that the image stretched appears also in case of redaction with pdfSweep.
In practical terms, it looks as if every row is shifted by the number of missing bits needed to make the row length a multiple of 8 (3 bits in this case).
With pdfbox the image is extracted correctly:
PDImageXObject image = ....
BufferedImage bi = image.getImage();
Can you help me?
Thanks