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