프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (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
                    await PageChangeAsync(this.CurrentPageNo);
289
                    //await App.PageStorage.GetPageUriAsync(this.CurrentPageNo);
290
                
291
                    if (_ButtonName == "Current")
292
                    {
293
                        stPageNo.Value = CurrentPageNo;
294
                        edPageNo.Value = CurrentPageNo;
295
                    }
296

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

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

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

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

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

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

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

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

    
366
            CheckCommentPages();
367
        }
368

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

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

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

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

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

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

    
414
        #endregion
415

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

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

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

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

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

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

    
445
                        
446
                        var uri = await  App.PageStorage.GetPageUriAsync(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.Clear();
453
                        printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
454
                        printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
455
                        printCanvas.Background = new ImageBrush { ImageSource = new BitmapImage(uri) };
456

    
457
                        //ImageBrush background = new ImageBrush(bitmap);
458
                        //printCanvas.Background = background;
459
                        //printCanvas.Background = new SolidColorBrush(Colors.Transparent);
460

    
461

    
462
                        foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
463
                        {
464
                            load.User_Id = info.UserID;
465
                            load.document_id = _DocInfo.DOCUMENT_ID;
466
                            load.Page_No = PageNo;
467
                            load.DisplayColor = info.DisplayColor;
468
                            load.Markupinfoid = info.MarkupInfoID;
469
                            await load.Markup_LoadAsync(printCanvas);
470
                        }
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
                            });
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
                await this.Dispatcher.InvokeAsync(() => { 
527
                        this.printIndy.IsBusy = true;
528
                        printIndy.BusyContent = "Printing. . .";
529
                });
530

    
531

    
532
                _lstPrintPageNo = PrintPageCreate();
533

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

    
547
                int cnt = 0;
548

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

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

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

    
572
        }
573

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

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

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

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

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

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

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

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

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

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

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

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

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

    
666
                                                    Export_img.SetAbsolutePosition(0, 0);
667

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

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

    
712
                    await PageChangeAsync(_StartPageNo);
713

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

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

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

    
733
        }
734
        #endregion
735

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

    
742

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
916
        }
917

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

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

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

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

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

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