File example: click here
Using great solution from this topic I try to extract visible text. Attached document has very small text which maybe cause this clip path problem where some part of letters could be hidden. For such rotated text I changed code from linked issue a bit:
@Override
protected void processTextPosition(TextPosition text) {
PDGraphicsState gs = getGraphicsState();
Vector center = getTextPositionCenterPoint(text);
Area area = gs.getCurrentClippingPath();
if (area == null || area.contains(lowerLeftX + center.getX(), lowerLeftY + center.getY())) {
nonStrokingColors.put(text, gs.getNonStrokingColor());
renderingModes.put(text, gs.getTextState().getRenderingMode());
super.processTextPosition(text);
}
}
private Vector getTextPositionCenterPoint(TextPosition text) {
Matrix textMatrix = text.getTextMatrix();
Vector start = textMatrix.transform(new Vector(0, 0));
Vector center = null;
switch (rotation) {
case 0:
center = new Vector(start.getX() + text.getWidth()/2, start.getY());
break;
case 90:
center = new Vector(start.getX(), start.getY() + text.getWidth()/2);
break;
case 180:
center = new Vector(start.getX() - text.getWidth()/2, start.getY());
break;
case 270:
center = new Vector(start.getX(), start.getY() - text.getWidth()/2);
break;
default:
center = new Vector(start.getX() + text.getWidth()/2, start.getY());
break;
}
return center;
}
What I'm trying to do - get character X-center point depending on rotation (I'm aware that sometimes this does not work because of text direction, however here it looks like this is not the case) But after applying this solution I have 2nd, 3rd and some others rows in the bottom skipped because of clip path. I'm wondering where is my mistake. Thanks in advance!