ComPDF React Native - v3.0.0
    Preparing search index...

    Class CPDFTextSearcher

    Index

    Constructors

    Methods

    • Searches for the specified text in the current PDF document.

      This method performs a text search in the currently loaded PDF document and returns an array of results. Each result is represented by a CPDFTextRange object containing the page index, location, length, and internal range index.

      Parameters

      • searchText: string

        The text string to search for in the document.

      • options: CPDFSearchOptions

        Optional search parameters such as case sensitivity, whole word match, etc.

      Returns Promise<CPDFTextRange[]>

      A promise that resolves to an array of CPDFTextRange objects representing the matched text results.

      const textSearcher = pdfReaderRef.current?._pdfDocument.textSearcher();
      const results = await textSearcher.searchText("example", new CPDFSearchOptions());

      if (results.length > 0) {
      const resultText = await textSearcher.getText(results[0]);
      }
    • Selects a specific search result and highlights it in the PDF viewer.

      This method is typically used when a user taps on a search result or navigates through search results using next/previous controls.

      Parameters

      Returns Promise<void>

      A promise that resolves once the selection is applied.

      const results = await textSearcher.searchText("example", options);
      if (results.length > 0) {
      await textSearcher.selection(results[0]);
      }
    • Clears all search results and removes any highlights from the PDF viewer.

      This is typically called when closing the search UI or performing a new search.

      Returns Promise<void>

      A promise that resolves when the search state is cleared.

      await textSearcher.clearSearch();
      
    • Retrieves the text content from a specific text range.

      Can be used to extract the original matched text or additional surrounding content by using the expanded() method on a CPDFTextRange.

      Parameters

      Returns Promise<string>

      A promise that resolves with the extracted text content.

      const results = await textSearcher.searchText("example", options);
      const originalText = await textSearcher.getText(results[0]);
      const expandedText = await textSearcher.getText(results[0].expanded(10, 10));