#28591

As I wrote it was only schematic code. Put there some debug output and check if the condition is true at some point.

if ( actualRatio < desiredRatio * 1.1 && actualRatio > desiredRatio * 0.9 ) {
break;
}

The resulting document is 0 bytes, as it is reset by the line:

baos.reset();

Probably it makes sense to place the line just after

for ( int i = 0; i < 40; i++ ) {