Skip to content

Commit

Permalink
Added the Find Text sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyalakshmit committed Aug 29, 2023
1 parent df6654c commit c20affd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Text/Find-text-in-PDF-document/.NET/Find-text-in-PDF-document.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-in-PDF-document", "Find-text-in-PDF-document\Find-text-in-PDF-document.csproj", "{A3B398F4-E8B9-4522-943B-12037BE3A417}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3B398F4-E8B9-4522-943B-12037BE3A417}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3B398F4-E8B9-4522-943B-12037BE3A417}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3B398F4-E8B9-4522-943B-12037BE3A417}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3B398F4-E8B9-4522-943B-12037BE3A417}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C22A03D0-BE02-4878-B421-6975254E28C6}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Find_text_in_PDF_document</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.NET" Version="22.2.11" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// See https://aka.ms/new-console-template for more information

using Syncfusion.Pdf.Parsing;
using static System.Net.Mime.MediaTypeNames;

string matchText = string.Empty;
//Load an existing PDF document.
FileStream docStream = new FileStream("../../../Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

//Returns page number and rectangle positions of the text maches.
Dictionary<int, List<Syncfusion.Drawing.RectangleF>> matchRects = new Dictionary<int, List<Syncfusion.Drawing.RectangleF>>();
loadedDocument.FindText("document", out matchRects);

for (int i = 0; i < loadedDocument.Pages.Count; i++)
{
List<Syncfusion.Drawing.RectangleF> rectCoords = matchRects[i];
matchText = "First Occurrence: X:" + rectCoords[0].X + "; Y:" + rectCoords[0].Y + "; Width:" + rectCoords[0].Width + "; Height:" + rectCoords[0].Height + Environment.NewLine +
"Second Occurrence: X:" + rectCoords[1].X + "; Y:" + rectCoords[1].Y + "; Width:" + rectCoords[1].Width + "; Height:" + rectCoords[1].Height + Environment.NewLine +
"Third Occurrence: X:" + rectCoords[2].X + "; Y:" + rectCoords[2].Y + "; Width:" + rectCoords[2].Width + "; Height:" + rectCoords[2].Height + Environment.NewLine +
"Fourth Occurrence: X:" + rectCoords[3].X + "; Y:" + rectCoords[3].Y + "; Width:" + rectCoords[3].Width + "; Height:" + rectCoords[3].Height + Environment.NewLine;
}

//Close the document.
loadedDocument.Close(true);

Console.WriteLine(matchText);
Console.ReadLine();

0 comments on commit c20affd

Please sign in to comment.