These sample source codes can be used to find text in PDF files and get coordinates using Bytescout PDF Extractor SDK.

Select your programming language:

ASP.NET

using System;
using System.Drawing;
using Bytescout.PDFExtractor;

<span data-scayt_word="namespace" data-scaytid="3">namespace</span> <span data-scayt_word="FindText" data-scaytid="4">FindText</span>
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, <span data-scayt_word="EventArgs" data-scaytid="5">EventArgs</span> e)
		{
			// This test file will be copied to the project directory on the pre-build event (see the project properties).
			String <span data-scayt_word="inputFile" data-scaytid="6">inputFile</span> = Server.MapPath("sample1.pdf");

			// Create Bytescout.PDFExtractor.TextExtractor instance
			<span data-scayt_word="TextExtractor" data-scaytid="8">TextExtractor</span> extractor = new <span data-scayt_word="TextExtractor" data-scaytid="9">TextExtractor</span>();
			extractor.RegistrationName = "demo";
			extractor.RegistrationKey = "demo";
			
			// Load sample PDF document
			extractor.LoadDocumentFromFile(<span data-scayt_word="inputFile" data-scaytid="7">inputFile</span>);

			Response.Clear();
			Response.ContentType = "text/html";

			Rectangle location;
			<span data-scayt_word="int" data-scaytid="10">int</span> <span data-scayt_word="pageIndex" data-scaytid="11">pageIndex</span>;

			Response.Write("Searching for "<span data-scayt_word="ipsum" data-scaytid="15">ipsum</span>" string:

");
			
			// Search for "<span data-scayt_word="ipsum" data-scaytid="16">ipsum</span>" string
			if (extractor.Find("<span data-scayt_word="ipsum" data-scaytid="17">ipsum</span>", out <span data-scayt_word="pageIndex" data-scaytid="12">pageIndex</span>, out location))
			{
				do
				{
					Response.Write("Found on page " + <span data-scayt_word="pageIndex" data-scaytid="13">pageIndex</span> + " at location " + location.ToString() + "
");

				} while (extractor.FindNext(out <span data-scayt_word="pageIndex" data-scaytid="14">pageIndex</span>, out location));
			}

			Response.End();
		}
	}
}

C#

using System;
using System.Drawing;
using Bytescout.PDFExtractor;

<span data-scayt_word="namespace" data-scaytid="18">namespace</span> <span data-scayt_word="FindText" data-scaytid="19">FindText</span>
{
	class Program
	{
		static void Main(string[] <span data-scayt_word="args" data-scaytid="43">args</span>)
		{
			// Create Bytescout.PDFExtractor.TextExtractor instance
			<span data-scayt_word="TextExtractor" data-scaytid="20">TextExtractor</span> extractor = new <span data-scayt_word="TextExtractor" data-scaytid="21">TextExtractor</span>();
			extractor.RegistrationName = "demo";
			extractor.RegistrationKey = "demo";

			// Load sample PDF document
			extractor.LoadDocumentFromFile("sample1.pdf");
			
			<span data-scayt_word="int" data-scaytid="22">int</span> <span data-scayt_word="pageCount" data-scaytid="48">pageCount</span> = extractor.GetPageCount();
			<span data-scayt_word="RectangleF" data-scaytid="50">RectangleF</span> location;

			for (<span data-scayt_word="int" data-scaytid="23">int</span> i = 0; i < <span data-scayt_word="pageCount" data-scaytid="49">pageCount</span>; i++)
			{
				// Search each page for "<span data-scayt_word="ipsum" data-scaytid="24">ipsum</span>" string
				if (extractor.Find(i, "<span data-scayt_word="ipsum" data-scaytid="25">ipsum</span>", false, out location))
				{
					do
					{
						Console.WriteLine("Found on page " + i + " at location " + location.ToString());

					}
					while (extractor.FindNext(out location));
				}
			}
			
			Console.WriteLine();
			Console.WriteLine("Press any key to continue...");
			Console.ReadLine();
		}
	}
}

VB.NET

Imports System.Drawing
Imports Bytescout.PDFExtractor

Class Program
	Friend Shared Sub Main(<span data-scayt_word="args" data-scaytid="53">args</span> As String())
		' Create Bytescout.PDFExtractor.TextExtractor instance
		Dim extractor As New <span data-scayt_word="TextExtractor" data-scaytid="34">TextExtractor</span>()
		extractor.RegistrationName = "demo"
		extractor.RegistrationKey = "demo"

		' Load sample PDF document
		extractor.LoadDocumentFromFile("sample1.pdf")

		Dim location As Rectangle
		Dim <span data-scayt_word="pageIndex" data-scaytid="35">pageIndex</span> As Integer

		' Search for "<span data-scayt_word="ipsum" data-scaytid="39">ipsum</span>" string
		If extractor.Find("<span data-scayt_word="ipsum" data-scaytid="40">ipsum</span>", <span data-scayt_word="pageIndex" data-scaytid="36">pageIndex</span>, location) Then
			Do
                Console.WriteLine("Found on page " & <span data-scayt_word="pageIndex" data-scaytid="37">pageIndex</span> & " at location " & location.ToString())
            Loop While extractor.FindNext(<span data-scayt_word="pageIndex" data-scaytid="38">pageIndex</span>, location)
		End If

		Console.WriteLine()
		Console.WriteLine("Press any key to continue...")
		Console.ReadLine()
	End Sub
End Class

VBScript

' Create Bytescout.PDFExtractor.TextExtractor object
Set extractor = <span data-scayt_word="CreateObject" data-scaytid="74">CreateObject</span>("Bytescout.PDFExtractor.TextExtractor")
extractor.RegistrationName = "demo"
extractor.RegistrationKey = "demo"

' Load sample PDF document
extractor.LoadDocumentFromFile("....sample1.pdf")

' Get page count

<span data-scayt_word="pageCount" data-scaytid="70">pageCount</span> = extractor.GetPageCount()

For i=0 to <span data-scayt_word="PageCount-1" data-scaytid="76">PageCount-1</span> 
 
 If extractor.Find(i, "<span data-scayt_word="ipsum" data-scaytid="71">ipsum</span>", false) Then ' parameters are: page index, string to find, case sensitivity
 	Do
 		<span data-scayt_word="MsgBox" data-scaytid="79">MsgBox</span> "Found word '<span data-scayt_word="ipsum" data-scaytid="72">ipsum</span>' on page #" & CStr(i) & " at left=" & CStr(extractor.GetFoundTextRectangle_Left) & "; top=" & CStr(extractor.GetFoundTextRectangle_Top) & "; width=" & CStr(extractor.GetFoundTextRectangle_Width) & "; height=" & CStr(extractor.GetFoundTextRectangle_Height)
  	Loop While extractor.FindNext
 End If

Next

MsgBox "Done"

Set extractor = Nothing