markus / KCOM / Controls / SearchPanel.xaml.cs @ 29010418
이력 | 보기 | 이력해설 | 다운로드 (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 | extractor.OCRLanguageDataFolder = System.AppDomain.CurrentDomain.BaseDirectory + "\\tessdata\\"; |
||
155 | extractor.OCRResolution = 300; |
||
156 | |||
157 | ocrAnalyzer.OCRLanguage = "eng"; |
||
158 | ocrAnalyzer.OCRLanguageDataFolder = System.AppDomain.CurrentDomain.BaseDirectory + "\\tessdata\\"; |
||
159 | |||
160 | } |
||
161 | catch (Exception ex) |
||
162 | { |
||
163 | Logger.sendResLog("LibInit", ex.Message, 0); |
||
164 | } |
||
165 | 787a4489 | KangIngu | |
166 | 79f3f21a | djkim | } |
167 | 787a4489 | KangIngu | private void SearchPanel_Loaded(object sender, RoutedEventArgs e) |
168 | { |
||
169 | 0c997b99 | ljiyeon | //측정 |
170 | //Stopwatch sw = new Stopwatch(); |
||
171 | //sw.Start(); |
||
172 | InitializeComponent(); |
||
173 | //System.Diagnostics.Debug.WriteLine("SearchPanel() : " + sw.ElapsedMilliseconds.ToString() + "ms"); |
||
174 | 136851cb | djkim | |
175 | 0c997b99 | ljiyeon | btnSearch.Click += BtnSearch_Click; |
176 | btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
||
177 | SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
||
178 | extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
||
179 | tbSearch.KeyDown += tbSearch_KeyDown; |
||
180 | this.DataContext = this; |
||
181 | |||
182 | if (Common.ViewerDataModel.Instance.searchPDF != null) |
||
183 | { |
||
184 | border_Overlap.Visibility = Visibility.Collapsed; |
||
185 | tbSearch.Focus(); |
||
186 | } |
||
187 | 992a98b4 | KangIngu | } |
188 | |||
189 | private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e) |
||
190 | { |
||
191 | 136851cb | djkim | try |
192 | 992a98b4 | KangIngu | { |
193 | 136851cb | djkim | using (System.Net.WebClient client = new System.Net.WebClient()) |
194 | { |
||
195 | string instnaceFile = System.IO.Path.GetTempFileName().Replace(".pdf", ".tmp"); |
||
196 | client.DownloadFileCompleted += Client_DownloadFileCompleted; |
||
197 | client.DownloadProgressChanged += Client_DownloadProgressChanged; |
||
198 | client.DownloadFileAsync(new Uri(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocInfo.ORIGINAL_FILE), instnaceFile, instnaceFile); |
||
199 | } |
||
200 | } |
||
201 | catch (Exception ex) |
||
202 | { |
||
203 | Logger.sendResLog("BtnSearchPDFDownload_Click", ex.Message, 0); |
||
204 | 992a98b4 | KangIngu | } |
205 | } |
||
206 | |||
207 | private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) |
||
208 | { |
||
209 | border_Overlap.Visibility = Visibility.Collapsed; |
||
210 | Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(e.UserState.ToString()); |
||
211 | } |
||
212 | |||
213 | private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) |
||
214 | { |
||
215 | tlDonwloadState.Text = "문서를 다운로드 중입니다 : " + e.ProgressPercentage; |
||
216 | 136851cb | djkim | |
217 | 992a98b4 | KangIngu | } |
218 | |||
219 | private void BtnSearch_Click(object sender, RoutedEventArgs e) |
||
220 | { |
||
221 | SearchMethod(); |
||
222 | } |
||
223 | 136851cb | djkim | |
224 | 992a98b4 | KangIngu | private void SearchMethod() |
225 | { |
||
226 | 136851cb | djkim | try |
227 | 992a98b4 | KangIngu | { |
228 | 136851cb | djkim | if (!worker.IsBusy) |
229 | 992a98b4 | KangIngu | { |
230 | 136851cb | djkim | SearchSet.Clear(); |
231 | this.searchIndicator.IsBusy = true; |
||
232 | worker.RunWorkerAsync(); |
||
233 | 992a98b4 | KangIngu | } |
234 | } |
||
235 | 136851cb | djkim | catch (Exception ex) |
236 | { |
||
237 | Logger.sendResLog("SearchMethod", ex.Message, 0); |
||
238 | } |
||
239 | 992a98b4 | KangIngu | |
240 | } |
||
241 | 136851cb | djkim | private void DialogMessage_Alert(string Msg) |
242 | { |
||
243 | RadWindow CheckPop = new RadWindow(); |
||
244 | Alert check = new Alert(Msg); |
||
245 | 992a98b4 | KangIngu | |
246 | 136851cb | djkim | CheckPop = new RadWindow |
247 | { |
||
248 | Owner = Application.Current.MainWindow, |
||
249 | MinWidth = 400, |
||
250 | MinHeight = 100, |
||
251 | //Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args), |
||
252 | Header = "Alert", |
||
253 | Content = check, |
||
254 | ResizeMode = System.Windows.ResizeMode.NoResize, |
||
255 | WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen, |
||
256 | IsTopmost = true, |
||
257 | }; |
||
258 | StyleManager.SetTheme(CheckPop, new Office2013Theme()); |
||
259 | CheckPop.ShowDialog(); |
||
260 | } |
||
261 | 992a98b4 | KangIngu | private void chkSelectionChangeEvent(object sender, RoutedEventArgs e) |
262 | { |
||
263 | 136851cb | djkim | try |
264 | 992a98b4 | KangIngu | { |
265 | 136851cb | djkim | if (Common.ViewerDataModel.Instance.searchPDF != null) |
266 | 992a98b4 | KangIngu | { |
267 | 136851cb | djkim | if (sender is RadioButton) |
268 | 992a98b4 | KangIngu | { |
269 | 136851cb | djkim | switch ((sender as RadioButton).Tag.ToString()) |
270 | { |
||
271 | case "0": |
||
272 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.None; |
||
273 | break; |
||
274 | case "1": |
||
275 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.ExactMatch; |
||
276 | break; |
||
277 | case "2": |
||
278 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.SmartMatch; |
||
279 | break; |
||
280 | default: |
||
281 | break; |
||
282 | } |
||
283 | 992a98b4 | KangIngu | } |
284 | } |
||
285 | } |
||
286 | 136851cb | djkim | catch (Exception ex) |
287 | { |
||
288 | Logger.sendResLog("chkSelectionChangeEvent", ex.Message, 0); |
||
289 | } |
||
290 | |||
291 | 992a98b4 | KangIngu | } |
292 | |||
293 | private void lstSearchWord_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||
294 | { |
||
295 | 136851cb | djkim | try |
296 | 992a98b4 | KangIngu | { |
297 | 136851cb | djkim | if (e.AddedItems.Count > 0) |
298 | { |
||
299 | SearchText item = (e.AddedItems[0] as SearchText); |
||
300 | 992a98b4 | KangIngu | |
301 | 136851cb | djkim | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(item.PageNo); |
302 | var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_WIDTH); |
||
303 | var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT); |
||
304 | var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo - 1)); |
||
305 | var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo - 1)); |
||
306 | 992a98b4 | KangIngu | |
307 | 136851cb | djkim | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect |
308 | { |
||
309 | X = item.searchResult.Left * widthScale, |
||
310 | Y = item.searchResult.Top * heightScale, |
||
311 | Width = item.searchResult.Width * widthScale, |
||
312 | Height = item.searchResult.Height * heightScale |
||
313 | }); |
||
314 | |||
315 | } |
||
316 | 992a98b4 | KangIngu | } |
317 | 136851cb | djkim | catch (Exception ex) |
318 | { |
||
319 | Logger.sendResLog("lstSearchWord_SelectionChanged", ex.Message, 0); |
||
320 | } |
||
321 | |||
322 | 787a4489 | KangIngu | } |
323 | } |
||
324 | } |