This functionality is supported only if you are using the Classic Agent.
The sample test script (ocrtest.t) includes a test case (shown below) that extracts the text from a Microsoft Word document. Microsoft Office controls are recognized as custom windows (CustomWin) by Silk Test Classic, so you cannot use the 4Test GetText() method to get the text. However, you can use the OcrGetTextFromWnd() function to capture a bitmap of the document window and convert it to text. Notice that, if necessary, the test case will scroll through the document and capture multiple bitmaps.
testcase GetOcrAPIDocText (STRING sDocument) MSWord.SetActive () // Open the specified document. MSWord.OpenDoc (sDocument) // Capture each page in succession. // Start at the top and page down until the bottom is reached LIST OF STRING lsResults = {} STRING sResult = NULL INTEGER iMaxPos, iCurPos, iLastPos = -1 INTEGER iResLen, iTotalLen = 0 withoptions BindAgentOption (OPT_REQUIRE_ACTIVE, FALSE) BindAgentOption (OPT_VERIFY_ACTIVE, FALSE) TheDoc.ScrollBarV.ScrollToMin () iCurPos = TheDoc.ScrollBarV.GetPosition () iMaxPos = TheDoc.ScrollBarV.GetRange ().iMax while TRUE // If we are capturing the first page, then eliminate the flashing cursor // by highlighting the current character. Otherwise, page down to capture // the next page. MSWord.SetActive () if sResult == NULL // First page MSWord.TypeKeys ("<Shift-Right>") else // Page down withoptions BindAgentOption (OPT_REQUIRE_ACTIVE, FALSE) BindAgentOption (OPT_VERIFY_ACTIVE, FALSE) TheDoc.ScrollBarV.ScrollByPage (1) iLastPos = iCurPos iCurPos = TheDoc.ScrollBarV.GetPosition () // If scrolling did not change the scrollbar position, then // we have reached the bottom. Also, if we scrolled up instead // of down by paging down, then we have reached the bottom. if iCurPos <= iLastPos break // Convert the bitmap for the current view. iResLen = OcrGetTextFromWnd (sResult, TheDoc.CurrentView) if sResult != NULL ListAppend (lsResults, sResult) iTotalLen = iTotalLen + Len (sResult) ResPrintList ("Document text ({iTotalLen} chars)", lsResults)
If neither of the 4Test functions in OCR.inc provides the functionality that you need, you can call the DLL functions in the Borland DLL, SgOcrLib.dll, through directly using the function declarations in SgOcrLib.inc. The DLL functions are documented at the top of SgOcrLib.inc. The functions in OCR.inc can serve as an example of how to use the DLL functions.