PDFtoolkit VCL
Edit, enhance, secure, merge, split, view, print PDF and AcroForms documents
Compatibility
Delphi C++Builder

New SearchAll Method In PDFtoolkit v3.x

Learn how to provide an option to cancel a text search operation in the middle.
By V. Subhash

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.

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.