Custom Text Selection Quads to Rect

21 views
Skip to first unread message

ASR

unread,
Aug 20, 2019, 2:00:55 PM8/20/19
to PDFTron PDFNet SDK
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::vector<pdftron::PDF::QuadPoint> vQuads;
Page first_page;
vQuads = pm_ViewCtrl->GetSelection().GetQuads();
first_page = pm_ViewCtrl->GetPage(pm_ViewCtrl->GetSelection().GetPageNum());

ElementReader reader;

std::vector<pdftron::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;
}

Ryan

unread,
Oct 1, 2019, 2:11:10 PM10/1/19
to PDFTron PDFNet SDK
Please see this forum post on how to convert Quads (OBB) to Rect (AABB)
Reply all
Reply to author
Forward
0 new messages