1Dim doc As PDFDoc = New PDFDoc(filename)
2Dim page_num As Int32 = 0
3Dim result_str As String = "", ambient_string As String = ""
4Dim hlts As Highlights = New Highlights()
5Dim txt_search As TextSearch = New TextSearch()
6Dim mode As Int32 = CInt((TextSearch.SearchMode.e_whole_word Or TextSearch.SearchMode.e_page_stop Or TextSearch.SearchMode.e_highlight))
7Dim pattern As String = ""
8
9' use regular expression to find credit card number
10mode = mode Or CInt((TextSearch.SearchMode.e_reg_expression Or TextSearch.SearchMode.e_highlight))
11txt_search.SetMode(mode)
12pattern = "\d{4}-\d{4}-\d{4}-\d{4}"
13txt_search.SetPattern(pattern)
14
15' call Begin method to initialize the text search.
16txt_search.Begin(doc, pattern, mode, -1, -1)
17Dim code As TextSearch.ResultCode = txt_search.Run(page_num, result_str, ambient_string, hlts)
18
19If code = TextSearch.ResultCode.e_found Then
20 ' add a link annotation based on the location of the found instance
21 hlts.Begin(doc)
22 While hlts.HasNext()
23 Dim cur_page As Page = doc.GetPage(hlts.GetCurrentPageNumber())
24 Dim quads As Double() = hlts.GetCurrentQuads()
25 Dim quad_count As Integer = quads.Length / 8
26
27 For i As Integer = 0 To quad_count - 1
28 Dim offset As Integer = 8 * i
29 Dim x1 As Double = Math.Min(Math.Min(Math.Min(quads(offset + 0), quads(offset + 2)), quads(offset + 4)), quads(offset + 6))
30 Dim x2 As Double = Math.Max(Math.Max(Math.Max(quads(offset + 0), quads(offset + 2)), quads(offset + 4)), quads(offset + 6))
31 Dim y1 As Double = Math.Min(Math.Min(Math.Min(quads(offset + 1), quads(offset + 3)), quads(offset + 5)), quads(offset + 7))
32 Dim y2 As Double = Math.Max(Math.Max(Math.Max(quads(offset + 1), quads(offset + 3)), quads(offset + 5)), quads(offset + 7))
33 Dim hyper_link As pdftron.PDF.Annots.Link = pdftron.PDF.Annots.Link.Create(doc, New Rect(x1, y1, x2, y2), pdftron.PDF.Action.CreateURI(doc, "http://www.apryse.com"))
34 hyper_link.RefreshAppearance()
35 cur_page.AnnotPushBack(hyper_link)
36 Next
37
38 hlts.Next()
39 End While
40End If