-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.vb
74 lines (64 loc) · 2.72 KB
/
MainForm.vb
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
72
73
74
#Region "#Reference"
Imports DevExpress.Pdf
Imports DevExpress.XtraBars
Imports DevExpress.XtraEditors
Imports System.Text
Imports System.Windows.Forms
' ...
#End Region ' #Reference
Namespace WindowsFormsApplication1
Public Partial Class MainForm
Inherits Ribbon.RibbonForm
Public Sub New()
InitializeComponent()
End Sub
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs)
pdfViewer1.LoadDocument("..\..\TextExtraction.pdf")
AddHandler repositoryItemButtonEdit3.ButtonClick, AddressOf repositoryItemButtonEdit3_ButtonClick
End Sub
#Region "#ExtractText"
Private Function ExtractTextFromPDF(ByVal filePath As String) As String
Dim documentText As String = ""
Try
Using documentProcessor As PdfDocumentProcessor = New PdfDocumentProcessor()
documentProcessor.LoadDocument(filePath)
documentText = documentProcessor.Text
End Using
Catch
End Try
Return documentText
End Function
#End Region ' #ExtractText
#Region "#WordCount"
Private Function WordCount(ByVal filePath As String, ByVal word As String) As Integer
Dim count As Integer = 0
Try
Using documentProcessor As PdfDocumentProcessor = New PdfDocumentProcessor()
documentProcessor.LoadDocument(filePath)
While documentProcessor.FindText(word).Status = PdfTextSearchStatus.Found
count += 1
End While
End Using
Catch
End Try
Return count
End Function
#End Region ' #WordCount
Private Sub barButtonItem1_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim path As String = pdfViewer1.DocumentFilePath
Dim textViewer As TextViewerForm = New TextViewerForm()
textViewer.textBox1.Text = ExtractTextFromPDF(path)
textViewer.ShowDialog()
End Sub
Private Sub repositoryItemButtonEdit3_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs)
Dim path As String = pdfViewer1.DocumentFilePath
Dim word As String = TryCast(sender, ButtonEdit).Text
Dim message As StringBuilder = New StringBuilder()
message.Append("The number of times the word """)
message.Append(word)
message.Append(""" appears in the PDF document: ")
message.Append(WordCount(path, word).ToString())
Call MessageBox.Show(message.ToString())
End Sub
End Class
End Namespace