Some test text!

keyboard_arrow_down

Get started

keyboard_arrow_down

Xamarin.Forms

keyboard_arrow_down

Fundamentals

keyboard_arrow_down

Document Viewer

keyboard_arrow_down

Document Viewer components

keyboard_arrow_down

Annotation and collaboration

keyboard_arrow_down

Advanced customization

keyboard_arrow_down

Conversion

keyboard_arrow_down

Parsing and extraction

keyboard_arrow_down

Digital signatures

keyboard_arrow_down

Form filling

keyboard_arrow_down

Search

keyboard_arrow_down

Redaction

keyboard_arrow_down

Advanced topics

keyboard_arrow_down

Reference

keyboard_arrow_down

PDF Processing API

Text search

In this document
chevron_rightPrerequisites
chevron_rightAdd text search using UI component
chevron_rightSearch results view
This tutorial only applies to Xamarin.Android.

Text search functionality can be added to your viewer using the text search UI component. Alternatively, you can programmatically perform text search in PDFViewCtrl.

linkPrerequisites

linkAdd text search using UI component

PDFTron provides SearchToolbar and FindTextOverlay as utility classes for implementing text search in your document viewer. Here is a short guide on adding text search to your activity:

  1. Add the search controls to your layout, a simple example will be something like:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
        <pdftron.PDF.Controls.SearchToolbar
            android:id="@+id/searchtoolbar"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:contentInsetStart="@dimen/second_keyline"
            android:background="?attr/colorPrimary"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:navigationIcon="@drawable/ic_arrow_back_white_24dp" />
        <pdftron.PDF.PDFViewCtrl
            android:id="@+id/pdfviewctrl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scrollbars="vertical|horizontal" />
      </LinearLayout>
      <pdftron.PDF.Controls.FindTextOverlay
            android:id="@+id/find_text_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"/>
    </RelativeLayout>
  2. In onCreate of your activity, set up your SearchToolbar and FindTextOverlay:

  3. Show the layout

Now when running the app, you will see a toolbar that allows you to enter search terms as well as an overlay on top of the PDFViewCtrl that navigates among search results.

linkSearch results view

SearchResultsView class enables users to easily search for a query and see the results.

To set up your layout for a SearchResultsView, add an element to your XML layout as follows:

<com.pdftron.pdf.controls.SearchResultsView
    android:id="@+id/searchResultsView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Then, you need to set SearchResultsListener to receive a callback when

  • An item from the search results is clicked
  • A full-text search is started and result has not yet been ready
  • A search is found