Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 10, 2025 9:21 pm

Hello,

i am using Spire.PDF in VB.net and i want to find a special text on a page (already got that!) and then get the Coordinates of the found text.
For finding the text on the page i am using this code:

Code: Select all
                   Dim findOptions As PdfTextFindOptions = New PdfTextFindOptions()
                   findOptions.Parameter = TextFindParameter.WholeWord
                   For Each page As PdfPageBase In pdf.Pages
                       Dim finder As PdfTextFinder = New PdfTextFinder(page)
                       finder.Options = findOptions
                       Dim results As List(Of PdfTextFragment) = finder.Find("erteilt")
                       For Each text As PdfTextFragment In results
                           text.HighLight(Color.Green)
                       Next
                   Next


But i am geting stuck of how to get the Coordinates of the found text.
I found this guide on the website for C#, which uses the "Positions"-Function.

But this Guide is for C#, and for example "text.Positions(0)" didnt work in VB.net.
Maybe anyone can help me with this problem?

Thank you in Advance!

seibert_daniel
 
Posts: 1
Joined: Fri Dec 06, 2024 9:45 am

Mon Jan 13, 2025 8:29 am

Hello,

Thank you for your letter. Please use the following code to get the Coordinates of the found text.

Code: Select all
         Dim doc As New PdfDocument()

         ' Load a PDF file
         doc.LoadFromFile("Input.pdf")

         ' Get a specific page
         Dim page As PdfPageBase = doc.Pages(1)

         ' Create a PdfTextFinder object based on the page
         Dim finder As New PdfTextFinder(page)

         ' Specify the find options
         finder.Options.Parameter = TextFindParameter.WholeWord
         finder.Options.Parameter = TextFindParameter.IgnoreCase

         ' Find the instances of the specified text
         Dim finds As List(Of PdfTextFragment) = finder.Find(".NET Framework")

         ' Iterate through the find results
         For Each fragment As PdfTextFragment In finds

            Dim rf() As RectangleF= fragment.Bounds
           Dim rf1 = rf(0)
         Next fragment

If there are any other issues during testing, please provide us with your testing document for further investigation.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1510
Joined: Wed Apr 25, 2018 3:20 am

Fri Jan 24, 2025 9:45 am

Hello,

Greetings from E-iceblue. Could you please let us know how is the issue going? I would appreciate that if you could give us some feedback.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1510
Joined: Wed Apr 25, 2018 3:20 am

Sat Jan 25, 2025 4:56 pm

Thanks a lot for help

thiefcrazy98
 
Posts: 4
Joined: Sat Jan 25, 2025 4:52 pm

Return to Spire.PDF