markus / KCOM / Controls / PrintControl.xaml.cs @ 4836261b
이력 | 보기 | 이력해설 | 다운로드 (33.7 KB)
1 | 787a4489 | KangIngu | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Windows; |
||
5 | using System.Windows.Controls; |
||
6 | using System.Windows.Media; |
||
7 | using Telerik.Windows.Controls; |
||
8 | using System.Collections.ObjectModel; |
||
9 | using System.Drawing.Printing; |
||
10 | using System.Windows.Media.Imaging; |
||
11 | using System.Reactive.Linq; |
||
12 | using KCOMDataModel.DataModel; |
||
13 | using Microsoft.Win32; |
||
14 | using System.IO; |
||
15 | using System.Timers; |
||
16 | //using IKCOM.Common; |
||
17 | using KCOM.Event; |
||
18 | using iTextSharp; |
||
19 | using iTextSharp.text; |
||
20 | //using Leadtools.Windows.Controls; |
||
21 | using IKCOM; |
||
22 | using iTextSharp.text.pdf; |
||
23 | using Microsoft.Office.Core; |
||
24 | e3a15e22 | djkim | |
25 | 787a4489 | KangIngu | namespace KCOM.Control |
26 | { |
||
27 | public class DefinedPages |
||
28 | { |
||
29 | public int PagesCount { get; set; } |
||
30 | public string vpSlip { get; set; } |
||
31 | public string vpTitle { get; set; } |
||
32 | public string fileUrl { get; set; } |
||
33 | public ImageBrush Back_Image { get; set; } |
||
34 | |||
35 | string _DefinedPagesStrings; |
||
36 | /// <summary> |
||
37 | /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용 |
||
38 | /// </summary> |
||
39 | public string DefinedPagesStrings |
||
40 | { |
||
41 | get { return _DefinedPagesStrings; } |
||
42 | set |
||
43 | { |
||
44 | if (string.IsNullOrWhiteSpace(value)) return; |
||
45 | |||
46 | var _definedPages = value.Replace('-', ',').Split(','); |
||
47 | List<char> _NotEx = new List<char>(); |
||
48 | |||
49 | foreach (var item in _definedPages) |
||
50 | { |
||
51 | bool _isNum = true; |
||
52 | |||
53 | foreach (var chr in item) |
||
54 | { |
||
55 | if (!char.IsNumber(chr)) |
||
56 | { |
||
57 | _NotEx.Add(chr); |
||
58 | _isNum = false; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | if (_isNum) |
||
63 | { |
||
64 | if (Convert.ToInt32(item) > PagesCount) |
||
65 | throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount)); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | if (_NotEx.Count() > 0) |
||
70 | { |
||
71 | string _notString = ""; |
||
72 | _NotEx.ForEach(s => _notString += s.ToString()); |
||
73 | throw new Exception(string.Format("'{0}' Can not be added.", _notString)); |
||
74 | } |
||
75 | |||
76 | |||
77 | try |
||
78 | { |
||
79 | |||
80 | string _notString2 = ""; |
||
81 | _NotEx.ForEach(s => _notString2 += s.ToString()); |
||
82 | _DefinedPagesStrings = value; |
||
83 | } |
||
84 | catch (Exception) |
||
85 | { |
||
86 | throw new Exception(string.Format("Can not be added.")); |
||
87 | } |
||
88 | |||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /// <summary> |
||
94 | /// Interaction logic for Print.xaml |
||
95 | /// </summary> |
||
96 | public partial class PrintControl : UserControl |
||
97 | { |
||
98 | #region Data |
||
99 | |||
100 | string ProjectNo = null; //프로젝트 넘버 |
||
101 | string _DefaultTileUri = null; //기본 타일 경로 |
||
102 | int _StartPageNo; //시작페이지 |
||
103 | DOCINFO _DocInfo; //문서 정보 |
||
104 | //DocInfo _DocInfo; //문서 정보 |
||
105 | bool currentPagePrint = false; //현재 페이지 수 |
||
106 | int PageCount { get; set; } //총 페이지수 |
||
107 | DefinedPages _definePages = null; //인쇄 설정 범위 지정 |
||
108 | public bool IsPrint { get; set; } |
||
109 | |||
110 | PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성 |
||
111 | |||
112 | //LayerControl LayerControl = null; // 레이어 컨트롤 |
||
113 | ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보 |
||
114 | List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>(); |
||
115 | List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>(); |
||
116 | List<int> _lstPrintPageNo = new List<int>(); |
||
117 | |||
118 | System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer(); |
||
119 | bool _initializeComponentFinished; //이벤트 |
||
120 | bool _IsDagSlider = false; //드래그 상태인가 |
||
121 | List<DisplayColorInfo> colorList = new List<DisplayColorInfo>(); |
||
122 | DefinedPages DocumentInfo { get; set; } //문서정보 정의 |
||
123 | //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 |
||
124 | delegate void PrintEventHandler(); //프린트 핸들러 |
||
125 | SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그 |
||
126 | //SaveFileDialog SaveFile { get; set; } //저장할 때 사용 |
||
127 | |||
128 | //RasterImageViewer _viewer; //이미지 뷰어 |
||
129 | System.Windows.Controls.Image backimg; //백그라운드 이미지 |
||
130 | System.Drawing.Image Printimg; //프린트 이미지 |
||
131 | System.Drawing.Image p_img; //프린트 이미지 |
||
132 | iTextSharp.text.Image Export_img; |
||
133 | Dictionary<int,System.Drawing.Image> Printimg_List; //프린트 이미지 |
||
134 | |||
135 | //RasterCodecs codecs; |
||
136 | int currentPage; |
||
137 | public string PrintName; |
||
138 | public string Type; |
||
139 | |||
140 | public System.Timers.Timer timm = new System.Timers.Timer(); |
||
141 | |||
142 | |||
143 | #endregion |
||
144 | |||
145 | #region Static Property Defines |
||
146 | public static readonly DependencyProperty CurrentPageNoProperty = |
||
147 | DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
||
148 | new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
||
149 | #endregion |
||
150 | |||
151 | #region Property |
||
152 | public int CurrentPageNo |
||
153 | { |
||
154 | get { return (int)GetValue(CurrentPageNoProperty); } |
||
155 | set { SetValue(CurrentPageNoProperty, value); } |
||
156 | } |
||
157 | #endregion |
||
158 | |||
159 | #region PropertyChangeMethod |
||
160 | private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
||
161 | { |
||
162 | var printPage = (PrintControl)d; |
||
163 | var newValue = (int)e.NewValue; |
||
164 | |||
165 | printPage.sliderPages.Value = newValue; |
||
166 | printPage.SetLoadMakupList(newValue); |
||
167 | |||
168 | } |
||
169 | #endregion |
||
170 | |||
171 | #region 생성자 |
||
172 | 6c781c0c | djkim | |
173 | 787a4489 | KangIngu | public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
174 | { |
||
175 | InitializeComponent(); |
||
176 | |||
177 | this.IsEnabled = true; |
||
178 | |||
179 | //Layer Control을 통째로 가져와야 하는건가 |
||
180 | //this.LayerControl = LayerControl; |
||
181 | this._DocInfo = DocInfo; |
||
182 | this._DefaultTileUri = TileSourceUri; |
||
183 | this.ProjectNo = ProjectNo; |
||
184 | this._StartPageNo = CurrentPageNo; |
||
185 | |||
186 | markupInfo.ForEach(info => this._markupInfo.Add(info)); |
||
187 | |||
188 | foreach (var info in _markupInfo) |
||
189 | { |
||
190 | if (info.Consolidate == 1) |
||
191 | { |
||
192 | info.UserName = "Consolidation"; |
||
193 | } |
||
194 | info.MarkupList.ForEach(makup => |
||
195 | { |
||
196 | var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber); |
||
197 | var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor }; |
||
198 | |||
199 | if (_pageMarkup.Count() > 0) |
||
200 | _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem); |
||
201 | else |
||
202 | _PageMarkupList.Add(new MarkupPageItem |
||
203 | { |
||
204 | PageNumber = makup.PageNumber, |
||
205 | DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem } |
||
206 | }); |
||
207 | }); |
||
208 | |||
209 | colorList.Add(new DisplayColorInfo |
||
210 | { |
||
211 | UserID = info.UserID, |
||
212 | DisplayColor = info.DisplayColor, |
||
213 | Department = info.Depatment, |
||
214 | UserName = info.UserName, |
||
215 | }); |
||
216 | } |
||
217 | |||
218 | gridViewMarkup.ItemsSource = this._markupInfo; |
||
219 | SetLoadMakupList(this._StartPageNo); |
||
220 | if (_LoadMakupList.Count() == 0) |
||
221 | chkOnlyMarkup.IsChecked = false; |
||
222 | |||
223 | this.CurrentPageNo = _StartPageNo; |
||
224 | _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl }; |
||
225 | DocumentInfo = _definePages; |
||
226 | this.DataContext = _definePages; |
||
227 | |||
228 | CheckCommentPages(); |
||
229 | |||
230 | //초기화면 Comment Check된 상태로 보여주기 |
||
231 | foreach (var item in _markupInfo) |
||
232 | { |
||
233 | gridViewMarkup.SelectedItems.Add(item); |
||
234 | } |
||
235 | PageChanged(_StartPageNo); |
||
236 | |||
237 | |||
238 | sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
239 | this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
240 | this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
241 | this.IsPrint = isPrint; |
||
242 | |||
243 | if (!IsPrint) |
||
244 | { |
||
245 | GetPrint(false); |
||
246 | btnWholeExport.Visibility = Visibility.Visible; |
||
247 | btnWholePrint.Visibility = Visibility.Collapsed; |
||
248 | Selected_Print.Header = "Export Type"; |
||
249 | } |
||
250 | else |
||
251 | { |
||
252 | //PrintList 가져오기 |
||
253 | GetPrint(true); |
||
254 | btnWholePrint.Visibility = Visibility.Visible; |
||
255 | btnWholeExport.Visibility = Visibility.Collapsed; |
||
256 | } |
||
257 | |||
258 | _initializeComponentFinished = true; |
||
259 | |||
260 | //timm.Interval = 10; |
||
261 | //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed); |
||
262 | //timm.Enabled = true; |
||
263 | } |
||
264 | |||
265 | private void _Timer_Elapsed(object sender, ElapsedEventArgs e) |
||
266 | { |
||
267 | timm.Enabled = false; |
||
268 | PageChanged(_StartPageNo); |
||
269 | } |
||
270 | #endregion |
||
271 | |||
272 | #region Control Event |
||
273 | private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
274 | { |
||
275 | if (_initializeComponentFinished) |
||
276 | { |
||
277 | if (!_IsDagSlider) |
||
278 | { |
||
279 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
280 | PageChanged(this.CurrentPageNo); |
||
281 | 114015fd | ljiyeon | |
282 | if(_ButtonName == "Current") |
||
283 | { |
||
284 | stPageNo.Value = CurrentPageNo; |
||
285 | edPageNo.Value = CurrentPageNo; |
||
286 | } |
||
287 | |||
288 | 787a4489 | KangIngu | //CheckCommentPages(); |
289 | } |
||
290 | } |
||
291 | } |
||
292 | |||
293 | private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
||
294 | { |
||
295 | _IsDagSlider = false; |
||
296 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
297 | if (_initializeComponentFinished) |
||
298 | { |
||
299 | PageChanged(this.CurrentPageNo); |
||
300 | } |
||
301 | } |
||
302 | |||
303 | private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e) |
||
304 | { |
||
305 | _IsDagSlider = true; |
||
306 | } |
||
307 | |||
308 | private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e) |
||
309 | { |
||
310 | if (_initializeComponentFinished) //GridRangePages |
||
311 | { |
||
312 | CheckCommentPages(); |
||
313 | } |
||
314 | } |
||
315 | 114015fd | ljiyeon | string _ButtonName; |
316 | 787a4489 | KangIngu | private void PageSelect_Checked(object sender, RoutedEventArgs e) |
317 | { |
||
318 | if (!_initializeComponentFinished) return; |
||
319 | |||
320 | 114015fd | ljiyeon | _ButtonName = (sender as RadRadioButton).Tag.ToString(); |
321 | 787a4489 | KangIngu | CommentPageList.ItemsSource = null; |
322 | |||
323 | switch (_ButtonName) |
||
324 | { |
||
325 | case "Current": |
||
326 | stPageNo.Value = CurrentPageNo; |
||
327 | edPageNo.Value = CurrentPageNo; |
||
328 | |||
329 | GridCurrentPage.Visibility = Visibility.Visible; |
||
330 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
331 | GridRangePages.Visibility = Visibility.Collapsed; |
||
332 | GridAllPages.Visibility = Visibility.Collapsed; |
||
333 | |||
334 | break; |
||
335 | case "RangePrint": |
||
336 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
337 | GridDefinePages.Visibility = Visibility.Visible; |
||
338 | GridRangePages.Visibility = Visibility.Collapsed; |
||
339 | GridAllPages.Visibility = Visibility.Collapsed; |
||
340 | break; |
||
341 | case "UserDefined": |
||
342 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
343 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
344 | GridRangePages.Visibility = Visibility.Visible; |
||
345 | GridAllPages.Visibility = Visibility.Collapsed; |
||
346 | break; |
||
347 | case "AllPrint": |
||
348 | stPageNo.Value = 1; |
||
349 | edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT); |
||
350 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
351 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
352 | GridRangePages.Visibility = Visibility.Collapsed; |
||
353 | GridAllPages.Visibility = Visibility.Visible; |
||
354 | break; |
||
355 | } |
||
356 | |||
357 | CheckCommentPages(); |
||
358 | } |
||
359 | |||
360 | private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e) |
||
361 | { |
||
362 | if (_initializeComponentFinished) //GridRangePages |
||
363 | { |
||
364 | if (stPageNo.Value > edPageNo.Value) |
||
365 | { |
||
366 | if (sender.Equals(stPageNo)) |
||
367 | edPageNo.Value = stPageNo.Value; |
||
368 | else |
||
369 | stPageNo.Value = edPageNo.Value; |
||
370 | } |
||
371 | |||
372 | //뷰어잠시제외(강인구) |
||
373 | //this.LayoutRoot.Dispatcher.BeginInvoke(delegate() |
||
374 | //{ |
||
375 | CheckCommentPages(); |
||
376 | //}); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e) |
||
381 | { |
||
382 | CheckCommentPages(); |
||
383 | } |
||
384 | |||
385 | private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e) |
||
386 | { |
||
387 | txtDefinedPages.Text = ""; |
||
388 | } |
||
389 | |||
390 | private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
||
391 | { |
||
392 | if (_initializeComponentFinished) |
||
393 | if (CommentPageList.SelectedItem != null) |
||
394 | this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber; |
||
395 | } |
||
396 | |||
397 | private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
||
398 | { |
||
399 | if (_initializeComponentFinished) |
||
400 | { |
||
401 | PageChanged(this.CurrentPageNo); |
||
402 | } |
||
403 | } |
||
404 | |||
405 | #endregion |
||
406 | |||
407 | public void PageChanged(int PageNo, bool Flag = false) |
||
408 | { |
||
409 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
410 | { |
||
411 | Load load = new Load(); |
||
412 | |||
413 | _definePages.Back_Image = new ImageBrush(); |
||
414 | var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png")); |
||
415 | |||
416 | printCanvas.Children.Clear(); |
||
417 | |||
418 | ImageBrush background = new ImageBrush(defaultBitmapImage); |
||
419 | printCanvas.Background = background; |
||
420 | |||
421 | iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png")); |
||
422 | printCanvas.Width = image.Width; |
||
423 | printCanvas.Height = image.Height; |
||
424 | |||
425 | foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
||
426 | { |
||
427 | load.User_Id = info.UserID; |
||
428 | load.document_id = _DocInfo.DOCUMENT_ID; |
||
429 | load.Page_No = PageNo; |
||
430 | load.DisplayColor = info.DisplayColor; |
||
431 | load.Markupinfoid = info.MarkupInfoID; |
||
432 | load.Markup_Load(printCanvas); |
||
433 | } |
||
434 | |||
435 | printCanvas.UpdateLayout(); |
||
436 | |||
437 | if(Flag) |
||
438 | { |
||
439 | MemoryStream ms = new MemoryStream(); |
||
440 | BmpBitmapEncoder bbe = new BmpBitmapEncoder(); |
||
441 | bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png"))); |
||
442 | bbe.Save(ms); |
||
443 | |||
444 | Printimg = System.Drawing.Image.FromStream(ms); |
||
445 | Export export = new Export(); |
||
446 | p_img = export.Exporting(printCanvas, Printimg); |
||
447 | Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
||
448 | } |
||
449 | })); |
||
450 | } |
||
451 | |||
452 | //Print 버튼 클릭 이벤트 |
||
453 | #region Method - 명령 |
||
454 | void PrintMethod(object sender, RoutedEventArgs e) |
||
455 | { |
||
456 | |||
457 | if (this.printIndy.IsBusy == true) |
||
458 | return; |
||
459 | |||
460 | System.Threading.Tasks.Task.Factory.StartNew(() => |
||
461 | { |
||
462 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
463 | { |
||
464 | this.printIndy.IsBusy = true; |
||
465 | printIndy.BusyContent = "Printing. . ."; |
||
466 | })); |
||
467 | }); |
||
468 | |||
469 | |||
470 | _lstPrintPageNo = PrintPageCreate(); |
||
471 | |||
472 | if (_lstPrintPageNo.Count == 0) |
||
473 | { |
||
474 | RadWindow.Alert(new DialogParameters |
||
475 | { |
||
476 | Theme = new VisualStudio2013Theme(), |
||
477 | Header = "안내", |
||
478 | Content = "페이지가 지정되지 않았습니다." |
||
479 | }); |
||
480 | this.printIndy.IsBusy = false; |
||
481 | return; |
||
482 | } |
||
483 | int cnt = 0; |
||
484 | List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>(); |
||
485 | |||
486 | Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
||
487 | |||
488 | foreach (int PageNo in _lstPrintPageNo) |
||
489 | { |
||
490 | cnt++; |
||
491 | 2024d8d1 | ljiyeon | sliderPages.Value = PageNo; |
492 | 787a4489 | KangIngu | PageChanged(PageNo, true); |
493 | //PageChanged(cnt, true); |
||
494 | } |
||
495 | PrintName = cbPrint.SelectedItem.ToString(); |
||
496 | |||
497 | System.Threading.Tasks.Task.Factory.StartNew(() => |
||
498 | { |
||
499 | if (cnt == _lstPrintPageNo.Count) |
||
500 | { |
||
501 | Printing(); |
||
502 | } |
||
503 | }); |
||
504 | } |
||
505 | |||
506 | //Export 버튼 클릭 이벤트 |
||
507 | void ExportMethod(object sender, RoutedEventArgs e) |
||
508 | { |
||
509 | if (this.printIndy.IsBusy == true) |
||
510 | return; |
||
511 | |||
512 | this.printIndy.IsBusy = true; |
||
513 | printIndy.BusyContent = "Exporting. . ."; |
||
514 | |||
515 | Export export = new Export(); |
||
516 | _lstPrintPageNo = PrintPageCreate(); |
||
517 | |||
518 | if (_lstPrintPageNo.Count == 0) |
||
519 | { |
||
520 | this.printIndy.IsBusy = false; |
||
521 | RadWindow.Alert(new DialogParameters |
||
522 | { |
||
523 | Theme = new VisualStudio2013Theme(), |
||
524 | Header = "안내", |
||
525 | Content = "페이지가 지정되지 않았습니다.", |
||
526 | }); |
||
527 | return; |
||
528 | } |
||
529 | |||
530 | //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png"); |
||
531 | |||
532 | switch (cbPrint.SelectedIndex) |
||
533 | { |
||
534 | case (0): |
||
535 | { |
||
536 | SaveDig.Filter = "PDF file format|*.pdf"; |
||
537 | break; |
||
538 | } |
||
539 | case (1): |
||
540 | { |
||
541 | SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png"; |
||
542 | break; |
||
543 | } |
||
544 | } |
||
545 | |||
546 | SaveDig.Title = "Save an PDF File"; |
||
547 | SaveDig.ShowDialog(); |
||
548 | Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
||
549 | |||
550 | foreach (int PageNo in _lstPrintPageNo) |
||
551 | { |
||
552 | sliderPages.Value = PageNo; |
||
553 | PageChanged(PageNo, true); |
||
554 | } |
||
555 | |||
556 | //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
||
557 | |||
558 | if (SaveDig.FileName != "") |
||
559 | { |
||
560 | switch (cbPrint.SelectedIndex) |
||
561 | { |
||
562 | case (0): |
||
563 | { |
||
564 | using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
||
565 | { |
||
566 | using (Document doc = new Document()) |
||
567 | { |
||
568 | using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) |
||
569 | { |
||
570 | doc.Open(); |
||
571 | 751494ca | ljiyeon | float height = doc.PageSize.Height; |
572 | float width = doc.PageSize.Width; |
||
573 | |||
574 | 787a4489 | KangIngu | foreach (var item in Printimg_List) |
575 | { |
||
576 | e3a15e22 | djkim | |
577 | 751494ca | ljiyeon | Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png); |
578 | |||
579 | e3a15e22 | djkim | |
580 | if (Export_img.Width > Export_img.Height) |
||
581 | { |
||
582 | 751494ca | ljiyeon | doc.SetPageSize(new Rectangle(height, width)); |
583 | Export_img.ScaleToFit(height, width); |
||
584 | e3a15e22 | djkim | } |
585 | else |
||
586 | { |
||
587 | 751494ca | ljiyeon | doc.SetPageSize(new Rectangle(width, height)); |
588 | Export_img.ScaleToFit(width, height); |
||
589 | e3a15e22 | djkim | } |
590 | 751494ca | ljiyeon | |
591 | e3a15e22 | djkim | Export_img.SetAbsolutePosition(0, 0); |
592 | 787a4489 | KangIngu | |
593 | doc.NewPage(); |
||
594 | doc.Add(Export_img); |
||
595 | } |
||
596 | doc.Close(); |
||
597 | } |
||
598 | } |
||
599 | } |
||
600 | break; |
||
601 | } |
||
602 | case (1): |
||
603 | { |
||
604 | foreach (var item in Printimg_List) |
||
605 | { |
||
606 | switch(SaveDig.FilterIndex) |
||
607 | { |
||
608 | case (1): |
||
609 | { |
||
610 | //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg); |
||
611 | (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); |
||
612 | } |
||
613 | break; |
||
614 | case (2): |
||
615 | { |
||
616 | //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png); |
||
617 | (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png); |
||
618 | } |
||
619 | break; |
||
620 | } |
||
621 | } |
||
622 | break; |
||
623 | } |
||
624 | } |
||
625 | } |
||
626 | else |
||
627 | { |
||
628 | this.printIndy.IsBusy = false; |
||
629 | return; |
||
630 | } |
||
631 | |||
632 | |||
633 | |||
634 | //docWriter.EndDocument(); |
||
635 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
636 | { |
||
637 | printIndy.IsBusy = false; |
||
638 | })); |
||
639 | PageChanged(_StartPageNo); |
||
640 | |||
641 | (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert"); |
||
642 | } |
||
643 | #endregion |
||
644 | |||
645 | #region Method - 처리 |
||
646 | void CheckCommentPages() |
||
647 | { |
||
648 | List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
||
649 | DoubleCollection _Ticks = new DoubleCollection(); |
||
650 | |||
651 | |||
652 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
||
653 | { |
||
654 | |||
655 | _pages = (from commPage in this._PageMarkupList |
||
656 | where commPage.PageNumber == CurrentPageNo |
||
657 | orderby commPage.PageNumber |
||
658 | select commPage).ToList(); |
||
659 | } |
||
660 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
661 | { |
||
662 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
663 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
664 | |||
665 | int _stPage = (int)stPageNo.Value; |
||
666 | int _edPage = (int)edPageNo.Value; |
||
667 | |||
668 | _pages = (from commPage in this._PageMarkupList |
||
669 | where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
||
670 | orderby commPage.PageNumber |
||
671 | select commPage).ToList(); |
||
672 | } |
||
673 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
674 | { |
||
675 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
676 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
677 | |||
678 | int _stPage = (int)stPageNo.Value; |
||
679 | int _edPage = (int)edPageNo.Value; |
||
680 | |||
681 | //Using DeepView.Common.RangeParser |
||
682 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
683 | _pages = (from commPage in this._PageMarkupList |
||
684 | from compareData in lst |
||
685 | where commPage.PageNumber == compareData |
||
686 | orderby commPage.PageNumber |
||
687 | select commPage).ToList(); |
||
688 | } |
||
689 | else |
||
690 | { |
||
691 | _pages = (from commPage in this._PageMarkupList |
||
692 | orderby commPage.PageNumber |
||
693 | select commPage).ToList(); |
||
694 | } |
||
695 | CommentPageList.ItemsSource = _pages.ToList(); |
||
696 | } |
||
697 | |||
698 | void SetLoadMakupList(int PageNo) |
||
699 | { |
||
700 | _LoadMakupList.Clear(); |
||
701 | var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
||
702 | |||
703 | if (_markupList.Count() > 0) |
||
704 | _LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
||
705 | } |
||
706 | |||
707 | #region 프린트 리스트 가져오기 |
||
708 | public void GetPrint(bool flag) |
||
709 | { |
||
710 | if (flag) |
||
711 | { |
||
712 | foreach (string printer in PrinterSettings.InstalledPrinters) |
||
713 | { |
||
714 | this.cbPrint.Items.Add(printer); |
||
715 | } |
||
716 | printDocument = new PrintDocument(); |
||
717 | this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
||
718 | } |
||
719 | else |
||
720 | { |
||
721 | this.cbPrint.Items.Add("PDF"); |
||
722 | this.cbPrint.Items.Add("IMAGE"); |
||
723 | |||
724 | this.cbPrint.SelectedItem = "PDF"; |
||
725 | } |
||
726 | } |
||
727 | #endregion |
||
728 | |||
729 | #region 프린트 실행 |
||
730 | public void Printing() |
||
731 | { |
||
732 | PageChanged(1); |
||
733 | if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
||
734 | { |
||
735 | 408e4218 | ljiyeon | printDocument = new PrintDocument(); |
736 | printDocument.OriginAtMargins = true; |
||
737 | 787a4489 | KangIngu | printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
738 | printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
||
739 | printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
||
740 | } |
||
741 | else |
||
742 | printDocument = null; |
||
743 | |||
744 | #region 인쇄 미리보기 테스트 |
||
745 | using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
||
746 | { |
||
747 | printDocument.PrinterSettings.MinimumPage = 1; |
||
748 | printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
||
749 | printDocument.PrinterSettings.FromPage = 1; |
||
750 | 408e4218 | ljiyeon | printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
751 | 787a4489 | KangIngu | printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
752 | 408e4218 | ljiyeon | printDocument.PrinterSettings.PrinterName = PrintName; |
753 | dlg.Document = printDocument; |
||
754 | 787a4489 | KangIngu | dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
755 | dlg.ShowDialog(); |
||
756 | } |
||
757 | #endregion |
||
758 | |||
759 | #region 인쇄 |
||
760 | //printDocument.PrinterSettings.MinimumPage = 1; |
||
761 | //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
||
762 | //printDocument.PrinterSettings.FromPage = 1; |
||
763 | //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
||
764 | |||
765 | //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
||
766 | //printDocument.PrinterSettings.PrinterName = PrintName; |
||
767 | |||
768 | //printDocument.Print(); |
||
769 | #endregion |
||
770 | } |
||
771 | |||
772 | private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
||
773 | { |
||
774 | //Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
||
775 | // This demo only loads one page at a time, so no need to re-set the print page number |
||
776 | 2024d8d1 | ljiyeon | PrintDocument document = sender as PrintDocument; |
777 | 787a4489 | KangIngu | currentPage = document.PrinterSettings.FromPage; |
778 | } |
||
779 | 408e4218 | ljiyeon | |
780 | 787a4489 | KangIngu | private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
781 | { |
||
782 | //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0); |
||
783 | |||
784 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
785 | { |
||
786 | p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
||
787 | 2024d8d1 | ljiyeon | |
788 | if(p_img.Width > p_img.Height) |
||
789 | { |
||
790 | p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); |
||
791 | } |
||
792 | 408e4218 | ljiyeon | |
793 | //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg); |
||
794 | System.Drawing.Image pic = p_img; |
||
795 | 787a4489 | KangIngu | System.Drawing.Rectangle m = e.MarginBounds; |
796 | |||
797 | 408e4218 | ljiyeon | //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider |
798 | //{ |
||
799 | // m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16; |
||
800 | //} |
||
801 | //else |
||
802 | //{ |
||
803 | // m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16; |
||
804 | //} |
||
805 | m.Width = (int)e.PageSettings.PrintableArea.Width; |
||
806 | m.Height = (int)e.PageSettings.PrintableArea.Height; |
||
807 | m.X = (int)e.PageSettings.HardMarginX; |
||
808 | m.Y = (int)e.PageSettings.HardMarginY; |
||
809 | |||
810 | e.Graphics.DrawImage(pic, m); |
||
811 | 787a4489 | KangIngu | //e.Graphics.DrawImage(p_img, e.MarginBounds); |
812 | //e.Graphics.DrawImage(p_img, 0, 0); |
||
813 | })); |
||
814 | |||
815 | //다음 페이지 |
||
816 | currentPage++; |
||
817 | |||
818 | ////인쇄를 계속 할지 말지 확인 |
||
819 | if (currentPage <= printDocument.PrinterSettings.ToPage) |
||
820 | e.HasMorePages = true; |
||
821 | else |
||
822 | e.HasMorePages = false; |
||
823 | |||
824 | } |
||
825 | |||
826 | private void printDocument_EndPrint(object sender, PrintEventArgs e) |
||
827 | { |
||
828 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
829 | { |
||
830 | printIndy.IsBusy = false; |
||
831 | })); |
||
832 | } |
||
833 | #endregion |
||
834 | |||
835 | #region Selected Pages Check |
||
836 | List<int> PrintPageCreate() |
||
837 | { |
||
838 | List<int> Result = new List<int>(); |
||
839 | |||
840 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
||
841 | { |
||
842 | Result.Add(CurrentPageNo); |
||
843 | } |
||
844 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
845 | { |
||
846 | for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
||
847 | { |
||
848 | Result.Add(i); |
||
849 | } |
||
850 | } |
||
851 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
852 | { |
||
853 | int _stPage = (int)stPageNo.Value; |
||
854 | int _edPage = (int)edPageNo.Value; |
||
855 | |||
856 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
857 | Result.AddRange(lst); |
||
858 | } |
||
859 | else |
||
860 | { |
||
861 | for (int i = 1; i <= _definePages.PagesCount; i++) |
||
862 | { |
||
863 | Result.Add(i); |
||
864 | } |
||
865 | } |
||
866 | if (currentPagePrint) |
||
867 | { |
||
868 | return Result; |
||
869 | } |
||
870 | |||
871 | if (chkOnlyMarkup.IsChecked.Value) |
||
872 | { |
||
873 | var _result = from result in Result |
||
874 | where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
||
875 | select result; |
||
876 | Result = _result.ToList(); |
||
877 | } |
||
878 | return Result; |
||
879 | } |
||
880 | #endregion |
||
881 | |||
882 | #endregion |
||
883 | } |
||
884 | } |