프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (38.7 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 KCOMDataModel.DataModel;
12
using Microsoft.Win32;
13
using System.IO;
14
using System.Timers;
15
//using IKCOM.Common;
16
using KCOM.Event;
17
using iTextSharp;
18
using iTextSharp.text;
19
//using Leadtools.Windows.Controls;
20
using IKCOM;
21
using iTextSharp.text.pdf;
22
using Microsoft.Office.Core;
23
using System.Net;
24
using Image = System.Windows.Controls.Image;
25

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

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

    
38
        public double CurrentValue { get; set; }
39

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

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

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

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

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

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

    
81

    
82
                try
83
                {
84

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

    
94
            }
95
        }
96
    }
97

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

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

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

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

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

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

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

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

    
147

    
148
        #endregion
149

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

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

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

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

    
173
        }
174
        #endregion
175

    
176
        #region 생성자
177

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

    
182
            this.IsEnabled = true;
183

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

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

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

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

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

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

    
227
            this.CurrentPageNo = _StartPageNo;
228

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

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

    
235
            CheckCommentPages();
236

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

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

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

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

    
265
            _initializeComponentFinished = true;
266

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

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

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

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

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

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

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

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

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

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

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

    
365
            CheckCommentPages();
366
        }
367

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

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

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

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

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

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

    
413
        #endregion
414

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

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

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

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

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

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

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

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

    
462

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

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

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

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

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

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

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

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

    
533

    
534
                _lstPrintPageNo = PrintPageCreate();
535

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

    
549
                int cnt = 0;
550

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

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

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

    
578
        }
579

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
675
                                                    Export_img.SetAbsolutePosition(0, 0);
676

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

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

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

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

    
724
                    await PageChangeAsync(_StartPageNo);
725

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

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

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

    
749

    
750
        }
751
        #endregion
752

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

    
759

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
933
        }
934

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

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

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

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

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

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