프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 53deabaf

이력 | 보기 | 이력해설 | 다운로드 (38.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
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

    
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
                await PageChangeAsync(this.CurrentPageNo);
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
                        printCanvas.Children.Clear();
446
                        var bitmapframe = await  App.PageStorage.GetPageImageAsync(PageNo);
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.Add(bitmap);
453
                         
454
                        //ImageBrush background = new ImageBrush(bitmap);
455
                        //printCanvas.Background = background;
456
                        printCanvas.Background = new SolidColorBrush(Colors.Transparent);
457

    
458
                        printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
459
                        printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
460

    
461
                        foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
462
                        {
463
                            load.User_Id = info.UserID;
464
                            load.document_id = _DocInfo.DOCUMENT_ID;
465
                            load.Page_No = PageNo;
466
                            load.DisplayColor = info.DisplayColor;
467
                            load.Markupinfoid = info.MarkupInfoID;
468
                            await load.Markup_LoadAsync(printCanvas);
469
                        }
470

    
471
                    await Dispatcher.InvokeAsync(() => {
472
                        printCanvas.UpdateLayout();
473
                    });
474

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

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

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

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

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

    
525
                await this.Dispatcher.InvokeAsync(() => { 
526
                        this.printIndy.IsBusy = true;
527
                        printIndy.BusyContent = "Printing. . .";
528
                });
529

    
530

    
531
                _lstPrintPageNo = PrintPageCreate();
532

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

    
546
                int cnt = 0;
547

    
548
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
549

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

    
559
                await this.Dispatcher.InvokeAsync(() => {
560
                    if (cnt == _lstPrintPageNo.Count)
561
                    {
562
                        Printing();
563
                    }
564
                });
565
            }
566
            catch (Exception ex)
567
            {
568
                Logger.sendResLog("PrintMethod", ex.Message, 0);
569
            }
570

    
571
        }
572

    
573
        //Export 버튼 클릭 이벤트
574
        async void ExportMethod(object sender, RoutedEventArgs e)
575
        {
576
            try
577
            {
578
                if (this.printIndy.IsBusy == true)
579
                    return;
580

    
581
                this.printIndy.IsBusy = true;
582
                printIndy.BusyContent = "Exporting. . .";
583

    
584
                Export export = new Export();
585
                _lstPrintPageNo = PrintPageCreate();
586

    
587
                if (_lstPrintPageNo.Count == 0)
588
                {
589
                    this.printIndy.IsBusy = false;
590
                    RadWindow.Alert(new DialogParameters
591
                    {
592
                        Owner = Application.Current.MainWindow,
593
                        Theme = new VisualStudio2013Theme(),
594
                        Header = "Info",
595
                        Content = "Not specified the page.",
596
                    });
597
                    return;
598
                }
599

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

    
602
                switch (cbPrint.SelectedIndex)
603
                {
604
                    case (0):
605
                        {
606
                            SaveDig.Filter = "PDF file format|*.pdf";
607
                            break;
608
                        }
609
                    case (1):
610
                        {
611
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
612
                            break;
613
                        }
614
                }
615

    
616
                SaveDig.Title = "Save an PDF File";
617
                if(SaveDig.ShowDialog().Value)
618
                {
619
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
620

    
621
                    foreach (int PageNo in _lstPrintPageNo)
622
                    {
623
                        await Dispatcher.InvokeAsync(() =>
624
                        {
625
                            sliderPages.Value = PageNo;
626
                        });
627

    
628
                        await PageChangeAsync(PageNo, true);
629
                        System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo);
630
                    }
631

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

    
634
                    if (SaveDig.FileName != "")
635
                    {
636
                        switch (cbPrint.SelectedIndex)
637
                        {
638
                            case (0):
639
                                {
640
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
641
                                    {
642
                                        using (Document doc = new Document())
643
                                        {
644
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
645
                                            {
646
                                                doc.Open();
647
                                                float height = doc.PageSize.Height;
648
                                                float width = doc.PageSize.Width;
649

    
650
                                                foreach (var item in Printimg_List)
651
                                                {
652
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
653

    
654
                                                    if (Export_img.Width > Export_img.Height)
655
                                                    {
656
                                                        doc.SetPageSize(new Rectangle(height, width));
657
                                                        Export_img.ScaleToFit(height, width);
658
                                                    }
659
                                                    else
660
                                                    {
661
                                                        doc.SetPageSize(new Rectangle(width, height));
662
                                                        Export_img.ScaleToFit(width, height);
663
                                                    }
664

    
665
                                                    Export_img.SetAbsolutePosition(0, 0);
666

    
667
                                                    doc.NewPage();
668
                                                    doc.Add(Export_img);
669
                                                }
670
                                                doc.Close();
671
                                            }
672
                                        }
673
                                    }
674
                                    break;
675
                                }
676
                            case (1):
677
                                {
678
                                    foreach (var item in Printimg_List)
679
                                    {
680
                                        switch (SaveDig.FilterIndex)
681
                                        {
682
                                            case (1):
683
                                                {
684
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
685
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
686
                                                }
687
                                                break;
688
                                            case (2):
689
                                                {
690
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
691
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
692
                                                }
693
                                                break;
694
                                        }
695
                                    }
696
                                    break;
697
                                }
698
                        }
699
                    }
700
                    else
701
                    {
702
                        this.printIndy.IsBusy = false;
703
                        return;
704
                    }
705

    
706
                    await this.Dispatcher.InvokeAsync(() =>
707
                    {
708
                        printIndy.IsBusy = false;
709
                    });
710

    
711
                    await PageChangeAsync(_StartPageNo);
712

    
713
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
714
                }else
715
                {
716
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
717
                    {
718
                        printIndy.IsBusy = false;
719
                    }));
720

    
721
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
722
                }                
723
            }
724
            catch (Exception ex)
725
            {
726
                printIndy.IsBusy = false;
727

    
728
                Logger.sendResLog("Export Method", ex.Message, 0);
729
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
730
            }
731

    
732
        }
733
        #endregion
734

    
735
        #region Method - 처리
736
        void CheckCommentPages()
737
        {
738
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
739
            DoubleCollection _Ticks = new DoubleCollection();
740

    
741

    
742
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
743
            {
744

    
745
                _pages = (from commPage in this._PageMarkupList
746
                          where commPage.PageNumber == CurrentPageNo
747
                          orderby commPage.PageNumber
748
                          select commPage).ToList();
749
            }
750
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
751
            {
752
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
753
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
754

    
755
                int _stPage = (int)stPageNo.Value;
756
                int _edPage = (int)edPageNo.Value;
757

    
758
                _pages = (from commPage in this._PageMarkupList
759
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
760
                          orderby commPage.PageNumber
761
                          select commPage).ToList();
762
            }
763
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
764
            {
765
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
766
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
767

    
768
                int _stPage = (int)stPageNo.Value;
769
                int _edPage = (int)edPageNo.Value;
770

    
771
                //Using DeepView.Common.RangeParser
772
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
773
                _pages = (from commPage in this._PageMarkupList
774
                          from compareData in lst
775
                          where commPage.PageNumber == compareData
776
                          orderby commPage.PageNumber
777
                          select commPage).ToList();
778
            }
779
            else
780
            {
781
                _pages = (from commPage in this._PageMarkupList
782
                          orderby commPage.PageNumber
783
                          select commPage).ToList();
784
            }
785
            CommentPageList.ItemsSource = _pages.ToList();
786
        }
787

    
788
        void SetLoadMakupList(int PageNo)
789
        {
790
            _LoadMakupList.Clear();
791
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
792

    
793
            if (_markupList.Count() > 0)
794
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
795
        }
796

    
797
        #region 프린트 리스트 가져오기
798
        public void GetPrint(bool flag)
799
        {
800
            if (flag)
801
            {
802
                foreach (string printer in PrinterSettings.InstalledPrinters)
803
                {
804
                    this.cbPrint.Items.Add(printer);
805
                }
806
                printDocument = new PrintDocument();
807
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
808
            }
809
            else
810
            {
811
                this.cbPrint.Items.Add("PDF");
812
                this.cbPrint.Items.Add("IMAGE");
813

    
814
                this.cbPrint.SelectedItem = "PDF";
815
            }
816
        }
817
        #endregion
818

    
819
        #region 프린트 실행
820
        public async void Printing()
821
        {
822
            await PageChangeAsync(1);
823

    
824
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
825
            {
826
                printDocument = new PrintDocument();
827
                printDocument.OriginAtMargins = true;
828
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
829
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
830
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
831
            }
832
            else
833
                printDocument = null;
834

    
835
            #region 인쇄 미리보기 테스트
836
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
837
            {
838
                printDocument.PrinterSettings.MinimumPage = 1;
839
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
840
                printDocument.PrinterSettings.FromPage = 1;
841
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
842
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
843
                printDocument.PrinterSettings.PrinterName = PrintName;
844
                dlg.Document = printDocument;
845
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
846
                dlg.ShowDialog();
847
            }
848
            #endregion
849

    
850
            #region 인쇄
851
            //printDocument.PrinterSettings.MinimumPage = 1;
852
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
853
            //printDocument.PrinterSettings.FromPage = 1;
854
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
855

    
856
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
857
            //printDocument.PrinterSettings.PrinterName = PrintName;
858

    
859
            //printDocument.Print();
860
            #endregion
861
        }
862

    
863
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
864
        {
865
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
866
            // This demo only loads one page at a time, so no need to re-set the print page number
867
            PrintDocument document = sender as PrintDocument;
868
            currentPage = document.PrinterSettings.FromPage;
869
        }
870

    
871
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
872
        {
873
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
874

    
875
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
876
            {
877
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
878

    
879
                if (p_img.Width > p_img.Height)
880
                {
881
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
882
                }
883

    
884
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
885
                System.Drawing.Image pic = p_img;
886
                System.Drawing.Rectangle m = e.MarginBounds;
887

    
888
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
889
                //{
890
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
891
                //}
892
                //else
893
                //{
894
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
895
                //}
896
                m.Width = (int)e.PageSettings.PrintableArea.Width;
897
                m.Height = (int)e.PageSettings.PrintableArea.Height;
898
                m.X = (int)e.PageSettings.HardMarginX;
899
                m.Y = (int)e.PageSettings.HardMarginY;
900

    
901
                e.Graphics.DrawImage(pic, m);
902
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
903
                //e.Graphics.DrawImage(p_img, 0, 0);
904
            }));
905

    
906
            //다음 페이지
907
            currentPage++;
908

    
909
            ////인쇄를 계속 할지 말지 확인
910
            if (currentPage <= printDocument.PrinterSettings.ToPage)
911
                e.HasMorePages = true;
912
            else
913
                e.HasMorePages = false;
914

    
915
        }
916

    
917
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
918
        {
919
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
920
            {
921
                printIndy.IsBusy = false;
922
            }));
923
        }
924
        #endregion
925

    
926
        #region Selected Pages Check
927
        List<int> PrintPageCreate()
928
        {
929
            List<int> Result = new List<int>();
930

    
931
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
932
            {
933
                Result.Add(CurrentPageNo);
934
            }
935
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
936
            {
937
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
938
                {
939
                    Result.Add(i);
940
                }
941
            }
942
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
943
            {
944
                int _stPage = (int)stPageNo.Value;
945
                int _edPage = (int)edPageNo.Value;
946

    
947
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
948
                Result.AddRange(lst);
949
            }
950
            else
951
            {
952
                for (int i = 1; i <= _definePages.PagesCount; i++)
953
                {
954
                    Result.Add(i);
955
                }
956
            }
957
            if (currentPagePrint)
958
            {
959
                return Result;
960
            }
961

    
962
            if (chkOnlyMarkup.IsChecked.Value)
963
            {
964
                var _result = from result in Result
965
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
966
                              select result;
967
                Result = _result.ToList();
968
            }
969
            return Result;
970
        }
971
        #endregion
972

    
973
        #endregion
974
    }
975
}
클립보드 이미지 추가 (최대 크기: 500 MB)