프로젝트

일반

사용자정보

개정판 136851cb

ID136851cb8d98234c79f66fa51e6299b7eb3a2bbb
상위 481c3fb9
하위 16d13764

김동진이(가) 약 6년 전에 추가함

issue #000 search processing modify

차이점 보기:

KCOM/Controls/SearchPanel.xaml.cs
1 1
using MarkupToPDF.Common;
2 2
using System;
3 3
using System.Collections.Generic;
4
using System.ComponentModel;
4 5
using System.Diagnostics;
5 6
using System.Linq;
6 7
using System.Text;
8
using System.Threading;
7 9
using System.Windows;
8 10
using System.Windows.Controls;
9 11
using System.Windows.Data;
......
13 15
using System.Windows.Media.Imaging;
14 16
using System.Windows.Navigation;
15 17
using System.Windows.Shapes;
18
using Telerik.Windows.Controls;
16 19

  
17 20
namespace KCOM.Controls
18 21
{
......
32 35
        string RegistrationName = "license@doftech.co.kr";
33 36
        Bytescout.PDFExtractor.TextExtractor extractor;
34 37
        Bytescout.PDFExtractor.OCRAnalyzer ocrAnalyzer;
38
        private BackgroundWorker worker = new BackgroundWorker();
35 39
        public SearchPanel()
36 40
        {
37 41
            InitializeComponent();
......
40 44
            btnSearch.Click += BtnSearch_Click;
41 45
            btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click;
42 46
            SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>();
43
            
47

  
44 48
            tbSearch.KeyDown += tbSearch_KeyDown;
45 49
            this.DataContext = this;
46 50

  
47
            
51
            worker.DoWork += Worker_DoWork;
52
            worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
48 53

  
49 54
            /*
50 55
            if (Common.ViewerDataModel.Instance.searchPDF ==null)
......
66 71
            }
67 72
        }
68 73

  
74
        private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
75
        {
76
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
77
            {                
78
                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
            
99
            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
                        }));                        
116
                    }
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
                            }));                            
133
                        }
134
                        while (extractor.FindNext());
135
                }
136
            }            
137
        }
138

  
69 139
        private void tbSearch_KeyDown(object sender, KeyEventArgs e)
70 140
        {
71 141
            if (e.Key == Key.Enter)
......
75 145
        }
76 146
        private void LibInit()
77 147
        {
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\\";
148
            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
            }
87 165

  
88 166
        }
89 167
        private void SearchPanel_Loaded(object sender, RoutedEventArgs e)
......
93 171
            //sw.Start();
94 172
            InitializeComponent();
95 173
            //System.Diagnostics.Debug.WriteLine("SearchPanel() : " + sw.ElapsedMilliseconds.ToString() + "ms");
96
            
174

  
97 175
            btnSearch.Click += BtnSearch_Click;
98 176
            btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click;
99 177
            SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>();
100 178
            extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey);
101 179
            tbSearch.KeyDown += tbSearch_KeyDown;
102 180
            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 181

  
117 182
            if (Common.ViewerDataModel.Instance.searchPDF != null)
118 183
            {
......
123 188

  
124 189
        private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e)
125 190
        {
126
            using (System.Net.WebClient client = new System.Net.WebClient())
191
            try
127 192
            {
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);
193
                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);
132 204
            }
133
            
134 205
        }
135 206

  
136 207
        private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
......
142 213
        private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
143 214
        {
144 215
            tlDonwloadState.Text = "문서를 다운로드 중입니다 : " + e.ProgressPercentage;
145
            
216

  
146 217
        }
147 218

  
148 219
        private void BtnSearch_Click(object sender, RoutedEventArgs e)
149 220
        {
150 221
            SearchMethod();
151 222
        }
152
         
223

  
153 224
        private void SearchMethod()
154 225
        {
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)
226
            try
162 227
            {
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++)
228
                if (!worker.IsBusy)
179 229
                {
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());
230
                    SearchSet.Clear();
231
                    this.searchIndicator.IsBusy = true;
232
                    worker.RunWorkerAsync();
188 233
                }
189 234
            }
235
            catch (Exception ex)
236
            {
237
                Logger.sendResLog("SearchMethod", ex.Message, 0);
238
            }
190 239

  
191

  
192
            this.DataContext = this;
193
            tbSearch.Text = "";
194
            tbSearch.Focus();
195 240
        }
241
        private void DialogMessage_Alert(string Msg)
242
        {
243
            RadWindow CheckPop = new RadWindow();
244
            Alert check = new Alert(Msg);
196 245

  
246
            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
        }
197 261
        private void chkSelectionChangeEvent(object sender, RoutedEventArgs e)
198 262
        {
199
            if (Common.ViewerDataModel.Instance.searchPDF != null)
263
            try
200 264
            {
201
                if (sender is RadioButton)
265
                if (Common.ViewerDataModel.Instance.searchPDF != null)
202 266
                {
203
                    switch ((sender as RadioButton).Tag.ToString())
267
                    if (sender is RadioButton)
204 268
                    {
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;
269
                        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
                        }
216 283
                    }
217 284
                }
218 285
            }
286
            catch (Exception ex)
287
            {
288
                Logger.sendResLog("chkSelectionChangeEvent", ex.Message, 0);
289
            }
290

  
219 291
        }
220 292

  
221 293
        private void lstSearchWord_SelectionChanged(object sender, SelectionChangedEventArgs e)
222 294
        {
223
            if(e.AddedItems.Count>0)
295
            try
224 296
            {
225
                SearchText item = (e.AddedItems[0] as SearchText);
297
                if (e.AddedItems.Count > 0)
298
                {
299
                    SearchText item = (e.AddedItems[0] as SearchText);
226 300

  
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));
301
                    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));
232 306

  
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
                
307
                    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
                }
241 316
            }
317
            catch (Exception ex)
318
            {
319
                Logger.sendResLog("lstSearchWord_SelectionChanged", ex.Message, 0);
320
            }
321

  
242 322
        }
243 323
    }
244 324
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)