How do I obtain lowest element's Y coordinate on a PDF page?

Q: In order to sign a PDF document I wrote a method that adds text at
the end of the last page of the PDF document. To compute mtx.m_v for
the added text: I wrote the following code (mtx is of type
Common::Matrix2D):

ElementReader reader;
reader.Begin(lastPage);

Element element;
Rect box;
while ((element = reader.Next()) != NULL)
        element.GetBBox(box);

m_lastPDFElementVPoint = box.GetY1();

This worked well for most of the PDF documents that I deal with.
But for some PDF files I got wrong "last v point" and therefore the
signature (prefixed with a line) was added in the middle of the text
and not at the end of the page. It seems that m_lastPDFElementVPoint =
box.GetY1() doesn't gives me the correct end of text in this case.
What is the correct code to get the last element (of any kind) in a
page and then to get its Y1 value?
----------
A: Unfortunately in PDF, elements are not necessarily sorted in Y
order you would need to keep a track of the lowest Y coordinate.
Something like:

while ((element = reader.Next()) != NULL) {
   if (element.GetBBox(box)) {
       if (bbox.y1<min_y) min_y = bbox.y1;
   }
}

Also please keep in mind that your current code will not process Form
XObjects and will also process paths and images (which you may want to
skip). If you are primarily interested in text you could use GetBBox
() on text elements returned by pdftron.PDF.TextExtractor (for example
please see TextExtract sample project - http://www.pdftron.com/pdfnet/samplecode.html#TextExtract).