for (int i = 0; i < pageArticles.size() && foundArticleDivisionIndex == -1; i++)
{
PDThreadBead bead = pageArticles.get(i);
if (bead != null)
{
PDRectangle rect = bead.getRectangle();
if (rect.contains(x, y))
{
foundArticleDivisionIndex = i * 2 + 1;
}
else if ((x < rect.getLowerLeftX() ||
y < rect.getUpperRightY()) &&
notFoundButFirstLeftAndAboveArticleDivisionIndex == -1)
{
notFoundButFirstLeftAndAboveArticleDivisionIndex = i * 2;
}
else if (x < rect.getLowerLeftX() &&
notFoundButFirstLeftArticleDivisionIndex == -1)
{
notFoundButFirstLeftArticleDivisionIndex = i * 2;
}
else if (y < rect.getUpperRightY() &&
notFoundButFirstAboveArticleDivisionIndex == -1)
{
notFoundButFirstAboveArticleDivisionIndex = i * 2;
}
}