프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 2024d8d1

이력 | 보기 | 이력해설 | 다운로드 (33.1 KB)

1
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

    
25
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
        
173
        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
                    //CheckCommentPages();
282
                }
283
            }
284
        }
285

    
286
        private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
287
        {
288
            _IsDagSlider = false;
289
            this.CurrentPageNo = (int)this.sliderPages.Value;
290
            if (_initializeComponentFinished)
291
            {
292
                PageChanged(this.CurrentPageNo);
293
            }
294
        }
295

    
296
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
297
        {
298
            _IsDagSlider = true;
299
        }
300

    
301
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
302
        {
303
            if (_initializeComponentFinished)      //GridRangePages
304
            {
305
                CheckCommentPages();
306
            }
307
        }
308

    
309
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
310
        {
311
            if (!_initializeComponentFinished) return;
312

    
313
            string _ButtonName = (sender as RadRadioButton).Tag.ToString();
314
            CommentPageList.ItemsSource = null;
315

    
316
            switch (_ButtonName)
317
            {
318
                case "Current":
319
                    stPageNo.Value = CurrentPageNo;
320
                    edPageNo.Value = CurrentPageNo;
321

    
322
                    GridCurrentPage.Visibility = Visibility.Visible;
323
                    GridDefinePages.Visibility = Visibility.Collapsed;
324
                    GridRangePages.Visibility = Visibility.Collapsed;
325
                    GridAllPages.Visibility = Visibility.Collapsed;
326

    
327
                    break;
328
                case "RangePrint":
329
                    GridCurrentPage.Visibility = Visibility.Collapsed;
330
                    GridDefinePages.Visibility = Visibility.Visible;
331
                    GridRangePages.Visibility = Visibility.Collapsed;
332
                    GridAllPages.Visibility = Visibility.Collapsed;
333
                    break;
334
                case "UserDefined":
335
                    GridCurrentPage.Visibility = Visibility.Collapsed;
336
                    GridDefinePages.Visibility = Visibility.Collapsed;
337
                    GridRangePages.Visibility = Visibility.Visible;
338
                    GridAllPages.Visibility = Visibility.Collapsed;
339
                    break;
340
                case "AllPrint":
341
                    stPageNo.Value = 1;
342
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
343
                    GridCurrentPage.Visibility = Visibility.Collapsed;
344
                    GridDefinePages.Visibility = Visibility.Collapsed;
345
                    GridRangePages.Visibility = Visibility.Collapsed;
346
                    GridAllPages.Visibility = Visibility.Visible;
347
                    break;
348
            }
349

    
350
            CheckCommentPages();
351
        }
352

    
353
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
354
        {
355
            if (_initializeComponentFinished)      //GridRangePages
356
            {
357
                if (stPageNo.Value > edPageNo.Value)
358
                {
359
                    if (sender.Equals(stPageNo))
360
                        edPageNo.Value = stPageNo.Value;
361
                    else
362
                        stPageNo.Value = edPageNo.Value;
363
                }
364

    
365
                //뷰어잠시제외(강인구)
366
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
367
                //{
368
                CheckCommentPages();
369
                //});
370
            }
371
        }
372

    
373
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
374
        {
375
            CheckCommentPages();
376
        }
377

    
378
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
379
        {
380
            txtDefinedPages.Text = "";
381
        }
382

    
383
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
384
        {
385
            if (_initializeComponentFinished)
386
                if (CommentPageList.SelectedItem != null)
387
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
388
        }
389

    
390
        private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
391
        {
392
            if (_initializeComponentFinished)
393
            {
394
                PageChanged(this.CurrentPageNo);
395
            }
396
        }
397

    
398
        #endregion
399

    
400
        public void PageChanged(int PageNo, bool Flag = false)
401
        {
402
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
403
            {
404
                Load load = new Load();
405
                
406
                _definePages.Back_Image = new ImageBrush();
407
                var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
408

    
409
                printCanvas.Children.Clear();
410

    
411
                ImageBrush background = new ImageBrush(defaultBitmapImage);
412
                printCanvas.Background = background;
413

    
414
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
415
                printCanvas.Width = image.Width;
416
                printCanvas.Height = image.Height;
417

    
418
                foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
419
                {
420
                    load.User_Id = info.UserID;
421
                    load.document_id = _DocInfo.DOCUMENT_ID;
422
                    load.Page_No = PageNo;
423
                    load.DisplayColor = info.DisplayColor;
424
                    load.Markupinfoid = info.MarkupInfoID;
425
                    load.Markup_Load(printCanvas);
426
                }
427

    
428
                printCanvas.UpdateLayout();
429

    
430
                if(Flag)
431
                {
432
                    MemoryStream ms = new MemoryStream();
433
                    BmpBitmapEncoder bbe = new BmpBitmapEncoder();
434
                    bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
435
                    bbe.Save(ms);
436

    
437
                    Printimg = System.Drawing.Image.FromStream(ms);
438
                    Export export = new Export();
439
                    p_img = export.Exporting(printCanvas, Printimg);
440
                    Printimg_List.Add(Printimg_List.Count() + 1, p_img);
441
                }
442
            }));
443
        }
444

    
445
        //Print 버튼 클릭 이벤트
446
        #region Method - 명령
447
        void PrintMethod(object sender, RoutedEventArgs e)
448
        {
449

    
450
            if (this.printIndy.IsBusy == true)
451
                return;
452

    
453
            System.Threading.Tasks.Task.Factory.StartNew(() =>
454
            {
455
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
456
                {
457
                    this.printIndy.IsBusy = true;
458
                    printIndy.BusyContent = "Printing. . .";
459
                }));
460
            });
461

    
462

    
463
            _lstPrintPageNo = PrintPageCreate();
464

    
465
            if (_lstPrintPageNo.Count == 0)
466
            {
467
                RadWindow.Alert(new DialogParameters
468
                {
469
                    Theme = new VisualStudio2013Theme(),
470
                    Header = "안내",
471
                    Content = "페이지가 지정되지 않았습니다."
472
                });
473
                this.printIndy.IsBusy = false;
474
                return;
475
            }
476
            int cnt = 0;
477
            List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
478

    
479
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
480

    
481
            foreach (int PageNo in _lstPrintPageNo)
482
            {
483
                cnt++;
484
                sliderPages.Value = PageNo;                
485
                PageChanged(PageNo, true);
486
                //PageChanged(cnt, true);
487
            }
488
            PrintName = cbPrint.SelectedItem.ToString();
489

    
490
            System.Threading.Tasks.Task.Factory.StartNew(() =>
491
            {
492
                if (cnt == _lstPrintPageNo.Count)
493
                {
494
                    Printing();
495
                }
496
            });
497
        }
498

    
499
        //Export 버튼 클릭 이벤트
500
        void ExportMethod(object sender, RoutedEventArgs e)
501
        {
502
            if (this.printIndy.IsBusy == true)
503
                return;
504

    
505
            this.printIndy.IsBusy = true;
506
            printIndy.BusyContent = "Exporting. . .";
507

    
508
            Export export = new Export();
509
            _lstPrintPageNo = PrintPageCreate();
510

    
511
            if (_lstPrintPageNo.Count == 0)
512
            {
513
                this.printIndy.IsBusy = false;
514
                RadWindow.Alert(new DialogParameters
515
                {
516
                    Theme = new VisualStudio2013Theme(),
517
                    Header = "안내",
518
                    Content = "페이지가 지정되지 않았습니다.",
519
                });
520
                return;
521
            }
522

    
523
            //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
524

    
525
            switch (cbPrint.SelectedIndex)
526
            {
527
                case (0):
528
                    {
529
                        SaveDig.Filter = "PDF file format|*.pdf";
530
                        break;
531
                    }
532
                case (1):
533
                    {
534
                        SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
535
                        break;
536
                    }
537
            }
538

    
539
            SaveDig.Title = "Save an PDF File";
540
            SaveDig.ShowDialog();
541
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
542

    
543
            foreach (int PageNo in _lstPrintPageNo)
544
            {
545
                sliderPages.Value = PageNo;
546
                PageChanged(PageNo, true);
547
            }
548

    
549
            //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
550

    
551
            if (SaveDig.FileName != "")
552
            {
553
                switch (cbPrint.SelectedIndex)
554
                {
555
                    case (0):
556
                        {
557
                            using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
558
                            {
559
                                using (Document doc = new Document())
560
                                {
561
                                    using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
562
                                    {
563
                                        doc.Open();
564
                                        float height = doc.PageSize.Height;
565
                                        float width = doc.PageSize.Width;
566

    
567
                                        foreach (var item in Printimg_List)
568
                                        {
569
                                            
570
                                             Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
571

    
572
                                            
573
                                            if (Export_img.Width > Export_img.Height)
574
                                            {
575
                                                doc.SetPageSize(new Rectangle(height, width));
576
                                                Export_img.ScaleToFit(height, width);
577
                                            }
578
                                            else
579
                                            {
580
                                                doc.SetPageSize(new Rectangle(width, height));
581
                                                Export_img.ScaleToFit(width, height);
582
                                            }
583
                                            
584
                                            Export_img.SetAbsolutePosition(0, 0);
585

    
586
                                            doc.NewPage();
587
                                            doc.Add(Export_img);
588
                                        }
589
                                        doc.Close();
590
                                    }
591
                                }
592
                            }
593
                            break;
594
                        }
595
                    case (1):
596
                        {
597
                            foreach (var item in Printimg_List)
598
                            {
599
                                switch(SaveDig.FilterIndex)
600
                                {
601
                                    case (1):
602
                                        {
603
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
604
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
605
                                        }
606
                                        break;
607
                                    case (2):
608
                                        {
609
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
610
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
611
                                        }
612
                                        break;
613
                                }
614
                            }
615
                            break;
616
                        }
617
                }
618
            }
619
            else
620
            {
621
                this.printIndy.IsBusy = false;
622
                return;
623
            }
624

    
625
         
626

    
627
            //docWriter.EndDocument();
628
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
629
            {
630
                printIndy.IsBusy = false;
631
            }));
632
            PageChanged(_StartPageNo);
633

    
634
            (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
635
        }
636
        #endregion
637

    
638
        #region Method - 처리
639
        void CheckCommentPages()
640
        {
641
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
642
            DoubleCollection _Ticks = new DoubleCollection();
643

    
644

    
645
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
646
            {
647

    
648
                _pages = (from commPage in this._PageMarkupList
649
                          where commPage.PageNumber == CurrentPageNo
650
                          orderby commPage.PageNumber
651
                          select commPage).ToList();
652
            }
653
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
654
            {
655
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
656
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
657

    
658
                int _stPage = (int)stPageNo.Value;
659
                int _edPage = (int)edPageNo.Value;
660

    
661
                _pages = (from commPage in this._PageMarkupList
662
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
663
                          orderby commPage.PageNumber
664
                          select commPage).ToList();
665
            }
666
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
667
            {
668
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
669
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
670

    
671
                int _stPage = (int)stPageNo.Value;
672
                int _edPage = (int)edPageNo.Value;
673

    
674
                //Using DeepView.Common.RangeParser
675
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
676
                _pages = (from commPage in this._PageMarkupList
677
                          from compareData in lst
678
                          where commPage.PageNumber == compareData
679
                          orderby commPage.PageNumber
680
                          select commPage).ToList();
681
            }
682
            else
683
            {
684
                _pages = (from commPage in this._PageMarkupList
685
                          orderby commPage.PageNumber
686
                          select commPage).ToList();
687
            }
688
            CommentPageList.ItemsSource = _pages.ToList();
689
        }
690

    
691
        void SetLoadMakupList(int PageNo)
692
        {
693
            _LoadMakupList.Clear();
694
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
695

    
696
            if (_markupList.Count() > 0)
697
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
698
        }
699

    
700
        #region 프린트 리스트 가져오기
701
        public void GetPrint(bool flag)
702
        {
703
            if (flag)
704
            {
705
                foreach (string printer in PrinterSettings.InstalledPrinters)
706
                {
707
                    this.cbPrint.Items.Add(printer);
708
                }
709
                printDocument = new PrintDocument();
710
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
711
            }
712
            else
713
            {
714
                this.cbPrint.Items.Add("PDF");
715
                this.cbPrint.Items.Add("IMAGE");
716

    
717
                this.cbPrint.SelectedItem = "PDF";
718
            }
719
        }
720
        #endregion
721

    
722
        #region 프린트 실행
723
        public void Printing()
724
        {
725
            PageChanged(1);
726
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
727
            {
728
                printDocument = new PrintDocument();
729
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
730
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
731
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
732
            }
733
            else
734
                printDocument = null;
735

    
736
            #region 인쇄 미리보기 테스트
737
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
738
            {
739
                printDocument.PrinterSettings.MinimumPage = 1;
740
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
741
                printDocument.PrinterSettings.FromPage = 1;
742
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();          
743
                
744
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
745
                printDocument.PrinterSettings.PrinterName = PrintName;
746
                
747
                dlg.Document = printDocument;
748
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
749
                dlg.ShowDialog();
750
            }
751
            #endregion
752

    
753
            #region 인쇄
754
            //printDocument.PrinterSettings.MinimumPage = 1;
755
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
756
            //printDocument.PrinterSettings.FromPage = 1;
757
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
758

    
759
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
760
            //printDocument.PrinterSettings.PrinterName = PrintName;
761

    
762
            //printDocument.Print();
763
            #endregion
764
        }
765

    
766
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
767
        {
768
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
769
            // This demo only loads one page at a time, so no need to re-set the print page number
770
            PrintDocument document = sender as PrintDocument;            
771
            currentPage = document.PrinterSettings.FromPage;
772
        }
773

    
774
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
775
        {
776
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
777

    
778
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
779
            {
780
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
781

    
782
                if(p_img.Width > p_img.Height)
783
                {
784
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
785
                }
786
                
787
                iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
788
                System.Drawing.Rectangle m = e.MarginBounds;
789

    
790
                if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
791
                {
792
                    m.Height = (int)((double)pic.Height / (double)pic.Width * (double)m.Width);
793
                }
794
                else
795
                {
796
                    m.Width = (int)((double)pic.Width / (double)pic.Height * (double)m.Height);
797
                }
798
                                
799
                e.Graphics.DrawImage(p_img, m);
800
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
801
                //e.Graphics.DrawImage(p_img, 0, 0);
802

    
803

    
804
            }));
805
            
806
            //다음 페이지
807
            currentPage++;
808
            
809
            ////인쇄를 계속 할지 말지 확인
810
            if (currentPage <= printDocument.PrinterSettings.ToPage)
811
                e.HasMorePages = true;
812
            else
813
                e.HasMorePages = false;
814

    
815
        }
816

    
817
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
818
        {
819
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
820
            {
821
                printIndy.IsBusy = false;
822
            }));
823
        }
824
        #endregion
825

    
826
        #region Selected Pages Check
827
        List<int> PrintPageCreate()
828
        {
829
            List<int> Result = new List<int>();
830

    
831
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
832
            {
833
                Result.Add(CurrentPageNo);
834
            }
835
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
836
            {
837
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
838
                {
839
                    Result.Add(i);
840
                }
841
            }
842
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
843
            {
844
                int _stPage = (int)stPageNo.Value;
845
                int _edPage = (int)edPageNo.Value;
846

    
847
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
848
                Result.AddRange(lst);
849
            }
850
            else
851
            {
852
                for (int i = 1; i <= _definePages.PagesCount; i++)
853
                {
854
                    Result.Add(i);
855
                }
856
            }
857
            if (currentPagePrint)
858
            {
859
                return Result;
860
            }
861

    
862
            if (chkOnlyMarkup.IsChecked.Value)
863
            {
864
                var _result = from result in Result
865
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
866
                              select result;
867
                Result = _result.ToList();
868
            }
869
            return Result;
870
        }
871
        #endregion
872

    
873
        #endregion
874
    }
875
}
클립보드 이미지 추가 (최대 크기: 500 MB)