Custom Text Selection Quads to Rect

Hi,

I am playing with implementing some text extraction logic in my CopySelectedText() function

I used pm_ViewCtrl->GetSelection().GetQuads() to load a std::vector<pdftron::PDF::QuadPoints)

Trying to use the ReadTextFromRect(ElementReader& reader, const Rect& pos, UString& srch_str) from the example code but am not clear how to go from Quads to Rect

my current code sort of works but more text is returned from ReadTextFromRect than I expect.

Can anyone point me to my error?

bool CopySelectedText(HWND hWnd,int iMode)

{
if (!OpenClipboard(hWnd)) return false;
bool bReturn = false;
HGLOBAL hGM = NULL;
EmptyClipboard();

UString TextSelected;

std::vectorpdftron::PDF::QuadPoint vQuads;
Page first_page;

vQuads = pm_ViewCtrl->GetSelection().GetQuads();
first_page = pm_ViewCtrl->GetPage(pm_ViewCtrl->GetSelection().GetPageNum());

ElementReader reader;

std::vectorpdftron::PDF::QuadPoint::const_iterator iIter;
for (iIter = vQuads.begin(); iIter != vQuads.end(); ++iIter)
{
Rect textRect((*iIter).p1.x, (*iIter).p1.y, (*iIter).p3.x, (*iIter).p3.y);

UString s1 = ReadTextFromRect(first_page, textRect, reader);

sprintf(szErrBuf, “Selected Text <%s>”, s1.ConvertToAscii().c_str() );
MessageBox(NULL, szErrBuf, “SELECTED TEXT”, MB_OK);

}

CloseClipboard();
return bReturn;

}

Please see this forum post on how to convert Quads (OBB) to Rect (AABB)

https://groups.google.com/d/msg/pdfnet-sdk/k59KeYvXDIo/g2cMSF-aDAAJ