Skip to content

Commit cbba2b5

Browse files
committed
899026 - Added sample to search and highlight all occurrences of text on desired page in PdfViewer
1 parent 517cf32 commit cbba2b5

16 files changed

+566
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="FindAndHighlightTextInDesiredPage.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:FindAndHighlightTextInDesiredPage"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace FindAndHighlightTextInDesiredPage
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{2623E934-BB50-4A59-9E83-FBBFC2E01823}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>FindAndHighlightTextInDesiredPage</RootNamespace>
10+
<AssemblyName>FindAndHighlightTextInDesiredPage</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
<TargetFrameworkProfile />
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<PlatformTarget>AnyCPU</PlatformTarget>
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<PlatformTarget>AnyCPU</PlatformTarget>
31+
<DebugType>pdbonly</DebugType>
32+
<Optimize>true</Optimize>
33+
<OutputPath>bin\Release\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="System" />
40+
<packageReference Include="Syncfusion.PdfViewer.WPF" version="*" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Drawing" />
43+
<Reference Include="System.Xml" />
44+
<Reference Include="Microsoft.CSharp" />
45+
<Reference Include="System.Core" />
46+
<Reference Include="System.Xml.Linq" />
47+
<Reference Include="System.Data.DataSetExtensions" />
48+
<Reference Include="System.Net.Http" />
49+
<Reference Include="System.Xaml">
50+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
51+
</Reference>
52+
<Reference Include="WindowsBase" />
53+
<Reference Include="PresentationCore" />
54+
<Reference Include="PresentationFramework" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ApplicationDefinition Include="App.xaml">
58+
<Generator>MSBuild:Compile</Generator>
59+
<SubType>Designer</SubType>
60+
</ApplicationDefinition>
61+
<Page Include="MainWindow.xaml">
62+
<Generator>MSBuild:Compile</Generator>
63+
<SubType>Designer</SubType>
64+
</Page>
65+
<Compile Include="App.xaml.cs">
66+
<DependentUpon>App.xaml</DependentUpon>
67+
<SubType>Code</SubType>
68+
</Compile>
69+
<Compile Include="MainWindow.xaml.cs">
70+
<DependentUpon>MainWindow.xaml</DependentUpon>
71+
<SubType>Code</SubType>
72+
</Compile>
73+
</ItemGroup>
74+
<ItemGroup>
75+
<Compile Include="Properties\AssemblyInfo.cs">
76+
<SubType>Code</SubType>
77+
</Compile>
78+
<Compile Include="Properties\Resources.Designer.cs">
79+
<AutoGen>True</AutoGen>
80+
<DesignTime>True</DesignTime>
81+
<DependentUpon>Resources.resx</DependentUpon>
82+
</Compile>
83+
<Compile Include="Properties\Settings.Designer.cs">
84+
<AutoGen>True</AutoGen>
85+
<DependentUpon>Settings.settings</DependentUpon>
86+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
87+
</Compile>
88+
<EmbeddedResource Include="Properties\Resources.resx">
89+
<Generator>ResXFileCodeGenerator</Generator>
90+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
91+
</EmbeddedResource>
92+
<None Include="packages.config" />
93+
<None Include="Properties\Settings.settings">
94+
<Generator>SettingsSingleFileGenerator</Generator>
95+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
96+
</None>
97+
</ItemGroup>
98+
<ItemGroup>
99+
<None Include="App.config" />
100+
</ItemGroup>
101+
<ItemGroup>
102+
<PackageReference Include="Syncfusion.PdfViewer.WPF">
103+
<Version>29.2.4</Version>
104+
</PackageReference>
105+
</ItemGroup>
106+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindAndHighlightTextInDesiredPage", "FindAndHighlightTextInDesiredPage.csproj", "{2623E934-BB50-4A59-9E83-FBBFC2E01823}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2623E934-BB50-4A59-9E83-FBBFC2E01823}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2623E934-BB50-4A59-9E83-FBBFC2E01823}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2623E934-BB50-4A59-9E83-FBBFC2E01823}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2623E934-BB50-4A59-9E83-FBBFC2E01823}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindAndHighlightTextInDesiredPage_NET", "FindAndHighlightTextInDesiredPage_NET.csproj", "{9473EACC-57B8-468E-A626-8638F9AB5093}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9473EACC-57B8-468E-A626-8638F9AB5093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9473EACC-57B8-468E-A626-8638F9AB5093}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9473EACC-57B8-468E-A626-8638F9AB5093}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9473EACC-57B8-468E-A626-8638F9AB5093}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Window x:Class="FindAndHighlightTextInDesiredPage.MainWindow"
2+
xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:local="clr-namespace:FindAndHighlightTextInDesiredPage"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
<Grid>
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="30" />
13+
<RowDefinition Height="*" />
14+
</Grid.RowDefinitions>
15+
<Button x:Name="Find" Content="Find Text" Width="80" Click="Find_Click" />
16+
<PdfViewer:PdfViewerControl x:Name="pdfViewer" Grid.Row="1" />
17+
</Grid>
18+
</Window>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Pdf.Interactive;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
using System.Windows.Data;
12+
using System.Windows.Documents;
13+
using System.Windows.Input;
14+
using System.Windows.Media;
15+
using System.Windows.Media.Imaging;
16+
using System.Windows.Navigation;
17+
using System.Windows.Shapes;
18+
19+
namespace FindAndHighlightTextInDesiredPage
20+
{
21+
/// <summary>
22+
/// Interaction logic for MainWindow.xaml
23+
/// </summary>
24+
public partial class MainWindow : Window
25+
{
26+
string file;
27+
int desiredPageIndex = 1;
28+
public MainWindow()
29+
{
30+
InitializeComponent();
31+
this.WindowState = WindowState.Maximized;
32+
#if NETCOREAPP
33+
file = "../../../Data/F#.pdf";
34+
#else
35+
file = "../../Data/F#.pdf";
36+
#endif
37+
//Load the document
38+
pdfViewer.Load(file);
39+
40+
}
41+
42+
private void Find_Click(object sender, RoutedEventArgs e)
43+
{
44+
//Navigating to desired page
45+
pdfViewer.GotoPage(desiredPageIndex + 1);
46+
47+
//To store the occurrences of the text found in the page
48+
List<RectangleF> textbounds = new List<RectangleF>();
49+
50+
//Find the text in the specific page returns true if the text is found in the particular page
51+
bool isMatchFound = pdfViewer.FindText("F#", desiredPageIndex, out textbounds);
52+
if (isMatchFound)
53+
{
54+
foreach(RectangleF rect in textbounds)
55+
{
56+
//Creating the markup annotation
57+
PdfTextMarkupAnnotation markUpannotation = new PdfTextMarkupAnnotation(rect);
58+
PdfLoadedPage page = pdfViewer.LoadedDocument.Pages[desiredPageIndex] as PdfLoadedPage;
59+
//Asigning the type of Text Mark up annotation
60+
markUpannotation.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
61+
//Adding the mark up annotation to the particular page
62+
page.Annotations.Add(markUpannotation);
63+
64+
}
65+
}
66+
67+
68+
}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyCopyright("Copyright © 2025")]
12+
[assembly: AssemblyTrademark("")]
13+
[assembly: AssemblyCulture("")]
14+
15+
// Setting ComVisible to false makes the types in this assembly not visible
16+
// to COM components. If you need to access a type in this assembly from
17+
// COM, set the ComVisible attribute to true on that type.
18+
[assembly: ComVisible(false)]
19+
20+
//In order to begin building localizable applications, set
21+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
22+
//inside a <PropertyGroup>. For example, if you are using US english
23+
//in your source files, set the <UICulture> to en-US. Then uncomment
24+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
25+
//the line below to match the UICulture setting in the project file.
26+
27+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
28+
29+
30+
[assembly: ThemeInfo(
31+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
32+
//(used if a resource is not found in the page,
33+
// or application resource dictionaries)
34+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
35+
//(used if a resource is not found in the page,
36+
// app, or any theme specific resource dictionaries)
37+
)]
38+
39+
40+
// Version information for an assembly consists of the following four values:
41+
//
42+
// Major Version
43+
// Minor Version
44+
// Build Number
45+
// Revision
46+
//

0 commit comments

Comments
 (0)