Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||||||
Version 3.0 has brought in more functionality and power to text search functions. There are now two overloads for the TgtPDFDocument.SearchAll method.
public procedure SearchAll( const ASearchText: string; Aoptions: TgtSearchTypes; SearchEvent: TgtSearchEvent; StartPage: Integer = 1 ); overload; public procedure SearchAll( const ASearchText: string; Aoptions: TgtSearchTypes; var SearchList: TgtStringList; StartPage: Integer = 1 ); overload;
These methods return a list of text strings that contain a specified search string. The second overload has an extra argument StartPage for the number of page from which the search needs to start, default being the first page. Otherwise, it is not different from v2.x.
This article will focus on the first overload. The first overload uses a new event TgtSearchEvent.
TgtSearchEvent = procedure (
Sender: Tobject;
List: Tstrings;
PageNum: Integer;
var Continue: Boolean) of object;
This event will be called after a page (referred by PageNum) has been searched. The text strings that contain the search string will be returned in the string list List.
The argument of interest however is boolean Continue. By setting its value, you have the option of cancelling the entire search operation after a page has been searched.
For this article, a sample VCL forms application has been created. The main form contains a TgtPDFDocument object, TgtPDFViewer object, a list box, and several buttons and edit boxes.

After a document is loaded, the application is ready to search the document for a search string entered by the user. The search button caption changes to "Cancel" when the search is in operation. If the user clicks while the button is in this state, then the search is cancelled.
The application uses the SearchAll() method to search the document. The method calls an event handler after each page is searched. When the user cancels the search, the event handler sets the Continue parameter to false and the SearchAll() is halted.
| Privacy | Legal | Feedback | Newsletter | © 2002-2010 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.