프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (38.8 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
using System.Net;
25
using Image = System.Windows.Controls.Image;
26

    
27
namespace KCOM.Control
28
{
29
    public class DefinedPages
30
    {
31
        public DOCINFO DocumentInfo { get; set; }
32

    
33
        public int PagesCount { get; set; }
34
        public string vpSlip { get; set; }
35
        public string vpTitle { get; set; }
36
        public string fileUrl { get; set; }
37
        public ImageBrush Back_Image { get; set; }
38

    
39
        public double CurrentValue { get; set; }
40

    
41
        string _DefinedPagesStrings;
42
        /// <summary>
43
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
44
        /// </summary>
45
        public string DefinedPagesStrings
46
        {
47
            get { return _DefinedPagesStrings; }
48
            set
49
            {
50
                if (string.IsNullOrWhiteSpace(value)) return;
51

    
52
                var _definedPages = value.Replace('-', ',').Split(',');
53
                List<char> _NotEx = new List<char>();
54

    
55
                foreach (var item in _definedPages)
56
                {
57
                    bool _isNum = true;
58

    
59
                    foreach (var chr in item)
60
                    {
61
                        if (!char.IsNumber(chr))
62
                        {
63
                            _NotEx.Add(chr);
64
                            _isNum = false;
65
                        }
66
                    }
67

    
68
                    if (_isNum)
69
                    {
70
                        if (Convert.ToInt32(item) > PagesCount)
71
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
72
                    }
73
                }
74

    
75
                if (_NotEx.Count() > 0)
76
                {
77
                    string _notString = "";
78
                    _NotEx.ForEach(s => _notString += s.ToString());
79
                    throw new Exception(string.Format("'{0}' Can not be added.", _notString));
80
                }
81

    
82

    
83
                try
84
                {
85

    
86
                    string _notString2 = "";
87
                    _NotEx.ForEach(s => _notString2 += s.ToString());
88
                    _DefinedPagesStrings = value;
89
                }
90
                catch (Exception)
91
                {
92
                    throw new Exception(string.Format("Can not be added."));
93
                }
94

    
95
            }
96
        }
97
    }
98

    
99
    /// <summary>
100
    /// Interaction logic for Print.xaml
101
    /// </summary>
102
    public partial class PrintControl : UserControl
103
    {
104
        #region Data
105

    
106
        string ProjectNo = null; //프로젝트 넘버
107
        string _DefaultTileUri = null; //기본 타일 경로
108
        int _StartPageNo; //시작페이지 
109
        DOCINFO _DocInfo; //문서 정보
110
        //DocInfo _DocInfo; //문서 정보
111
        bool currentPagePrint = false; //현재 페이지 수
112
        int PageCount { get; set; } //총 페이지수 
113
        DefinedPages _definePages = null; //인쇄 설정 범위 지정
114
        public bool IsPrint { get; set; }
115

    
116
        PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성
117

    
118
        //LayerControl LayerControl = null; // 레이어 컨트롤
119
        ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보
120
        List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>();
121
        List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>();
122
        List<int> _lstPrintPageNo = new List<int>();
123

    
124
        System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer();
125
        bool _initializeComponentFinished; //이벤트
126
        bool _IsDagSlider = false; //드래그 상태인가
127
        List<DisplayColorInfo> colorList = new List<DisplayColorInfo>();
128
        DefinedPages DocumentInfo { get; set; } //문서정보 정의        
129
        //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 
130
        delegate void PrintEventHandler(); //프린트 핸들러
131
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
132
        //SaveFileDialog SaveFile { get; set; } //저장할 때 사용
133

    
134
        //RasterImageViewer _viewer; //이미지 뷰어
135
        //System.Windows.Controls.Image backimg; //백그라운드 이미지
136
        System.Drawing.Image Printimg; //프린트 이미지
137
        System.Drawing.Image p_img; //프린트 이미지
138
        iTextSharp.text.Image Export_img;
139
        Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지
140

    
141
        //RasterCodecs codecs;
142
        int currentPage;
143
        public string PrintName;
144
        public string Type;
145

    
146
        public System.Timers.Timer timm = new System.Timers.Timer();
147

    
148

    
149
        #endregion
150

    
151
        #region Static Property Defines
152
        public static readonly DependencyProperty CurrentPageNoProperty =
153
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
154
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
155
        #endregion
156

    
157
        #region Property
158
        public int CurrentPageNo
159
        {
160
            get { return (int)GetValue(CurrentPageNoProperty); }
161
            set { SetValue(CurrentPageNoProperty, value); }
162
        }
163
        #endregion
164

    
165
        #region PropertyChangeMethod
166
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
167
        {
168
            var printPage = (PrintControl)d;
169
            var newValue = (int)e.NewValue;
170

    
171
            printPage.sliderPages.Value = newValue;
172
            printPage.SetLoadMakupList(newValue);
173

    
174
        }
175
        #endregion
176

    
177
        #region 생성자
178

    
179
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
180
        {
181
            InitializeComponent();
182

    
183
            this.IsEnabled = true;
184

    
185
            //Layer Control을 통째로 가져와야 하는건가
186
            this._DocInfo = DocInfo;
187
            this._DefaultTileUri = TileSourceUri;
188
            this.ProjectNo = ProjectNo;
189
            this._StartPageNo = CurrentPageNo;
190

    
191
            markupInfo.ForEach(info => this._markupInfo.Add(info));
192

    
193
            foreach (var info in _markupInfo)
194
            {
195
                if (info.Consolidate == 1)
196
                {
197
                    info.UserName = "Consolidation";
198
                }
199
                info.MarkupList.ForEach(makup =>
200
                {
201
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
202
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
203

    
204
                    if (_pageMarkup.Count() > 0)
205
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
206
                    else
207
                        _PageMarkupList.Add(new MarkupPageItem
208
                        {
209
                            PageNumber = makup.PageNumber,
210
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
211
                        });
212
                });
213

    
214
                colorList.Add(new DisplayColorInfo
215
                {
216
                    UserID = info.UserID,
217
                    DisplayColor = info.DisplayColor,
218
                    Department = info.Depatment,
219
                    UserName = info.UserName,
220
                });
221
            }
222

    
223
            gridViewMarkup.ItemsSource = this._markupInfo;
224
            SetLoadMakupList(this._StartPageNo);
225
            if (_LoadMakupList.Count() == 0)
226
                chkOnlyMarkup.IsChecked = false;
227

    
228
            this.CurrentPageNo = _StartPageNo;
229

    
230
            _definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo
231
                            , PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
232

    
233
            DocumentInfo = _definePages;
234
            this.DataContext = _definePages;
235

    
236
            CheckCommentPages();
237

    
238
            //초기화면 Comment Check된 상태로 보여주기
239
            foreach (var item in _markupInfo)
240
            {
241
                gridViewMarkup.SelectedItems.Add(item);
242
            }
243

    
244
            PageChangeAsync(_StartPageNo).ConfigureAwait(true);
245

    
246
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
247
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
248
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
249
            this.IsPrint = isPrint;
250

    
251
            if (!IsPrint)
252
            {
253
                GetPrint(false);
254
                btnWholeExport.Visibility = Visibility.Visible;
255
                btnWholePrint.Visibility = Visibility.Collapsed;
256
                Selected_Print.Header = "Export Type";
257
            }
258
            else
259
            {
260
                //PrintList 가져오기
261
                GetPrint(true);
262
                btnWholePrint.Visibility = Visibility.Visible;
263
                btnWholeExport.Visibility = Visibility.Collapsed;
264
            }
265

    
266
            _initializeComponentFinished = true;
267

    
268
            //timm.Interval = 10;
269
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
270
            //timm.Enabled = true;
271
        }
272

    
273
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
274
        {
275
            timm.Enabled = false;
276
            PageChangeAsync(_StartPageNo);
277
        }
278
        #endregion
279

    
280
        #region Control Event
281
        private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
282
        {
283
            if (_initializeComponentFinished)
284
            {
285
                if (!_IsDagSlider)
286
                {
287
                    this.CurrentPageNo = (int)this.sliderPages.Value;
288
                    await PageChangeAsync(this.CurrentPageNo);
289
                    //await App.PageStorage.GetPageUriAsync(this.CurrentPageNo);
290
                
291
                    if (_ButtonName == "Current")
292
                    {
293
                        stPageNo.Value = CurrentPageNo;
294
                        edPageNo.Value = CurrentPageNo;
295
                    }
296

    
297
                    //CheckCommentPages();
298
                }
299
            }
300
        }
301

    
302
        private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
303
        {
304
            _IsDagSlider = false;
305
            this.CurrentPageNo = (int)this.sliderPages.Value;
306
            if (_initializeComponentFinished)
307
            {
308
               
309
            }
310
        }
311

    
312
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
313
        {
314
            _IsDagSlider = true;
315
        }
316

    
317
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
318
        {
319
            if (_initializeComponentFinished)      //GridRangePages
320
            {
321
                CheckCommentPages();
322
            }
323
        }
324
        string _ButtonName;
325
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
326
        {
327
            if (!_initializeComponentFinished) return;
328

    
329
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
330
            CommentPageList.ItemsSource = null;
331

    
332
            switch (_ButtonName)
333
            {
334
                case "Current":
335
                    stPageNo.Value = CurrentPageNo;
336
                    edPageNo.Value = CurrentPageNo;
337

    
338
                    GridCurrentPage.Visibility = Visibility.Visible;
339
                    GridDefinePages.Visibility = Visibility.Collapsed;
340
                    GridRangePages.Visibility = Visibility.Collapsed;
341
                    GridAllPages.Visibility = Visibility.Collapsed;
342

    
343
                    break;
344
                case "RangePrint":
345
                    GridCurrentPage.Visibility = Visibility.Collapsed;
346
                    GridDefinePages.Visibility = Visibility.Visible;
347
                    GridRangePages.Visibility = Visibility.Collapsed;
348
                    GridAllPages.Visibility = Visibility.Collapsed;
349
                    break;
350
                case "UserDefined":
351
                    GridCurrentPage.Visibility = Visibility.Collapsed;
352
                    GridDefinePages.Visibility = Visibility.Collapsed;
353
                    GridRangePages.Visibility = Visibility.Visible;
354
                    GridAllPages.Visibility = Visibility.Collapsed;
355
                    break;
356
                case "AllPrint":
357
                    stPageNo.Value = 1;
358
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
359
                    GridCurrentPage.Visibility = Visibility.Collapsed;
360
                    GridDefinePages.Visibility = Visibility.Collapsed;
361
                    GridRangePages.Visibility = Visibility.Collapsed;
362
                    GridAllPages.Visibility = Visibility.Visible;
363
                    break;
364
            }
365

    
366
            CheckCommentPages();
367
        }
368

    
369
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
370
        {
371
            if (_initializeComponentFinished)      //GridRangePages
372
            {
373
                if (stPageNo.Value > edPageNo.Value)
374
                {
375
                    if (sender.Equals(stPageNo))
376
                        edPageNo.Value = stPageNo.Value;
377
                    else
378
                        stPageNo.Value = edPageNo.Value;
379
                }
380

    
381
                //뷰어잠시제외(강인구)
382
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
383
                //{
384
                CheckCommentPages();
385
                //});
386
            }
387
        }
388

    
389
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
390
        {
391
            CheckCommentPages();
392
        }
393

    
394
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
395
        {
396
            txtDefinedPages.Text = "";
397
        }
398

    
399
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
400
        {
401
            if (_initializeComponentFinished)
402
                if (CommentPageList.SelectedItem != null)
403
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
404
        }
405

    
406
        private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
407
        {
408
            if (_initializeComponentFinished)
409
            {
410
                await PageChangeAsync(this.CurrentPageNo);
411
            }
412
        }
413

    
414
        #endregion
415

    
416
        public async System.Threading.Tasks.Task<bool> PageChangeAsync(int PageNo, bool Flag = false)
417
        {
418
            System.Diagnostics.Debug.WriteLine("PageChangeAsync " + PageNo);
419
            bool result = false;
420
            //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
421
            //{
422
            try
423
            {
424
                Load load = new Load();
425

    
426
                _definePages.Back_Image = new ImageBrush();
427
                //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
428

    
429
                var pages = _definePages.DocumentInfo.DOCPAGE.Where(x => x.PAGE_NUMBER == PageNo);
430

    
431
                if(pages.Count() > 0)
432
                {
433
                    var currentPage = pages.First();
434

    
435
                    //var buffer = await new WebClient().DownloadDataTaskAsync(_DefaultTileUri + PageNo + ".png");
436

    
437
                    //var bitmap = new BitmapImage();
438
                    //using (var stream = new MemoryStream(buffer))
439
                    //{
440
                    //bitmap.BeginInit();
441
                    //bitmap.CacheOption = BitmapCacheOption.OnLoad;
442
                    //bitmap.StreamSource = stream;
443
                    //bitmap.EndInit();
444

    
445
                        
446
                    var uri = await  App.PageStorage.GetPageUriAsync(currentPage.PAGE_NUMBER);
447
                    //Image bitmap = new Image();
448
                    //bitmap.Stretch = Stretch.Fill;
449
                    //bitmap.Source = bitmapframe;
450
                    //bitmap.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
451
                    //bitmap.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
452
                    printCanvas.Children.Clear();
453
                    printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
454
                    printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
455
                    printCanvas.Background = new ImageBrush { ImageSource = new BitmapImage(uri)};
456

    
457
                    //printCanvas.RenderTransformOrigin = new Point(0.5, 0.5);
458
                    //printCanvas.RenderTransform = new RotateTransform(currentPage.PAGE_ANGLE);
459
                    //ImageBrush background = new ImageBrush(bitmap);
460
                    //printCanvas.Background = background;
461
                    //printCanvas.Background = new SolidColorBrush(Colors.Transparent);
462

    
463

    
464
                    foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
465
                    {
466
                        load.User_Id = info.UserID;
467
                        load.document_id = _DocInfo.DOCUMENT_ID;
468
                        load.Page_No = PageNo;
469
                        load.DisplayColor = info.DisplayColor;
470
                        load.Markupinfoid = info.MarkupInfoID;
471
                        var IsLoad = await load.Markup_LoadAsync(printCanvas);
472
                    }
473
                    //await Dispatcher.InvokeAsync(() => {
474
                    //    printCanvas.UpdateLayout();
475
                    //});
476

    
477
                    if (Flag)
478
                        {
479
                        //MemoryStream ms = new MemoryStream();
480
                        //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
481
                        //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
482
                        //bbe.Save(ms);
483

    
484
                        //System.Drawing.Image.FromFile()
485
                        //Printimg = System.Drawing.Image.FromStream(stream);
486
                        //await System.Threading.Tasks.Task.Run(() =>
487
                        //{
488
                           await Dispatcher.InvokeAsync(() =>
489
                            {
490
                                Export export = new Export();
491
                                p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height);
492
                                Printimg_List.Add(Printimg_List.Count() + 1, p_img);
493
                            },System.Windows.Threading.DispatcherPriority.Render);
494
                        //});
495
                    }
496

    
497
                        result = true;
498
                    //}
499
                } 
500
            }
501
            catch (Exception ex)
502
            {
503
                Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
504
            }
505

    
506
            return result;
507
            //}));
508
        }
509
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
510
        {
511
            var ms = new MemoryStream();
512
            var pngEncoder = new PngBitmapEncoder();
513
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
514
            pngEncoder.Save(ms);
515

    
516
            return ms;
517
        }
518
        //Print 버튼 클릭 이벤트
519
        #region Method - 명령
520
        async void PrintMethod(object sender, RoutedEventArgs e)
521
        {
522
            try
523
            {
524
                if (this.printIndy.IsBusy == true)
525
                    return;
526

    
527
                (this.Parent as RadWindow).CanClose = false;
528

    
529
                await this.Dispatcher.InvokeAsync(() => { 
530
                        this.printIndy.IsBusy = true;
531
                        printIndy.BusyContent = "Printing. . .";
532
                });
533

    
534

    
535
                _lstPrintPageNo = PrintPageCreate();
536

    
537
                if (_lstPrintPageNo.Count == 0)
538
                {
539
                    RadWindow.Alert(new DialogParameters
540
                    {
541
                        Owner = Application.Current.MainWindow,
542
                        Theme = new VisualStudio2013Theme(),
543
                        Header = "Info",
544
                        Content = "Not specified the page."
545
                    });
546
                    this.printIndy.IsBusy = false;
547
                    return;
548
                }
549

    
550
                int cnt = 0;
551

    
552
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
553

    
554
                foreach (int PageNo in _lstPrintPageNo)
555
                {
556
                    cnt++;
557
                    sliderPages.Value = PageNo;
558
                    await PageChangeAsync(PageNo, true);
559
                    //PageChanged(cnt, true);
560
                }
561
                PrintName = cbPrint.SelectedItem.ToString();
562

    
563
                await this.Dispatcher.InvokeAsync(() => {
564
                    if (cnt == _lstPrintPageNo.Count)
565
                    {
566
                        Printing();
567
                    }
568
                });
569
            }
570
            catch (Exception ex)
571
            {
572
                Logger.sendResLog("PrintMethod", ex.Message, 0);
573
            }
574
            finally
575
            {
576
                (this.Parent as RadWindow).CanClose = true;
577
            }
578

    
579
        }
580

    
581
        //Export 버튼 클릭 이벤트
582
        async void ExportMethod(object sender, RoutedEventArgs e)
583
        {
584
            try
585
            {
586
                if (this.printIndy.IsBusy == true)
587
                    return;
588

    
589
                (this.Parent as RadWindow).CanClose = false;
590

    
591
                this.printIndy.IsBusy = true;
592
                printIndy.BusyContent = "Exporting. . .";
593

    
594
                Export export = new Export();
595
                _lstPrintPageNo = PrintPageCreate();
596

    
597
                if (_lstPrintPageNo.Count == 0)
598
                {
599
                    this.printIndy.IsBusy = false;
600
                    RadWindow.Alert(new DialogParameters
601
                    {
602
                        Owner = Application.Current.MainWindow,
603
                        Theme = new VisualStudio2013Theme(),
604
                        Header = "Info",
605
                        Content = "Not specified the page.",
606
                    });
607
                    return;
608
                }
609

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

    
612
                switch (cbPrint.SelectedIndex)
613
                {
614
                    case (0):
615
                        {
616
                            SaveDig.Filter = "PDF file format|*.pdf";
617
                            break;
618
                        }
619
                    case (1):
620
                        {
621
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
622
                            break;
623
                        }
624
                }
625

    
626
                SaveDig.Title = "Save an PDF File";
627
                if(SaveDig.ShowDialog().Value)
628
                {
629
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
630

    
631
                    foreach (int PageNo in _lstPrintPageNo)
632
                    {
633
                        await Dispatcher.InvokeAsync(() =>
634
                        {
635
                            sliderPages.Value = PageNo;
636
                        });
637

    
638
                        await PageChangeAsync(PageNo, true);
639
                        System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo);
640
                    }
641

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

    
644
                    if (SaveDig.FileName != "")
645
                    {
646
                        switch (cbPrint.SelectedIndex)
647
                        {
648
                            case (0):
649
                                {
650
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
651
                                    {
652
                                        using (Document doc = new Document())
653
                                        {
654
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
655
                                            {
656
                                                doc.Open();
657
                                                
658
                                                float height = doc.PageSize.Height;
659
                                                float width = doc.PageSize.Width;
660

    
661
                                                foreach (var item in Printimg_List)
662
                                                {
663
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
664

    
665
                                                    if (Export_img.Width > Export_img.Height)
666
                                                    {
667
                                                        doc.SetPageSize(new Rectangle(height, width));
668
                                                        Export_img.ScaleToFit(height, width);
669
                                                    }
670
                                                    else
671
                                                    {
672
                                                        doc.SetPageSize(new Rectangle(width, height));
673
                                                        Export_img.ScaleToFit(width, height);
674
                                                    }
675

    
676
                                                    Export_img.SetAbsolutePosition(0, 0);
677

    
678
                                                    doc.NewPage();
679
                                                    doc.Add(Export_img);
680

    
681
                                                    await System.Threading.Tasks.Task.Delay(100);
682

    
683
                                                }
684
                                                doc.Close();
685
                                            }
686
                                        }
687
                                    }
688
                                    break;
689
                                }
690
                            case (1):
691
                                {
692
                                    foreach (var item in Printimg_List)
693
                                    {
694
                                        switch (SaveDig.FilterIndex)
695
                                        {
696
                                            case (1):
697
                                                {
698
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
699
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
700
                                                }
701
                                                break;
702
                                            case (2):
703
                                                {
704
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
705
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
706
                                                }
707
                                                break;
708
                                        }
709
                                    }
710
                                    break;
711
                                }
712
                        }
713
                    }
714
                    else
715
                    {
716
                        this.printIndy.IsBusy = false;
717
                        return;
718
                    }
719

    
720
                    await this.Dispatcher.InvokeAsync(() =>
721
                    {
722
                        printIndy.IsBusy = false;
723
                    });
724

    
725
                    await PageChangeAsync(_StartPageNo);
726

    
727
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
728
                }else
729
                {
730
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
731
                    {
732
                        printIndy.IsBusy = false;
733
                    }));
734

    
735
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
736
                }                
737
            }
738
            catch (Exception ex)
739
            {
740
                printIndy.IsBusy = false;
741

    
742
                Logger.sendResLog("Export Method", ex.Message, 0);
743
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
744
            }
745
            finally
746
            {
747
                (this.Parent as RadWindow).CanClose = true;
748
            }
749

    
750

    
751
        }
752
        #endregion
753

    
754
        #region Method - 처리
755
        void CheckCommentPages()
756
        {
757
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
758
            DoubleCollection _Ticks = new DoubleCollection();
759

    
760

    
761
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
762
            {
763

    
764
                _pages = (from commPage in this._PageMarkupList
765
                          where commPage.PageNumber == CurrentPageNo
766
                          orderby commPage.PageNumber
767
                          select commPage).ToList();
768
            }
769
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
770
            {
771
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
772
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
773

    
774
                int _stPage = (int)stPageNo.Value;
775
                int _edPage = (int)edPageNo.Value;
776

    
777
                _pages = (from commPage in this._PageMarkupList
778
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
779
                          orderby commPage.PageNumber
780
                          select commPage).ToList();
781
            }
782
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
783
            {
784
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
785
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
786

    
787
                int _stPage = (int)stPageNo.Value;
788
                int _edPage = (int)edPageNo.Value;
789

    
790
                //Using DeepView.Common.RangeParser
791
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
792
                _pages = (from commPage in this._PageMarkupList
793
                          from compareData in lst
794
                          where commPage.PageNumber == compareData
795
                          orderby commPage.PageNumber
796
                          select commPage).ToList();
797
            }
798
            else
799
            {
800
                _pages = (from commPage in this._PageMarkupList
801
                          orderby commPage.PageNumber
802
                          select commPage).ToList();
803
            }
804
            CommentPageList.ItemsSource = _pages.ToList();
805
        }
806

    
807
        void SetLoadMakupList(int PageNo)
808
        {
809
            _LoadMakupList.Clear();
810
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
811

    
812
            if (_markupList.Count() > 0)
813
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
814
        }
815

    
816
        #region 프린트 리스트 가져오기
817
        public void GetPrint(bool flag)
818
        {
819
            if (flag)
820
            {
821
                foreach (string printer in PrinterSettings.InstalledPrinters)
822
                {
823
                    this.cbPrint.Items.Add(printer);
824
                }
825
                printDocument = new PrintDocument();
826
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
827
            }
828
            else
829
            {
830
                this.cbPrint.Items.Add("PDF");
831
                this.cbPrint.Items.Add("IMAGE");
832

    
833
                this.cbPrint.SelectedItem = "PDF";
834
            }
835
        }
836
        #endregion
837

    
838
        #region 프린트 실행
839
        public async void Printing()
840
        {
841
            await PageChangeAsync(1);
842

    
843
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
844
            {
845
                printDocument = new PrintDocument();
846
                printDocument.OriginAtMargins = true;
847
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
848
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
849
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
850
            }
851
            else
852
                printDocument = null;
853

    
854
            #region 인쇄 미리보기 테스트
855
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
856
            {
857
                printDocument.PrinterSettings.MinimumPage = 1;
858
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
859
                printDocument.PrinterSettings.FromPage = 1;
860
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
861
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
862
                printDocument.PrinterSettings.PrinterName = PrintName;
863
                dlg.Document = printDocument;
864
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
865
                dlg.ShowDialog();
866
            }
867
            #endregion
868

    
869
            #region 인쇄
870
            //printDocument.PrinterSettings.MinimumPage = 1;
871
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
872
            //printDocument.PrinterSettings.FromPage = 1;
873
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
874

    
875
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
876
            //printDocument.PrinterSettings.PrinterName = PrintName;
877

    
878
            //printDocument.Print();
879
            #endregion
880
        }
881

    
882
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
883
        {
884
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
885
            // This demo only loads one page at a time, so no need to re-set the print page number
886
            PrintDocument document = sender as PrintDocument;
887
            currentPage = document.PrinterSettings.FromPage;
888
        }
889

    
890
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
891
        {
892
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
893

    
894
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
895
            {
896
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
897

    
898
                if (p_img.Width > p_img.Height)
899
                {
900
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
901
                }
902

    
903
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
904
                System.Drawing.Image pic = p_img;
905
                System.Drawing.Rectangle m = e.MarginBounds;
906

    
907
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
908
                //{
909
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
910
                //}
911
                //else
912
                //{
913
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
914
                //}
915
                m.Width = (int)e.PageSettings.PrintableArea.Width;
916
                m.Height = (int)e.PageSettings.PrintableArea.Height;
917
                m.X = (int)e.PageSettings.HardMarginX;
918
                m.Y = (int)e.PageSettings.HardMarginY;
919

    
920
                e.Graphics.DrawImage(pic, m);
921
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
922
                //e.Graphics.DrawImage(p_img, 0, 0);
923
            }));
924

    
925
            //다음 페이지
926
            currentPage++;
927

    
928
            ////인쇄를 계속 할지 말지 확인
929
            if (currentPage <= printDocument.PrinterSettings.ToPage)
930
                e.HasMorePages = true;
931
            else
932
                e.HasMorePages = false;
933

    
934
        }
935

    
936
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
937
        {
938
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
939
            {
940
                printIndy.IsBusy = false;
941
            }));
942
        }
943
        #endregion
944

    
945
        #region Selected Pages Check
946
        List<int> PrintPageCreate()
947
        {
948
            List<int> Result = new List<int>();
949

    
950
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
951
            {
952
                Result.Add(CurrentPageNo);
953
            }
954
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
955
            {
956
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
957
                {
958
                    Result.Add(i);
959
                }
960
            }
961
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
962
            {
963
                int _stPage = (int)stPageNo.Value;
964
                int _edPage = (int)edPageNo.Value;
965

    
966
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
967
                Result.AddRange(lst);
968
            }
969
            else
970
            {
971
                for (int i = 1; i <= _definePages.PagesCount; i++)
972
                {
973
                    Result.Add(i);
974
                }
975
            }
976
            if (currentPagePrint)
977
            {
978
                return Result;
979
            }
980

    
981
            if (chkOnlyMarkup.IsChecked.Value)
982
            {
983
                var _result = from result in Result
984
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
985
                              select result;
986
                Result = _result.ToList();
987
            }
988
            return Result;
989
        }
990
        #endregion
991

    
992
        #endregion
993
    }
994
}
클립보드 이미지 추가 (최대 크기: 500 MB)