PDFDocumentSource allows you to implement text search in a PDF file by matching the search criteria and examining all the words stored in the file through C1TextSearchManager class, member of C1.Xaml.Document namespace. The class provides various methods, such as FindStart to find the first occurrence, FindNext to find the next occurrence, and FindPrevious to find the previous occurrence of the searched text. You can use C1FindTextParams(string text, bool wholeWord, bool matchCase) method to initialize a new instance of C1FindTextParams class with the following parameters:
The following image shows the word searched in a PDF file and the list of matches as search results.
In this sample code, we use the FindStart method on the C1TextSearchManager to find instances of the search text.
XAML |
Copy Code
|
---|---|
<ListView x:Name="listView1" HorizontalAlignment="Left" Width="585" Margin="10,150,0,10"> <ListView.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="#" Margin="5,5,0,0"></TextBlock> <TextBlock Text="Page" Margin="15,5,0,0"></TextBlock> <TextBlock Text="Bounds" Margin="40,5,0,0"></TextBlock> <TextBlock Text="Position" Margin="40,5,0,0"></TextBlock> <TextBlock Text="NearText" Margin="40,5,0,0"></TextBlock> </StackPanel> </DataTemplate> </ListView.HeaderTemplate> <ListView.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding ID}" Margin="5,0,0,0"></TextBlock> <TextBlock Text="{Binding Page}" Margin="15,0,0,0"></TextBlock> <TextBlock Text="{Binding Bounds}" Margin="30,5,0,0"></TextBlock> <TextBlock Text="{Binding Position}" Margin="30,5,0,0"></TextBlock> <TextBlock Text="{Binding NearText}" Margin="30,5,0,0"></TextBlock> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> |