-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
71 lines (62 loc) · 3.52 KB
/
Copy pathProgram.vb
File metadata and controls
71 lines (62 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Imports System.Diagnostics
Imports System.Drawing
Namespace HighlightSearchResults
Friend Class Program
Shared Sub Main(ByVal args As String())
'Create a PDF document processor.
Using documentProcessor As PdfDocumentProcessor = New PdfDocumentProcessor()
'Define search words
Dim words As String() = {"Get", "DX-RX809", "HD", "DX-B5000"}
'Load a PDF document
documentProcessor.LoadDocument("..\..\..\Document.pdf")
'Specify the search parameters
Dim searchParameters As PdfTextSearchParameters = New PdfTextSearchParameters()
searchParameters.CaseSensitive = True
searchParameters.WholeWords = True
For Each word As String In words
Dim result As PdfTextSearchResults
'Get the search results from the FindText method call with search text and search parameters
While CSharpImpl.__Assign(result, documentProcessor.FindText(word, searchParameters)).Status Is PdfTextSearchStatus.Found
'HighlightResultWithGraphics(documentProcessor, result);
HighlightResultWithAnnotations(documentProcessor, result)
End While
Next
'Save the document
documentProcessor.SaveDocument("..\..\..\Result.pdf")
Process.Start(New ProcessStartInfo("..\..\..\Result.pdf") With {.UseShellExecute = True})
End Using
End Sub
'This method uses PdfGraphics to highlight text
Private Shared Sub HighlightResultWithGraphics(ByVal processor As PdfDocumentProcessor, ByVal result As PdfTextSearchResults)
Using graphics As PdfGraphics = processor.CreateGraphics()
For i As Integer = 0 To result.Rectangles.Count - 1
Dim rect As RectangleF = New RectangleF(New PointF(CSng(result.Rectangles(i).Left), CSng(result.Page.CropBox.Height) - CSng(result.Rectangles(i).Top)), New SizeF(CSng(result.Rectangles(i).Width), CSng(result.Rectangles(i).Height)))
Using brush = New DXSolidBrush(Color.FromArgb(130, 55, 155, 255))
graphics.FillRectangle(brush, rect)
End Using
Next
graphics.AddToPageForeground(result.Page, 72, 72)
End Using
End Sub
'This method uses annotations to highlight text
Private Shared Sub HighlightResultWithAnnotations(ByVal processor As PdfDocumentProcessor, ByVal result As PdfTextSearchResults)
Dim facade As PdfDocumentFacade = processor.DocumentFacade
Dim page As PdfPageFacade = facade.Pages(result.Page.GetPageIndex())
For i As Integer = 0 To result.Rectangles.Count - 1
Dim annotation As PdfTextMarkupAnnotationFacade = page.AddTextMarkupAnnotation(result.Rectangles(i), PdfTextMarkupAnnotationType.Highlight)
If annotation IsNot Nothing Then
annotation.Color = New PdfRGBColor(0.2, 0.6, 0)
End If
Next
End Sub
Private Class CSharpImpl
<System.Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
target = value
Return value
End Function
End Class
End Class
End Namespace