markus / KCOM / Controls / SearchPanel.xaml.cs @ 79f3f21a
이력 | 보기 | 이력해설 | 다운로드 (9.41 KB)
1 |
using MarkupToPDF.Common; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Diagnostics; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Windows; |
8 |
using System.Windows.Controls; |
9 |
using System.Windows.Data; |
10 |
using System.Windows.Documents; |
11 |
using System.Windows.Input; |
12 |
using System.Windows.Media; |
13 |
using System.Windows.Media.Imaging; |
14 |
using System.Windows.Navigation; |
15 |
using System.Windows.Shapes; |
16 |
|
17 |
namespace KCOM.Controls |
18 |
{ |
19 |
public class SearchText |
20 |
{ |
21 |
public Bytescout.PDFExtractor.ISearchResult searchResult { get; set; } |
22 |
public int PageNo { get; set; } |
23 |
} |
24 |
/// <summary> |
25 |
/// Interaction logic for SearchPanel.xaml |
26 |
/// </summary> |
27 |
public partial class SearchPanel : UserControl |
28 |
{ |
29 |
//List<HoneyheadTEXT> txtSet = new List<HoneyheadTEXT>(); |
30 |
public System.Collections.ObjectModel.ObservableCollection<SearchText> SearchSet { get; set; } |
31 |
string RegistrationKey = "193B-FD48-42F4-68E6-2D35-4C94-D07"; |
32 |
string RegistrationName = "license@doftech.co.kr"; |
33 |
Bytescout.PDFExtractor.TextExtractor extractor; |
34 |
Bytescout.PDFExtractor.OCRAnalyzer ocrAnalyzer; |
35 |
public SearchPanel() |
36 |
{ |
37 |
InitializeComponent(); |
38 |
LibInit(); |
39 |
//this.Loaded += SearchPanel_Loaded; |
40 |
btnSearch.Click += BtnSearch_Click; |
41 |
btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
42 |
SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
43 |
|
44 |
tbSearch.KeyDown += tbSearch_KeyDown; |
45 |
this.DataContext = this; |
46 |
|
47 |
|
48 |
|
49 |
/* |
50 |
if (Common.ViewerDataModel.Instance.searchPDF ==null) |
51 |
{ |
52 |
|
53 |
} |
54 |
else |
55 |
{ |
56 |
border_Overlap.Visibility = Visibility.Collapsed; |
57 |
tbSearch.Focus(); |
58 |
|
59 |
} |
60 |
*/ |
61 |
|
62 |
if (Common.ViewerDataModel.Instance.searchPDF != null) |
63 |
{ |
64 |
border_Overlap.Visibility = Visibility.Collapsed; |
65 |
tbSearch.Focus(); |
66 |
} |
67 |
} |
68 |
|
69 |
private void tbSearch_KeyDown(object sender, KeyEventArgs e) |
70 |
{ |
71 |
if (e.Key == Key.Enter) |
72 |
{ |
73 |
SearchMethod(); |
74 |
} |
75 |
} |
76 |
private void LibInit() |
77 |
{ |
78 |
extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
79 |
ocrAnalyzer = new Bytescout.PDFExtractor.OCRAnalyzer(RegistrationName, RegistrationKey); |
80 |
extractor.OCRMode = Bytescout.PDFExtractor.OCRMode.Auto; |
81 |
extractor.OCRLanguage = "eng"; |
82 |
extractor.OCRLanguageDataFolder = System.AppDomain.CurrentDomain.BaseDirectory + "\\tessdata\\"; |
83 |
extractor.OCRResolution = 300; |
84 |
|
85 |
ocrAnalyzer.OCRLanguage = "eng"; |
86 |
ocrAnalyzer.OCRLanguageDataFolder = System.AppDomain.CurrentDomain.BaseDirectory + "\\tessdata\\"; |
87 |
|
88 |
} |
89 |
private void SearchPanel_Loaded(object sender, RoutedEventArgs e) |
90 |
{ |
91 |
//측정 |
92 |
//Stopwatch sw = new Stopwatch(); |
93 |
//sw.Start(); |
94 |
InitializeComponent(); |
95 |
//System.Diagnostics.Debug.WriteLine("SearchPanel() : " + sw.ElapsedMilliseconds.ToString() + "ms"); |
96 |
|
97 |
btnSearch.Click += BtnSearch_Click; |
98 |
btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
99 |
SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
100 |
extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
101 |
tbSearch.KeyDown += tbSearch_KeyDown; |
102 |
this.DataContext = this; |
103 |
|
104 |
/* |
105 |
if (Common.ViewerDataModel.Instance.searchPDF ==null) |
106 |
{ |
107 |
|
108 |
} |
109 |
else |
110 |
{ |
111 |
border_Overlap.Visibility = Visibility.Collapsed; |
112 |
tbSearch.Focus(); |
113 |
|
114 |
} |
115 |
*/ |
116 |
|
117 |
if (Common.ViewerDataModel.Instance.searchPDF != null) |
118 |
{ |
119 |
border_Overlap.Visibility = Visibility.Collapsed; |
120 |
tbSearch.Focus(); |
121 |
} |
122 |
} |
123 |
|
124 |
private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e) |
125 |
{ |
126 |
using (System.Net.WebClient client = new System.Net.WebClient()) |
127 |
{ |
128 |
string instnaceFile = System.IO.Path.GetTempFileName().Replace(".pdf", ".tmp"); |
129 |
client.DownloadFileCompleted += Client_DownloadFileCompleted; |
130 |
client.DownloadProgressChanged += Client_DownloadProgressChanged; |
131 |
client.DownloadFileAsync(new Uri(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocInfo.ORIGINAL_FILE), instnaceFile, instnaceFile); |
132 |
} |
133 |
|
134 |
} |
135 |
|
136 |
private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) |
137 |
{ |
138 |
border_Overlap.Visibility = Visibility.Collapsed; |
139 |
Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(e.UserState.ToString()); |
140 |
} |
141 |
|
142 |
private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) |
143 |
{ |
144 |
tlDonwloadState.Text = "문서를 다운로드 중입니다 : " + e.ProgressPercentage; |
145 |
|
146 |
} |
147 |
|
148 |
private void BtnSearch_Click(object sender, RoutedEventArgs e) |
149 |
{ |
150 |
SearchMethod(); |
151 |
} |
152 |
|
153 |
private void SearchMethod() |
154 |
{ |
155 |
|
156 |
SearchSet.Clear(); |
157 |
string searchString = tbSearch.Text; |
158 |
extractor.LoadDocumentFromFile(Common.ViewerDataModel.Instance.searchPDF.FullName); |
159 |
ocrAnalyzer.LoadDocumentFromFile(Common.ViewerDataModel.Instance.searchPDF.FullName); |
160 |
|
161 |
if (chkCurrentPageOnly.IsChecked.Value) |
162 |
{ |
163 |
var currentPage = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber - 1; |
164 |
|
165 |
Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(currentPage); |
166 |
ocrAnalyzer.ApplyResults(analysisResults, extractor); |
167 |
|
168 |
if (extractor.Find(currentPage, searchString, false)) |
169 |
do |
170 |
{ |
171 |
SearchSet.Add(new SearchText { PageNo = currentPage + 1, searchResult = extractor.FoundText }); |
172 |
} |
173 |
while (extractor.FindNext()); |
174 |
} |
175 |
else |
176 |
{ |
177 |
int pageCount = extractor.GetPageCount(); |
178 |
for (int i = 0; i < pageCount; i++) |
179 |
{ |
180 |
Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(i); |
181 |
ocrAnalyzer.ApplyResults(analysisResults, extractor); |
182 |
if (extractor.Find(i, searchString, false)) |
183 |
do |
184 |
{ |
185 |
SearchSet.Add(new SearchText { PageNo = i + 1, searchResult = extractor.FoundText }); |
186 |
} |
187 |
while (extractor.FindNext()); |
188 |
} |
189 |
} |
190 |
|
191 |
|
192 |
this.DataContext = this; |
193 |
tbSearch.Text = ""; |
194 |
tbSearch.Focus(); |
195 |
} |
196 |
|
197 |
private void chkSelectionChangeEvent(object sender, RoutedEventArgs e) |
198 |
{ |
199 |
if (Common.ViewerDataModel.Instance.searchPDF != null) |
200 |
{ |
201 |
if (sender is RadioButton) |
202 |
{ |
203 |
switch ((sender as RadioButton).Tag.ToString()) |
204 |
{ |
205 |
case "0": |
206 |
extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.None; |
207 |
break; |
208 |
case "1": |
209 |
extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.ExactMatch; |
210 |
break; |
211 |
case "2": |
212 |
extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.SmartMatch; |
213 |
break; |
214 |
default: |
215 |
break; |
216 |
} |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
private void lstSearchWord_SelectionChanged(object sender, SelectionChangedEventArgs e) |
222 |
{ |
223 |
if(e.AddedItems.Count>0) |
224 |
{ |
225 |
SearchText item = (e.AddedItems[0] as SearchText); |
226 |
|
227 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(item.PageNo); |
228 |
var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo-1].PAGE_WIDTH); |
229 |
var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT); |
230 |
var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo-1)); |
231 |
var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo-1)); |
232 |
|
233 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect |
234 |
{ |
235 |
X = item.searchResult.Left* widthScale, |
236 |
Y = item.searchResult.Top * heightScale, |
237 |
Width = item.searchResult.Width * widthScale, |
238 |
Height = item.searchResult.Height * heightScale |
239 |
}); |
240 |
|
241 |
} |
242 |
} |
243 |
} |
244 |
} |