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