markus / KCOM / Controls / SearchPanel.xaml.cs @ 40b3ce25
이력 | 보기 | 이력해설 | 다운로드 (7.33 KB)
1 | 787a4489 | KangIngu | using MarkupToPDF.Common; |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | 0c997b99 | ljiyeon | using System.Diagnostics; |
5 | 787a4489 | KangIngu | 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 | 992a98b4 | KangIngu | public class SearchText |
20 | { |
||
21 | public Bytescout.PDFExtractor.ISearchResult searchResult { get; set; } |
||
22 | public int PageNo { get; set; } |
||
23 | } |
||
24 | 787a4489 | KangIngu | /// <summary> |
25 | /// Interaction logic for SearchPanel.xaml |
||
26 | /// </summary> |
||
27 | public partial class SearchPanel : UserControl |
||
28 | { |
||
29 | 992a98b4 | KangIngu | //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 | |||
35 | 787a4489 | KangIngu | public SearchPanel() |
36 | { |
||
37 | 0c997b99 | ljiyeon | //InitializeComponent(); |
38 | 787a4489 | KangIngu | this.Loaded += SearchPanel_Loaded; |
39 | 0c997b99 | ljiyeon | |
40 | 787a4489 | KangIngu | } |
41 | |||
42 | 992a98b4 | KangIngu | private void tbSearch_KeyDown(object sender, KeyEventArgs e) |
43 | 787a4489 | KangIngu | { |
44 | 992a98b4 | KangIngu | if (e.Key == Key.Enter) |
45 | { |
||
46 | SearchMethod(); |
||
47 | } |
||
48 | 787a4489 | KangIngu | } |
49 | |||
50 | private void SearchPanel_Loaded(object sender, RoutedEventArgs e) |
||
51 | { |
||
52 | 0c997b99 | ljiyeon | //측정 |
53 | //Stopwatch sw = new Stopwatch(); |
||
54 | //sw.Start(); |
||
55 | InitializeComponent(); |
||
56 | //System.Diagnostics.Debug.WriteLine("SearchPanel() : " + sw.ElapsedMilliseconds.ToString() + "ms"); |
||
57 | |||
58 | btnSearch.Click += BtnSearch_Click; |
||
59 | btnSearchPDFDownload.Click += BtnSearchPDFDownload_Click; |
||
60 | SearchSet = new System.Collections.ObjectModel.ObservableCollection<SearchText>(); |
||
61 | extractor = new Bytescout.PDFExtractor.TextExtractor(RegistrationName, RegistrationKey); |
||
62 | tbSearch.KeyDown += tbSearch_KeyDown; |
||
63 | this.DataContext = this; |
||
64 | |||
65 | /* |
||
66 | 992a98b4 | KangIngu | if (Common.ViewerDataModel.Instance.searchPDF ==null) |
67 | { |
||
68 | |||
69 | } |
||
70 | else |
||
71 | { |
||
72 | border_Overlap.Visibility = Visibility.Collapsed; |
||
73 | tbSearch.Focus(); |
||
74 | |||
75 | 0c997b99 | ljiyeon | } |
76 | */ |
||
77 | |||
78 | if (Common.ViewerDataModel.Instance.searchPDF != null) |
||
79 | { |
||
80 | border_Overlap.Visibility = Visibility.Collapsed; |
||
81 | tbSearch.Focus(); |
||
82 | } |
||
83 | 992a98b4 | KangIngu | } |
84 | |||
85 | private void BtnSearchPDFDownload_Click(object sender, RoutedEventArgs e) |
||
86 | { |
||
87 | using (System.Net.WebClient client = new System.Net.WebClient()) |
||
88 | { |
||
89 | string instnaceFile = System.IO.Path.GetTempFileName().Replace(".pdf", ".tmp"); |
||
90 | client.DownloadFileCompleted += Client_DownloadFileCompleted; |
||
91 | client.DownloadProgressChanged += Client_DownloadProgressChanged; |
||
92 | client.DownloadFileAsync(new Uri(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocInfo.ORIGINAL_FILE), instnaceFile, instnaceFile); |
||
93 | } |
||
94 | |||
95 | } |
||
96 | |||
97 | private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) |
||
98 | { |
||
99 | border_Overlap.Visibility = Visibility.Collapsed; |
||
100 | Common.ViewerDataModel.Instance.searchPDF = new System.IO.FileInfo(e.UserState.ToString()); |
||
101 | } |
||
102 | |||
103 | private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) |
||
104 | { |
||
105 | tlDonwloadState.Text = "문서를 다운로드 중입니다 : " + e.ProgressPercentage; |
||
106 | |||
107 | } |
||
108 | |||
109 | private void BtnSearch_Click(object sender, RoutedEventArgs e) |
||
110 | { |
||
111 | SearchMethod(); |
||
112 | } |
||
113 | |||
114 | private void SearchMethod() |
||
115 | { |
||
116 | extractor.LoadDocumentFromFile(Common.ViewerDataModel.Instance.searchPDF.FullName); |
||
117 | SearchSet.Clear(); |
||
118 | string searchString = tbSearch.Text; |
||
119 | int pageCount = extractor.GetPageCount(); |
||
120 | |||
121 | if (chkCurrentPageOnly.IsChecked.Value) |
||
122 | { |
||
123 | var currentPage = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.CurrentPage.PageNumber - 1; |
||
124 | if (extractor.Find(currentPage, searchString, false)) |
||
125 | do |
||
126 | { |
||
127 | SearchSet.Add(new SearchText { PageNo = currentPage + 1, searchResult = extractor.FoundText }); |
||
128 | } |
||
129 | while (extractor.FindNext()); |
||
130 | } |
||
131 | else |
||
132 | { |
||
133 | for (int i = 0; i < pageCount; i++) |
||
134 | { |
||
135 | if (extractor.Find(i, searchString, false)) |
||
136 | do |
||
137 | { |
||
138 | SearchSet.Add(new SearchText { PageNo = i + 1, searchResult = extractor.FoundText }); |
||
139 | } |
||
140 | while (extractor.FindNext()); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | |||
145 | this.DataContext = this; |
||
146 | tbSearch.Text = ""; |
||
147 | tbSearch.Focus(); |
||
148 | } |
||
149 | |||
150 | private void chkSelectionChangeEvent(object sender, RoutedEventArgs e) |
||
151 | { |
||
152 | if (Common.ViewerDataModel.Instance.searchPDF != null) |
||
153 | { |
||
154 | if (sender is RadioButton) |
||
155 | { |
||
156 | switch ((sender as RadioButton).Tag.ToString()) |
||
157 | { |
||
158 | case "0": |
||
159 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.None; |
||
160 | break; |
||
161 | case "1": |
||
162 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.ExactMatch; |
||
163 | break; |
||
164 | case "2": |
||
165 | extractor.WordMatchingMode = Bytescout.PDFExtractor.WordMatchingMode.SmartMatch; |
||
166 | break; |
||
167 | default: |
||
168 | break; |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | |||
174 | private void lstSearchWord_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||
175 | { |
||
176 | if(e.AddedItems.Count>0) |
||
177 | { |
||
178 | SearchText item = (e.AddedItems[0] as SearchText); |
||
179 | |||
180 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.GotoPage(item.PageNo); |
||
181 | var width = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo-1].PAGE_WIDTH); |
||
182 | var height = Convert.ToDouble(Common.ViewerDataModel.Instance.Document_Info[item.PageNo - 1].PAGE_HEIGHT); |
||
183 | var widthScale = width / Convert.ToDouble(extractor.GetPageRect_Width(item.PageNo-1)); |
||
184 | var heightScale = height / Convert.ToDouble(extractor.GetPageRect_Height(item.PageNo-1)); |
||
185 | |||
186 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanControl.ZoomTo(new Rect |
||
187 | { |
||
188 | X = item.searchResult.Left* widthScale, |
||
189 | Y = item.searchResult.Top * heightScale, |
||
190 | Width = item.searchResult.Width * widthScale, |
||
191 | Height = item.searchResult.Height * heightScale |
||
192 | }); |
||
193 | |||
194 | } |
||
195 | 787a4489 | KangIngu | } |
196 | } |
||
197 | } |