프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Controls / PrintControl.xaml.cs @ b9b01f8e

이력 | 보기 | 이력해설 | 다운로드 (33.8 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 b9b01f8e ljiyeon
            
177 787a4489 KangIngu
            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 b9b01f8e ljiyeon
                    Owner = Application.Current.MainWindow,
477 787a4489 KangIngu
                    Theme = new VisualStudio2013Theme(),
478
                    Header = "안내",
479
                    Content = "페이지가 지정되지 않았습니다."
480
                });
481
                this.printIndy.IsBusy = false;
482
                return;
483
            }
484
            int cnt = 0;
485
            List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
486
487
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
488
489
            foreach (int PageNo in _lstPrintPageNo)
490
            {
491
                cnt++;
492 2024d8d1 ljiyeon
                sliderPages.Value = PageNo;                
493 787a4489 KangIngu
                PageChanged(PageNo, true);
494
                //PageChanged(cnt, true);
495
            }
496
            PrintName = cbPrint.SelectedItem.ToString();
497
498
            System.Threading.Tasks.Task.Factory.StartNew(() =>
499
            {
500
                if (cnt == _lstPrintPageNo.Count)
501
                {
502
                    Printing();
503
                }
504
            });
505
        }
506
507
        //Export 버튼 클릭 이벤트
508
        void ExportMethod(object sender, RoutedEventArgs e)
509
        {
510
            if (this.printIndy.IsBusy == true)
511
                return;
512
513
            this.printIndy.IsBusy = true;
514
            printIndy.BusyContent = "Exporting. . .";
515
516
            Export export = new Export();
517
            _lstPrintPageNo = PrintPageCreate();
518
519
            if (_lstPrintPageNo.Count == 0)
520
            {
521
                this.printIndy.IsBusy = false;
522
                RadWindow.Alert(new DialogParameters
523
                {
524 b9b01f8e ljiyeon
                    Owner = Application.Current.MainWindow,
525 787a4489 KangIngu
                    Theme = new VisualStudio2013Theme(),
526
                    Header = "안내",
527
                    Content = "페이지가 지정되지 않았습니다.",
528
                });
529
                return;
530
            }
531
532
            //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
533
534
            switch (cbPrint.SelectedIndex)
535
            {
536
                case (0):
537
                    {
538
                        SaveDig.Filter = "PDF file format|*.pdf";
539
                        break;
540
                    }
541
                case (1):
542
                    {
543
                        SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
544
                        break;
545
                    }
546
            }
547
548
            SaveDig.Title = "Save an PDF File";
549
            SaveDig.ShowDialog();
550
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
551
552
            foreach (int PageNo in _lstPrintPageNo)
553
            {
554
                sliderPages.Value = PageNo;
555
                PageChanged(PageNo, true);
556
            }
557
558
            //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
559
560
            if (SaveDig.FileName != "")
561
            {
562
                switch (cbPrint.SelectedIndex)
563
                {
564
                    case (0):
565
                        {
566
                            using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
567
                            {
568
                                using (Document doc = new Document())
569
                                {
570
                                    using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
571
                                    {
572
                                        doc.Open();
573 751494ca ljiyeon
                                        float height = doc.PageSize.Height;
574
                                        float width = doc.PageSize.Width;
575
576 787a4489 KangIngu
                                        foreach (var item in Printimg_List)
577
                                        {
578 e3a15e22 djkim
                                            
579 751494ca ljiyeon
                                             Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
580
581 e3a15e22 djkim
                                            
582
                                            if (Export_img.Width > Export_img.Height)
583
                                            {
584 751494ca ljiyeon
                                                doc.SetPageSize(new Rectangle(height, width));
585
                                                Export_img.ScaleToFit(height, width);
586 e3a15e22 djkim
                                            }
587
                                            else
588
                                            {
589 751494ca ljiyeon
                                                doc.SetPageSize(new Rectangle(width, height));
590
                                                Export_img.ScaleToFit(width, height);
591 e3a15e22 djkim
                                            }
592 751494ca ljiyeon
                                            
593 e3a15e22 djkim
                                            Export_img.SetAbsolutePosition(0, 0);
594 787a4489 KangIngu
595
                                            doc.NewPage();
596
                                            doc.Add(Export_img);
597
                                        }
598
                                        doc.Close();
599
                                    }
600
                                }
601
                            }
602
                            break;
603
                        }
604
                    case (1):
605
                        {
606
                            foreach (var item in Printimg_List)
607
                            {
608
                                switch(SaveDig.FilterIndex)
609
                                {
610
                                    case (1):
611
                                        {
612
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
613
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
614
                                        }
615
                                        break;
616
                                    case (2):
617
                                        {
618
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
619
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
620
                                        }
621
                                        break;
622
                                }
623
                            }
624
                            break;
625
                        }
626
                }
627
            }
628
            else
629
            {
630
                this.printIndy.IsBusy = false;
631
                return;
632
            }
633
634
         
635
636
            //docWriter.EndDocument();
637
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
638
            {
639
                printIndy.IsBusy = false;
640
            }));
641
            PageChanged(_StartPageNo);
642
643
            (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
644
        }
645
        #endregion
646
647
        #region Method - 처리
648
        void CheckCommentPages()
649
        {
650
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
651
            DoubleCollection _Ticks = new DoubleCollection();
652
653
654
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
655
            {
656
657
                _pages = (from commPage in this._PageMarkupList
658
                          where commPage.PageNumber == CurrentPageNo
659
                          orderby commPage.PageNumber
660
                          select commPage).ToList();
661
            }
662
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
663
            {
664
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
665
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
666
667
                int _stPage = (int)stPageNo.Value;
668
                int _edPage = (int)edPageNo.Value;
669
670
                _pages = (from commPage in this._PageMarkupList
671
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
672
                          orderby commPage.PageNumber
673
                          select commPage).ToList();
674
            }
675
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
676
            {
677
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
678
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
679
680
                int _stPage = (int)stPageNo.Value;
681
                int _edPage = (int)edPageNo.Value;
682
683
                //Using DeepView.Common.RangeParser
684
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
685
                _pages = (from commPage in this._PageMarkupList
686
                          from compareData in lst
687
                          where commPage.PageNumber == compareData
688
                          orderby commPage.PageNumber
689
                          select commPage).ToList();
690
            }
691
            else
692
            {
693
                _pages = (from commPage in this._PageMarkupList
694
                          orderby commPage.PageNumber
695
                          select commPage).ToList();
696
            }
697
            CommentPageList.ItemsSource = _pages.ToList();
698
        }
699
700
        void SetLoadMakupList(int PageNo)
701
        {
702
            _LoadMakupList.Clear();
703
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
704
705
            if (_markupList.Count() > 0)
706
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
707
        }
708
709
        #region 프린트 리스트 가져오기
710
        public void GetPrint(bool flag)
711
        {
712
            if (flag)
713
            {
714
                foreach (string printer in PrinterSettings.InstalledPrinters)
715
                {
716
                    this.cbPrint.Items.Add(printer);
717
                }
718
                printDocument = new PrintDocument();
719
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
720
            }
721
            else
722
            {
723
                this.cbPrint.Items.Add("PDF");
724
                this.cbPrint.Items.Add("IMAGE");
725
726
                this.cbPrint.SelectedItem = "PDF";
727
            }
728
        }
729
        #endregion
730
731
        #region 프린트 실행
732
        public void Printing()
733
        {
734
            PageChanged(1);
735
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
736
            {
737 408e4218 ljiyeon
                printDocument = new PrintDocument();                
738
                printDocument.OriginAtMargins = true;
739 787a4489 KangIngu
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
740
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
741
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
742
            }
743
            else
744
                printDocument = null;
745
746
            #region 인쇄 미리보기 테스트
747
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
748
            {
749
                printDocument.PrinterSettings.MinimumPage = 1;
750
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
751
                printDocument.PrinterSettings.FromPage = 1;
752 408e4218 ljiyeon
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
753 787a4489 KangIngu
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
754 408e4218 ljiyeon
                printDocument.PrinterSettings.PrinterName = PrintName;              
755
                dlg.Document = printDocument;                
756 787a4489 KangIngu
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
757
                dlg.ShowDialog();
758
            }
759
            #endregion
760
761
            #region 인쇄
762
            //printDocument.PrinterSettings.MinimumPage = 1;
763
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
764
            //printDocument.PrinterSettings.FromPage = 1;
765
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
766
767
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
768
            //printDocument.PrinterSettings.PrinterName = PrintName;
769
770
            //printDocument.Print();
771
            #endregion
772
        }
773
774
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
775
        {
776
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
777
            // This demo only loads one page at a time, so no need to re-set the print page number
778 2024d8d1 ljiyeon
            PrintDocument document = sender as PrintDocument;            
779 787a4489 KangIngu
            currentPage = document.PrinterSettings.FromPage;
780
        }
781 408e4218 ljiyeon
                   
782 787a4489 KangIngu
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
783
        {
784
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
785
786
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
787
            {
788
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
789 2024d8d1 ljiyeon
790
                if(p_img.Width > p_img.Height)
791
                {
792
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
793
                }
794 408e4218 ljiyeon
795
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
796
                System.Drawing.Image pic = p_img;
797 787a4489 KangIngu
                System.Drawing.Rectangle m = e.MarginBounds;
798
799 408e4218 ljiyeon
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
800
                //{
801
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
802
                //}
803
                //else
804
                //{
805
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
806
                //}
807
                m.Width = (int)e.PageSettings.PrintableArea.Width;
808
                m.Height = (int)e.PageSettings.PrintableArea.Height;
809
                m.X = (int)e.PageSettings.HardMarginX;
810
                m.Y = (int)e.PageSettings.HardMarginY;
811
812
                e.Graphics.DrawImage(pic, m);
813 787a4489 KangIngu
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
814
                //e.Graphics.DrawImage(p_img, 0, 0);
815
            }));
816
            
817
            //다음 페이지
818
            currentPage++;
819
            
820
            ////인쇄를 계속 할지 말지 확인
821
            if (currentPage <= printDocument.PrinterSettings.ToPage)
822
                e.HasMorePages = true;
823
            else
824
                e.HasMorePages = false;
825
826
        }
827
828
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
829
        {
830
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
831
            {
832
                printIndy.IsBusy = false;
833
            }));
834
        }
835
        #endregion
836
837
        #region Selected Pages Check
838
        List<int> PrintPageCreate()
839
        {
840
            List<int> Result = new List<int>();
841
842
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
843
            {
844
                Result.Add(CurrentPageNo);
845
            }
846
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
847
            {
848
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
849
                {
850
                    Result.Add(i);
851
                }
852
            }
853
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
854
            {
855
                int _stPage = (int)stPageNo.Value;
856
                int _edPage = (int)edPageNo.Value;
857
858
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
859
                Result.AddRange(lst);
860
            }
861
            else
862
            {
863
                for (int i = 1; i <= _definePages.PagesCount; i++)
864
                {
865
                    Result.Add(i);
866
                }
867
            }
868
            if (currentPagePrint)
869
            {
870
                return Result;
871
            }
872
873
            if (chkOnlyMarkup.IsChecked.Value)
874
            {
875
                var _result = from result in Result
876
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
877
                              select result;
878
                Result = _result.ToList();
879
            }
880
            return Result;
881
        }
882
        #endregion
883
884
        #endregion
885
    }
886
}
클립보드 이미지 추가 (최대 크기: 500 MB)