프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 86bff326

이력 | 보기 | 이력해설 | 다운로드 (37.2 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 PageChangeAsync(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
            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
                        printCanvas.Children.Clear();
445
                        var bitmapframe = await  App.PageStorage.GetPageAsync(PageNo);
446
                        Image bitmap = new Image();
447

    
448
                        bitmap.Source = bitmapframe;
449
                        printCanvas.Children.Add(bitmap);
450
                         
451
                        //ImageBrush background = new ImageBrush(bitmap);
452
                        //printCanvas.Background = background;
453
                        printCanvas.Background = new SolidColorBrush(Colors.Transparent);
454

    
455
                        printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
456
                        printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
457

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

    
468
                        printCanvas.UpdateLayout();
469

    
470
                        if (Flag)
471
                        {
472
                            //MemoryStream ms = new MemoryStream();
473
                            //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
474
                            //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
475
                            //bbe.Save(ms);
476

    
477
                            //System.Drawing.Image.FromFile()
478
                            //Printimg = System.Drawing.Image.FromStream(stream);
479
                            Export export = new Export();
480
                            p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height);
481
                            Printimg_List.Add(Printimg_List.Count() + 1, p_img);
482
                        }
483

    
484
                        result = true;
485
                    //}
486
                } 
487
            }
488
            catch (Exception ex)
489
            {
490
                Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
491
            }
492

    
493
            return result;
494
            //}));
495
        }
496
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
497
        {
498
            var ms = new MemoryStream();
499
            var pngEncoder = new PngBitmapEncoder();
500
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
501
            pngEncoder.Save(ms);
502

    
503
            return ms;
504
        }
505
        //Print 버튼 클릭 이벤트
506
        #region Method - 명령
507
        async void PrintMethod(object sender, RoutedEventArgs e)
508
        {
509
            try
510
            {
511
                if (this.printIndy.IsBusy == true)
512
                    return;
513

    
514
                await this.Dispatcher.InvokeAsync(() => { 
515
                        this.printIndy.IsBusy = true;
516
                        printIndy.BusyContent = "Printing. . .";
517
                });
518

    
519

    
520
                _lstPrintPageNo = PrintPageCreate();
521

    
522
                if (_lstPrintPageNo.Count == 0)
523
                {
524
                    RadWindow.Alert(new DialogParameters
525
                    {
526
                        Owner = Application.Current.MainWindow,
527
                        Theme = new VisualStudio2013Theme(),
528
                        Header = "Info",
529
                        Content = "Not specified the page."
530
                    });
531
                    this.printIndy.IsBusy = false;
532
                    return;
533
                }
534

    
535
                int cnt = 0;
536

    
537
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
538

    
539
                foreach (int PageNo in _lstPrintPageNo)
540
                {
541
                    cnt++;
542
                    sliderPages.Value = PageNo;
543
                    await PageChangeAsync(PageNo, true);
544
                    //PageChanged(cnt, true);
545
                }
546
                PrintName = cbPrint.SelectedItem.ToString();
547

    
548
                await this.Dispatcher.InvokeAsync(() => {
549
                    if (cnt == _lstPrintPageNo.Count)
550
                    {
551
                        Printing();
552
                    }
553
                });
554
            }
555
            catch (Exception ex)
556
            {
557
                Logger.sendResLog("PrintMethod", ex.Message, 0);
558
            }
559

    
560
        }
561

    
562
        //Export 버튼 클릭 이벤트
563
        async void ExportMethod(object sender, RoutedEventArgs e)
564
        {
565
            try
566
            {
567
                if (this.printIndy.IsBusy == true)
568
                    return;
569

    
570
                this.printIndy.IsBusy = true;
571
                printIndy.BusyContent = "Exporting. . .";
572

    
573
                Export export = new Export();
574
                _lstPrintPageNo = PrintPageCreate();
575

    
576
                if (_lstPrintPageNo.Count == 0)
577
                {
578
                    this.printIndy.IsBusy = false;
579
                    RadWindow.Alert(new DialogParameters
580
                    {
581
                        Owner = Application.Current.MainWindow,
582
                        Theme = new VisualStudio2013Theme(),
583
                        Header = "Info",
584
                        Content = "Not specified the page.",
585
                    });
586
                    return;
587
                }
588

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

    
591
                switch (cbPrint.SelectedIndex)
592
                {
593
                    case (0):
594
                        {
595
                            SaveDig.Filter = "PDF file format|*.pdf";
596
                            break;
597
                        }
598
                    case (1):
599
                        {
600
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
601
                            break;
602
                        }
603
                }
604

    
605
                SaveDig.Title = "Save an PDF File";
606
                if(SaveDig.ShowDialog().Value)
607
                {
608
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
609

    
610
                    foreach (int PageNo in _lstPrintPageNo)
611
                    {
612
                        sliderPages.Value = PageNo;
613
                        await PageChangeAsync(PageNo, true);
614
                    }
615

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

    
618
                    if (SaveDig.FileName != "")
619
                    {
620
                        switch (cbPrint.SelectedIndex)
621
                        {
622
                            case (0):
623
                                {
624
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
625
                                    {
626
                                        using (Document doc = new Document())
627
                                        {
628
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
629
                                            {
630
                                                doc.Open();
631
                                                float height = doc.PageSize.Height;
632
                                                float width = doc.PageSize.Width;
633

    
634
                                                foreach (var item in Printimg_List)
635
                                                {
636

    
637
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
638

    
639

    
640
                                                    if (Export_img.Width > Export_img.Height)
641
                                                    {
642
                                                        doc.SetPageSize(new Rectangle(height, width));
643
                                                        Export_img.ScaleToFit(height, width);
644
                                                    }
645
                                                    else
646
                                                    {
647
                                                        doc.SetPageSize(new Rectangle(width, height));
648
                                                        Export_img.ScaleToFit(width, height);
649
                                                    }
650

    
651
                                                    Export_img.SetAbsolutePosition(0, 0);
652

    
653
                                                    doc.NewPage();
654
                                                    doc.Add(Export_img);
655
                                                }
656
                                                doc.Close();
657
                                            }
658
                                        }
659
                                    }
660
                                    break;
661
                                }
662
                            case (1):
663
                                {
664
                                    foreach (var item in Printimg_List)
665
                                    {
666
                                        switch (SaveDig.FilterIndex)
667
                                        {
668
                                            case (1):
669
                                                {
670
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
671
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
672
                                                }
673
                                                break;
674
                                            case (2):
675
                                                {
676
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
677
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
678
                                                }
679
                                                break;
680
                                        }
681
                                    }
682
                                    break;
683
                                }
684
                        }
685
                    }
686
                    else
687
                    {
688
                        this.printIndy.IsBusy = false;
689
                        return;
690
                    }
691

    
692
                    await this.Dispatcher.InvokeAsync(() =>
693
                    {
694
                        printIndy.IsBusy = false;
695
                    });
696

    
697
                    await PageChangeAsync(_StartPageNo);
698

    
699
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
700
                }else
701
                {
702
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
703
                    {
704
                        printIndy.IsBusy = false;
705
                    }));
706

    
707
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
708
                }                
709
            }
710
            catch (Exception ex)
711
            {
712
                printIndy.IsBusy = false;
713

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

    
718
        }
719
        #endregion
720

    
721
        #region Method - 처리
722
        void CheckCommentPages()
723
        {
724
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
725
            DoubleCollection _Ticks = new DoubleCollection();
726

    
727

    
728
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
729
            {
730

    
731
                _pages = (from commPage in this._PageMarkupList
732
                          where commPage.PageNumber == CurrentPageNo
733
                          orderby commPage.PageNumber
734
                          select commPage).ToList();
735
            }
736
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
737
            {
738
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
739
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
740

    
741
                int _stPage = (int)stPageNo.Value;
742
                int _edPage = (int)edPageNo.Value;
743

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

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

    
757
                //Using DeepView.Common.RangeParser
758
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
759
                _pages = (from commPage in this._PageMarkupList
760
                          from compareData in lst
761
                          where commPage.PageNumber == compareData
762
                          orderby commPage.PageNumber
763
                          select commPage).ToList();
764
            }
765
            else
766
            {
767
                _pages = (from commPage in this._PageMarkupList
768
                          orderby commPage.PageNumber
769
                          select commPage).ToList();
770
            }
771
            CommentPageList.ItemsSource = _pages.ToList();
772
        }
773

    
774
        void SetLoadMakupList(int PageNo)
775
        {
776
            _LoadMakupList.Clear();
777
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
778

    
779
            if (_markupList.Count() > 0)
780
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
781
        }
782

    
783
        #region 프린트 리스트 가져오기
784
        public void GetPrint(bool flag)
785
        {
786
            if (flag)
787
            {
788
                foreach (string printer in PrinterSettings.InstalledPrinters)
789
                {
790
                    this.cbPrint.Items.Add(printer);
791
                }
792
                printDocument = new PrintDocument();
793
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
794
            }
795
            else
796
            {
797
                this.cbPrint.Items.Add("PDF");
798
                this.cbPrint.Items.Add("IMAGE");
799

    
800
                this.cbPrint.SelectedItem = "PDF";
801
            }
802
        }
803
        #endregion
804

    
805
        #region 프린트 실행
806
        public async void Printing()
807
        {
808
            await PageChangeAsync(1);
809

    
810
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
811
            {
812
                printDocument = new PrintDocument();
813
                printDocument.OriginAtMargins = true;
814
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
815
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
816
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
817
            }
818
            else
819
                printDocument = null;
820

    
821
            #region 인쇄 미리보기 테스트
822
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
823
            {
824
                printDocument.PrinterSettings.MinimumPage = 1;
825
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
826
                printDocument.PrinterSettings.FromPage = 1;
827
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
828
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
829
                printDocument.PrinterSettings.PrinterName = PrintName;
830
                dlg.Document = printDocument;
831
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
832
                dlg.ShowDialog();
833
            }
834
            #endregion
835

    
836
            #region 인쇄
837
            //printDocument.PrinterSettings.MinimumPage = 1;
838
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
839
            //printDocument.PrinterSettings.FromPage = 1;
840
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
841

    
842
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
843
            //printDocument.PrinterSettings.PrinterName = PrintName;
844

    
845
            //printDocument.Print();
846
            #endregion
847
        }
848

    
849
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
850
        {
851
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
852
            // This demo only loads one page at a time, so no need to re-set the print page number
853
            PrintDocument document = sender as PrintDocument;
854
            currentPage = document.PrinterSettings.FromPage;
855
        }
856

    
857
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
858
        {
859
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
860

    
861
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
862
            {
863
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
864

    
865
                if (p_img.Width > p_img.Height)
866
                {
867
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
868
                }
869

    
870
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
871
                System.Drawing.Image pic = p_img;
872
                System.Drawing.Rectangle m = e.MarginBounds;
873

    
874
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
875
                //{
876
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
877
                //}
878
                //else
879
                //{
880
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
881
                //}
882
                m.Width = (int)e.PageSettings.PrintableArea.Width;
883
                m.Height = (int)e.PageSettings.PrintableArea.Height;
884
                m.X = (int)e.PageSettings.HardMarginX;
885
                m.Y = (int)e.PageSettings.HardMarginY;
886

    
887
                e.Graphics.DrawImage(pic, m);
888
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
889
                //e.Graphics.DrawImage(p_img, 0, 0);
890
            }));
891

    
892
            //다음 페이지
893
            currentPage++;
894

    
895
            ////인쇄를 계속 할지 말지 확인
896
            if (currentPage <= printDocument.PrinterSettings.ToPage)
897
                e.HasMorePages = true;
898
            else
899
                e.HasMorePages = false;
900

    
901
        }
902

    
903
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
904
        {
905
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
906
            {
907
                printIndy.IsBusy = false;
908
            }));
909
        }
910
        #endregion
911

    
912
        #region Selected Pages Check
913
        List<int> PrintPageCreate()
914
        {
915
            List<int> Result = new List<int>();
916

    
917
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
918
            {
919
                Result.Add(CurrentPageNo);
920
            }
921
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
922
            {
923
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
924
                {
925
                    Result.Add(i);
926
                }
927
            }
928
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
929
            {
930
                int _stPage = (int)stPageNo.Value;
931
                int _edPage = (int)edPageNo.Value;
932

    
933
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
934
                Result.AddRange(lst);
935
            }
936
            else
937
            {
938
                for (int i = 1; i <= _definePages.PagesCount; i++)
939
                {
940
                    Result.Add(i);
941
                }
942
            }
943
            if (currentPagePrint)
944
            {
945
                return Result;
946
            }
947

    
948
            if (chkOnlyMarkup.IsChecked.Value)
949
            {
950
                var _result = from result in Result
951
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
952
                              select result;
953
                Result = _result.ToList();
954
            }
955
            return Result;
956
        }
957
        #endregion
958

    
959
        #endregion
960
    }
961
}
클립보드 이미지 추가 (최대 크기: 500 MB)