markus / KCOM / Controls / SearchPanel.xaml.cs @ c5519c44
이력 | 보기 | 이력해설 | 다운로드 (15.1 KB)
1 | e0cfc73c | ljiyeon | using KCOM.Common; |
---|---|---|---|
2 | using MarkupToPDF.Common; |
||
3 | 787a4489 | KangIngu | using System; |
4 | using System.Collections.Generic; |
||
5 | 136851cb | djkim | using System.ComponentModel; |
6 | 0c997b99 | ljiyeon | using System.Diagnostics; |
7 | 787a4489 | KangIngu | using System.Linq; |
8 | using System.Text; |
||
9 | 136851cb | djkim | using System.Threading; |
10 | 6af42ff0 | taeseongkim | using System.Threading.Tasks; |
11 | 787a4489 | KangIngu | using System.Windows; |
12 | using System.Windows.Controls; |
||
13 | using System.Windows.Data; |
||
14 | using System.Windows.Documents; |
||
15 | using System.Windows.Input; |
||
16 | using System.Windows.Media; |
||
17 | using System.Windows.Media.Imaging; |
||
18 | using System.Windows.Navigation; |
||
19 | using System.Windows.Shapes; |
||
20 | 136851cb | djkim | using Telerik.Windows.Controls; |
21 | 787a4489 | KangIngu | |
22 | namespace KCOM.Controls |
||
23 | { |
||
24 | 992a98b4 | KangIngu | public class SearchText |
25 | { |
||
26 | public Bytescout.PDFExtractor.ISearchResult searchResult { get; set; } |
||
27 | public int PageNo { get; set; } |
||
28 | } |
||
29 | 787a4489 | KangIngu | /// <summary> |
30 | /// Interaction logic for SearchPanel.xaml |
||
31 | /// </summary> |
||
32 | public partial class SearchPanel : UserControl |
||
33 | { |
||
34 | 992a98b4 | KangIngu | //List<HoneyheadTEXT> txtSet = new List<HoneyheadTEXT>(); |
35 | public System.Collections.ObjectModel.ObservableCollection<SearchText> SearchSet { get; set; } |
||
36 | string RegistrationKey = "193B-FD48-42F4-68E6-2D35-4C94-D07"; |
||
37 | string RegistrationName = "license@doftech.co.kr"; |
||
38 | Bytescout.PDFExtractor.TextExtractor extractor; |
||
39 | 79f3f21a | djkim | Bytescout.PDFExtractor.OCRAnalyzer ocrAnalyzer; |
40 | 136851cb | djkim | private BackgroundWorker worker = new BackgroundWorker(); |
41 | 6af42ff0 | taeseongkim | private bool IsCancelWork = false; |
42 | |||
43 | 787a4489 | KangIngu | public SearchPanel() |
44 | { |
||
45 | e0cfc73c | ljiyeon | App.splashString(ISplashMessage.SEARCHPANEL); |
46 | 79f3f21a | djkim | InitializeComponent(); |
47 | LibInit(); |
||
48 | //this.Loaded += SearchPanel_Loaded; |
||
49 | btnSearch.Click += BtnSearch_Click; |
||
50 | btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
||
51 | SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
||
52 | 136851cb | djkim | |
53 | 79f3f21a | djkim | tbSearch.KeyDown += tbSearch_KeyDown; |
54 | |||
55 | 136851cb | djkim | worker.DoWork += Worker_DoWork; |
56 | worker.RunWorkerCompleted += Worker_RunWorkerCompleted; |
||
57 | 79f3f21a | djkim | |
58 | 6af42ff0 | taeseongkim | this.DataContext = this; |
59 | 79f3f21a | djkim | /* |
60 | if (Common.ViewerDataModel.Instance.searchPDF ==null) |
||
61 | { |
||
62 | |||
63 | } |
||
64 | else |
||
65 | { |
||
66 | border_Overlap.Visibility = Visibility.Collapsed; |
||
67 | tbSearch.Focus(); |
||
68 | |||
69 | } |
||
70 | */ |
||
71 | |||
72 | 6af42ff0 | taeseongkim | if (ViewerDataModel.Instance.IsDownloadOriginal) |
73 | 79f3f21a | djkim | { |
74 | 6af42ff0 | taeseongkim | SetSerachPDFFile(ViewerDataModel.Instance.OriginalTempFile); |
75 | 79f3f21a | djkim | } |
76 | 787a4489 | KangIngu | } |
77 | |||
78 | 136851cb | djkim | private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
79 | { |
||
80 | Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
81 | 29010418 | ljiyeon | { |
82 | 6af42ff0 | taeseongkim | btnSearch.Content = "Search"; |
83 | IsCancelWork = false; |
||
84 | |||
85 | this.searchIndicator.IsIndeterminate = false; |
||
86 | 136851cb | djkim | this.DataContext = this; |
87 | 6af42ff0 | taeseongkim | //tbSearch.Text = ""; |
88 | 136851cb | djkim | tbSearch.Focus(); |
89 | |||
90 | 6af42ff0 | taeseongkim | txtSearchMsg.Text = "search has completed."; |
91 | })); |
||
92 | 136851cb | djkim | } |
93 | //private System.Collections.ObjectModel.ObservableCollection<SearchText> searchTexts = null; |
||
94 | private void Worker_DoWork(object sender, DoWorkEventArgs e) |
||
95 | { |
||
96 | string searchString = string.Empty; |
||
97 | bool pageoption = false; |
||
98 | |||
99 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
100 | { |
||
101 | SearchSet.Clear(); |
||
102 | searchString = tbSearch.Text; |
||
103 | pageoption = chkCurrentPageOnly.IsChecked.Value; |
||
104 | })); |
||
105 | 29010418 | ljiyeon | |
106 | 136851cb | djkim | extractor.LoadDocumentFromFile(Common.ViewerDataModel.Instance.searchPDF.FullName); |
107 | 223975f7 | taeseongkim | //ocrAnalyzer.LoadDocumentFromFile(Common.ViewerDataModel.Instance.searchPDF.FullName); |
108 | 136851cb | djkim | |
109 | if (pageoption) |
||
110 | { |
||
111 | var currentPage = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber - 1; |
||
112 | |||
113 | 223975f7 | taeseongkim | //Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(currentPage); |
114 | //ocrAnalyzer.ApplyResults(analysisResults, extractor); |
||
115 | 136851cb | djkim | |
116 | if (extractor.Find(currentPage, searchString, false)) |
||
117 | do |
||
118 | { |
||
119 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
120 | { |
||
121 | SearchSet.Add(new SearchText { PageNo = currentPage + 1, searchResult = extractor.FoundText }); |
||
122 | 29010418 | ljiyeon | })); |
123 | 136851cb | djkim | } |
124 | while (extractor.FindNext()); |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | int pageCount = extractor.GetPageCount(); |
||
129 | 6af42ff0 | taeseongkim | |
130 | 136851cb | djkim | for (int i = 0; i < pageCount; i++) |
131 | { |
||
132 | 6af42ff0 | taeseongkim | txtSearchMsg.Dispatcher.Invoke(()=> txtSearchMsg.Text = $"Search Pages {i + 1}/{pageCount}"); |
133 | |||
134 | //Bytescout.PDFExtractor.OCRAnalysisResults analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(i); |
||
135 | 223975f7 | taeseongkim | //ocrAnalyzer.ApplyResults(analysisResults, extractor); |
136 | 136851cb | djkim | if (extractor.Find(i, searchString, false)) |
137 | do |
||
138 | { |
||
139 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
140 | { |
||
141 | SearchSet.Add(new SearchText { PageNo = i + 1, searchResult = extractor.FoundText }); |
||
142 | 29010418 | ljiyeon | })); |
143 | 6af42ff0 | taeseongkim | |
144 | if(IsCancelWork) |
||
145 | { |
||
146 | break; |
||
147 | } |
||
148 | 136851cb | djkim | } |
149 | while (extractor.FindNext()); |
||
150 | 6af42ff0 | taeseongkim | |
151 | if (IsCancelWork) |
||
152 | { |
||
153 | break; |
||
154 | } |
||
155 | 136851cb | djkim | } |
156 | 29010418 | ljiyeon | } |
157 | 136851cb | djkim | } |
158 | |||
159 | 992a98b4 | KangIngu | private void tbSearch_KeyDown(object sender, KeyEventArgs e) |
160 | 787a4489 | KangIngu | { |
161 | 992a98b4 | KangIngu | if (e.Key == Key.Enter) |
162 | { |
||
163 | SearchMethod(); |
||
164 | } |
||
165 | 787a4489 | KangIngu | } |
166 | 79f3f21a | djkim | private void LibInit() |
167 | { |
||
168 | 136851cb | djkim | try |
169 | { |
||
170 | extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
||
171 | ocrAnalyzer = new Bytescout.PDFExtractor.OCRAnalyzer(RegistrationName, RegistrationKey); |
||
172 | extractor.OCRMode = Bytescout.PDFExtractor.OCRMode.Auto; |
||
173 | extractor.OCRLanguage = "eng"; |
||
174 | 90a0bfa9 | djkim | extractor.OCRLanguageDataFolder = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "tessdata"); |
175 | 6af42ff0 | taeseongkim | |
176 | 136851cb | djkim | extractor.OCRResolution = 300; |
177 | |||
178 | ocrAnalyzer.OCRLanguage = "eng"; |
||
179 | 90a0bfa9 | djkim | ocrAnalyzer.OCRLanguageDataFolder = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "tessdata"); |
180 | 136851cb | djkim | |
181 | } |
||
182 | catch (Exception ex) |
||
183 | { |
||
184 | Logger.sendResLog("LibInit", ex.Message, 0); |
||
185 | } |
||
186 | 787a4489 | KangIngu | |
187 | 79f3f21a | djkim | } |
188 | 6af42ff0 | taeseongkim | |
189 | 787a4489 | KangIngu | private void SearchPanel_Loaded(object sender, RoutedEventArgs e) |
190 | { |
||
191 | 6af42ff0 | taeseongkim | //// |
192 | /// 이벤트 안 들어옴 |
||
193 | |||
194 | |||
195 | 0c997b99 | ljiyeon | //측정 |
196 | //Stopwatch sw = new Stopwatch(); |
||
197 | //sw.Start(); |
||
198 | InitializeComponent(); |
||
199 | //System.Diagnostics.Debug.WriteLine("SearchPanel() : " + sw.ElapsedMilliseconds.ToString() + "ms"); |
||
200 | 136851cb | djkim | |
201 | 0c997b99 | ljiyeon | btnSearch.Click += BtnSearch_Click; |
202 | btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
||
203 | SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
||
204 | extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
||
205 | tbSearch.KeyDown += tbSearch_KeyDown; |
||
206 | 6af42ff0 | taeseongkim | |
207 | 0c997b99 | ljiyeon | this.DataContext = this; |
208 | |||
209 | 992a98b4 | KangIngu | } |
210 | |||
211 | private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e) |
||
212 | { |
||
213 | 136851cb | djkim | try |
214 | 992a98b4 | KangIngu | { |
215 | 6af42ff0 | taeseongkim | Common.ViewerDataModel.Instance.IsDownloadCancel = true; |
216 | |||
217 | |||
218 | 136851cb | djkim | using (System.Net.WebClient client = new System.Net.WebClient()) |
219 | { |
||
220 | string instnaceFile = System.IO.Path.GetTempFileName().Replace(".pdf", ".tmp"); |
||
221 | client.DownloadFileCompleted += Client_DownloadFileCompleted; |
||
222 | client.DownloadProgressChanged += Client_DownloadProgressChanged; |
||
223 | 223975f7 | taeseongkim | string downloadurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.GetOriginalPDFURL(); |
224 | 6af42ff0 | taeseongkim | |
225 | client.DownloadFileAsync(new Uri(downloadurl), instnaceFile); |
||
226 | 136851cb | djkim | } |
227 | } |
||
228 | catch (Exception ex) |
||
229 | { |
||
230 | 6af42ff0 | taeseongkim | Logger.sendResLog("DownloadOriginalFileAsync", ex.Message, 0); |
231 | 992a98b4 | KangIngu | } |
232 | } |
||
233 | |||
234 | 6af42ff0 | taeseongkim | |
235 | 992a98b4 | KangIngu | private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) |
236 | { |
||
237 | 6af42ff0 | taeseongkim | SetSerachPDFFile(e.UserState.ToString()); |
238 | } |
||
239 | |||
240 | public void SetSerachPDFFile(string FileFullPath) |
||
241 | { |
||
242 | 992a98b4 | KangIngu | border_Overlap.Visibility = Visibility.Collapsed; |
243 | 6af42ff0 | taeseongkim | Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(FileFullPath); |
244 | tbSearch.Focus(); |
||
245 | 992a98b4 | KangIngu | } |
246 | |||
247 | private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) |
||
248 | { |
||
249 | tlDonwloadState.Text = "문서를 다운로드 중입니다 : " + e.ProgressPercentage; |
||
250 | 136851cb | djkim | |
251 | 992a98b4 | KangIngu | } |
252 | |||
253 | private void BtnSearch_Click(object sender, RoutedEventArgs e) |
||
254 | { |
||
255 | SearchMethod(); |
||
256 | } |
||
257 | 136851cb | djkim | |
258 | 992a98b4 | KangIngu | private void SearchMethod() |
259 | { |
||
260 | 6af42ff0 | taeseongkim | string _strCancel = "Cancel"; // 나중에 정리 |
261 | |||
262 | 136851cb | djkim | try |
263 | 992a98b4 | KangIngu | { |
264 | 6af42ff0 | taeseongkim | if (btnSearch.Content.ToString() == _strCancel) |
265 | { |
||
266 | IsCancelWork = true; |
||
267 | c5519c44 | taeseongkim | worker.CancelAsync(); |
268 | 6af42ff0 | taeseongkim | } |
269 | |||
270 | 136851cb | djkim | if (!worker.IsBusy) |
271 | 992a98b4 | KangIngu | { |
272 | 136851cb | djkim | SearchSet.Clear(); |
273 | 6af42ff0 | taeseongkim | |
274 | this.searchIndicator.IsIndeterminate = true; |
||
275 | btnSearch.Content = _strCancel; |
||
276 | |||
277 | 136851cb | djkim | worker.RunWorkerAsync(); |
278 | 992a98b4 | KangIngu | } |
279 | } |
||
280 | 136851cb | djkim | catch (Exception ex) |
281 | { |
||
282 | Logger.sendResLog("SearchMethod", ex.Message, 0); |
||
283 | } |
||
284 | 992a98b4 | KangIngu | |
285 | } |
||
286 | 136851cb | djkim | private void DialogMessage_Alert(string Msg) |
287 | { |
||
288 | RadWindow CheckPop = new RadWindow(); |
||
289 | Alert check = new Alert(Msg); |
||
290 | 992a98b4 | KangIngu | |
291 | 136851cb | djkim | CheckPop = new RadWindow |
292 | { |
||
293 | Owner = Application.Current.MainWindow, |
||
294 | MinWidth = 400, |
||
295 | MinHeight = 100, |
||
296 | //Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args), |
||
297 | Header = "Alert", |
||
298 | Content = check, |
||
299 | ResizeMode = System.Windows.ResizeMode.NoResize, |
||
300 | WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen, |
||
301 | IsTopmost = true, |
||
302 | }; |
||
303 | StyleManager.SetTheme(CheckPop, new Office2013Theme()); |
||
304 | CheckPop.ShowDialog(); |
||
305 | } |
||
306 | 992a98b4 | KangIngu | private void chkSelectionChangeEvent(object sender, RoutedEventArgs e) |
307 | { |
||
308 | 136851cb | djkim | try |
309 | 992a98b4 | KangIngu | { |
310 | 136851cb | djkim | if (Common.ViewerDataModel.Instance.searchPDF != null) |
311 | 992a98b4 | KangIngu | { |
312 | 136851cb | djkim | if (sender is RadioButton) |
313 | 992a98b4 | KangIngu | { |
314 | 136851cb | djkim | switch ((sender as RadioButton).Tag.ToString()) |
315 | { |
||
316 | case "0": |
||
317 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.None; |
||
318 | break; |
||
319 | case "1": |
||
320 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.ExactMatch; |
||
321 | break; |
||
322 | case "2": |
||
323 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.SmartMatch; |
||
324 | break; |
||
325 | default: |
||
326 | break; |
||
327 | } |
||
328 | 992a98b4 | KangIngu | } |
329 | } |
||
330 | } |
||
331 | 136851cb | djkim | catch (Exception ex) |
332 | { |
||
333 | Logger.sendResLog("chkSelectionChangeEvent", ex.Message, 0); |
||
334 | } |
||
335 | |||
336 | 992a98b4 | KangIngu | } |
337 | |||
338 | private void lstSearchWord_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||
339 | { |
||
340 | 136851cb | djkim | try |
341 | 992a98b4 | KangIngu | { |
342 | 136851cb | djkim | if (e.AddedItems.Count > 0) |
343 | { |
||
344 | SearchText item = (e.AddedItems[0] as SearchText); |
||
345 | 992a98b4 | KangIngu | |
346 | 6af42ff0 | taeseongkim | if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber == item.PageNo) |
347 | { |
||
348 | GotoPosition(item); |
||
349 | } |
||
350 | else |
||
351 | 136851cb | djkim | { |
352 | 5a00ee8e | taeseongkim | var pageNavigator = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator; |
353 | 136851cb | djkim | |
354 | eeb0a39c | taeseongkim | EventHandler<EventArgs> handler = null; |
355 | 5a00ee8e | taeseongkim | |
356 | handler = (snd, evt) => |
||
357 | 6af42ff0 | taeseongkim | { |
358 | GotoPosition(item); |
||
359 | eeb0a39c | taeseongkim | ViewerDataModel.Instance.PageLoaded -= handler; |
360 | 6af42ff0 | taeseongkim | }; |
361 | 5a00ee8e | taeseongkim | |
362 | eeb0a39c | taeseongkim | ViewerDataModel.Instance.PageLoaded += handler; |
363 | 5a00ee8e | taeseongkim | pageNavigator.GotoPage(item.PageNo); |
364 | |||
365 | 6af42ff0 | taeseongkim | } |
366 | 136851cb | djkim | } |
367 | 992a98b4 | KangIngu | } |
368 | 136851cb | djkim | catch (Exception ex) |
369 | { |
||
370 | Logger.sendResLog("lstSearchWord_SelectionChanged", ex.Message, 0); |
||
371 | } |
||
372 | |||
373 | 787a4489 | KangIngu | } |
374 | 6af42ff0 | taeseongkim | |
375 | private void GotoPosition(SearchText item) |
||
376 | { |
||
377 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Dispatcher.Invoke(() => { |
||
378 | |||
379 | 5beaf28e | taeseongkim | for (int i = 0; i < (Common.ViewerDataModel.Instance.Angle / 90); i++) |
380 | { |
||
381 | Common.ViewerDataModel.Instance.SystemMain.dzTopMenu.drawingPannelRotate(true); |
||
382 | } |
||
383 | |||
384 | 6af42ff0 | taeseongkim | var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_WIDTH); |
385 | var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT); |
||
386 | var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo - 1)); |
||
387 | var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo - 1)); |
||
388 | |||
389 | f4ec4218 | taeseongkim | var searchFocus = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SearchFocusBorder; |
390 | searchFocus.Visibility = Visibility; |
||
391 | |||
392 | Canvas.SetLeft(searchFocus, item.searchResult.Left * widthScale); |
||
393 | Canvas.SetTop(searchFocus, item.searchResult.Top * heightScale); |
||
394 | searchFocus.Width = item.searchResult.Width * widthScale; |
||
395 | searchFocus.Height = item.searchResult.Height * widthScale; |
||
396 | |||
397 | 6af42ff0 | taeseongkim | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect |
398 | { |
||
399 | X =item.searchResult.Left * widthScale, |
||
400 | Y = item.searchResult.Top * heightScale, |
||
401 | Width = ( item.searchResult.Width * widthScale *7), |
||
402 | Height = (item.searchResult.Height * heightScale *7) |
||
403 | }); |
||
404 | }); |
||
405 | } |
||
406 | 787a4489 | KangIngu | } |
407 | } |