ByteScout PDF Extractor SDK - C# - Find Phone Number (with Regex) - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Extractor SDK – C# – Find Phone Number (with Regex)

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Extractor SDK – C# – Find Phone Number (with Regex)

ByteScout PDF Extractor SDK – C# – Find Phone Number (with Regex)

Program.cs

using Bytescout.PDFExtractor;
using System;

namespace FindPhoneNumberRegex
{
class Program
{
static void Main(string[] args)
{
try
{
// Create Bytescout.PDFExtractor.TextExtractor instance
using (TextExtractor extractor = new TextExtractor())
{
extractor.RegistrationName = “demo”;
extractor.RegistrationKey = “demo”;

// Load sample PDF document
extractor.LoadDocumentFromFile(“samplePDF_PhoneNo.pdf”);

extractor.RegexSearch = true; // Enable the regular expressions

int pageCount = extractor.GetPageCount();

// Search through pages
for (int i = 0; i < pageCount; i++) { // Search phoneNos in format 202-555-0130 string regexPattern = "[0-9]{3}-[0-9]{3}-[0-9]{4}"; // See the complete regular expressions reference at https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx // Search each page for the pattern if (extractor.Find(i, regexPattern, false)) { do { // Iterate through each element in the found text foreach (ISearchResultElement element in extractor.FoundText.Elements) { Console.WriteLine("Found Phone No: " + element.Text); } } while (extractor.FindNext()); } } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } Console.WriteLine(); Console.WriteLine("Press enter key to continue..."); Console.ReadLine(); } } } [/csharp]


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next