프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 481c3fb9

이력 | 보기 | 이력해설 | 다운로드 (36.6 KB)

1 787a4489 KangIngu
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 481c3fb9 djkim
using System.Net;
25 e3a15e22 djkim
26 787a4489 KangIngu
namespace KCOM.Control
27
{
28
    public class DefinedPages
29
    {
30
        public int PagesCount { get; set; }
31
        public string vpSlip { get; set; }
32
        public string vpTitle { get; set; }
33
        public string fileUrl { get; set; }
34
        public ImageBrush Back_Image { get; set; }
35
36
        string _DefinedPagesStrings;
37
        /// <summary>
38
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
39
        /// </summary>
40
        public string DefinedPagesStrings
41
        {
42
            get { return _DefinedPagesStrings; }
43
            set
44
            {
45
                if (string.IsNullOrWhiteSpace(value)) return;
46
47
                var _definedPages = value.Replace('-', ',').Split(',');
48
                List<char> _NotEx = new List<char>();
49
50
                foreach (var item in _definedPages)
51
                {
52
                    bool _isNum = true;
53
54
                    foreach (var chr in item)
55
                    {
56
                        if (!char.IsNumber(chr))
57
                        {
58
                            _NotEx.Add(chr);
59
                            _isNum = false;
60
                        }
61
                    }
62
63
                    if (_isNum)
64
                    {
65
                        if (Convert.ToInt32(item) > PagesCount)
66
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
67
                    }
68
                }
69
70
                if (_NotEx.Count() > 0)
71
                {
72
                    string _notString = "";
73
                    _NotEx.ForEach(s => _notString += s.ToString());
74
                    throw new Exception(string.Format("'{0}' Can not be added.", _notString));
75
                }
76
77
78
                try
79
                {
80
81
                    string _notString2 = "";
82
                    _NotEx.ForEach(s => _notString2 += s.ToString());
83
                    _DefinedPagesStrings = value;
84
                }
85
                catch (Exception)
86
                {
87
                    throw new Exception(string.Format("Can not be added."));
88
                }
89
90
            }
91
        }
92
    }
93
94
    /// <summary>
95
    /// Interaction logic for Print.xaml
96
    /// </summary>
97
    public partial class PrintControl : UserControl
98
    {
99
        #region Data
100
101
        string ProjectNo = null; //프로젝트 넘버
102
        string _DefaultTileUri = null; //기본 타일 경로
103
        int _StartPageNo; //시작페이지 
104
        DOCINFO _DocInfo; //문서 정보
105
        //DocInfo _DocInfo; //문서 정보
106
        bool currentPagePrint = false; //현재 페이지 수
107
        int PageCount { get; set; } //총 페이지수 
108
        DefinedPages _definePages = null; //인쇄 설정 범위 지정
109
        public bool IsPrint { get; set; }
110
111
        PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성
112
113
        //LayerControl LayerControl = null; // 레이어 컨트롤
114
        ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보
115
        List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>();
116
        List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>();
117
        List<int> _lstPrintPageNo = new List<int>();
118
119
        System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer();
120
        bool _initializeComponentFinished; //이벤트
121
        bool _IsDagSlider = false; //드래그 상태인가
122
        List<DisplayColorInfo> colorList = new List<DisplayColorInfo>();
123
        DefinedPages DocumentInfo { get; set; } //문서정보 정의        
124
        //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 
125
        delegate void PrintEventHandler(); //프린트 핸들러
126
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
127
        //SaveFileDialog SaveFile { get; set; } //저장할 때 사용
128
129
        //RasterImageViewer _viewer; //이미지 뷰어
130
        System.Windows.Controls.Image backimg; //백그라운드 이미지
131
        System.Drawing.Image Printimg; //프린트 이미지
132
        System.Drawing.Image p_img; //프린트 이미지
133
        iTextSharp.text.Image Export_img;
134 481c3fb9 djkim
        Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지
135 787a4489 KangIngu
136
        //RasterCodecs codecs;
137
        int currentPage;
138
        public string PrintName;
139
        public string Type;
140
141
        public System.Timers.Timer timm = new System.Timers.Timer();
142
143
144
        #endregion
145
146
        #region Static Property Defines
147
        public static readonly DependencyProperty CurrentPageNoProperty =
148
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
149
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
150
        #endregion
151
152
        #region Property
153
        public int CurrentPageNo
154
        {
155
            get { return (int)GetValue(CurrentPageNoProperty); }
156
            set { SetValue(CurrentPageNoProperty, value); }
157
        }
158
        #endregion
159
160
        #region PropertyChangeMethod
161
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
162
        {
163
            var printPage = (PrintControl)d;
164
            var newValue = (int)e.NewValue;
165
166
            printPage.sliderPages.Value = newValue;
167
            printPage.SetLoadMakupList(newValue);
168
169
        }
170
        #endregion
171
172
        #region 생성자
173 481c3fb9 djkim
174 787a4489 KangIngu
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
175
        {
176
            InitializeComponent();
177 481c3fb9 djkim
178 787a4489 KangIngu
            this.IsEnabled = true;
179
180
            //Layer Control을 통째로 가져와야 하는건가
181
            //this.LayerControl = LayerControl;
182
            this._DocInfo = DocInfo;
183
            this._DefaultTileUri = TileSourceUri;
184
            this.ProjectNo = ProjectNo;
185
            this._StartPageNo = CurrentPageNo;
186
187
            markupInfo.ForEach(info => this._markupInfo.Add(info));
188
189
            foreach (var info in _markupInfo)
190
            {
191
                if (info.Consolidate == 1)
192
                {
193
                    info.UserName = "Consolidation";
194
                }
195
                info.MarkupList.ForEach(makup =>
196
                {
197
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
198
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
199
200
                    if (_pageMarkup.Count() > 0)
201
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
202
                    else
203
                        _PageMarkupList.Add(new MarkupPageItem
204
                        {
205
                            PageNumber = makup.PageNumber,
206
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
207
                        });
208
                });
209
210
                colorList.Add(new DisplayColorInfo
211
                {
212
                    UserID = info.UserID,
213
                    DisplayColor = info.DisplayColor,
214
                    Department = info.Depatment,
215
                    UserName = info.UserName,
216
                });
217
            }
218
219
            gridViewMarkup.ItemsSource = this._markupInfo;
220
            SetLoadMakupList(this._StartPageNo);
221
            if (_LoadMakupList.Count() == 0)
222
                chkOnlyMarkup.IsChecked = false;
223
224
            this.CurrentPageNo = _StartPageNo;
225
            _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
226
            DocumentInfo = _definePages;
227
            this.DataContext = _definePages;
228
229
            CheckCommentPages();
230
231
            //초기화면 Comment Check된 상태로 보여주기
232
            foreach (var item in _markupInfo)
233
            {
234
                gridViewMarkup.SelectedItems.Add(item);
235
            }
236
            PageChanged(_StartPageNo);
237
238
239
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
240
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
241
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
242
            this.IsPrint = isPrint;
243
244
            if (!IsPrint)
245
            {
246
                GetPrint(false);
247
                btnWholeExport.Visibility = Visibility.Visible;
248
                btnWholePrint.Visibility = Visibility.Collapsed;
249
                Selected_Print.Header = "Export Type";
250
            }
251
            else
252
            {
253
                //PrintList 가져오기
254
                GetPrint(true);
255
                btnWholePrint.Visibility = Visibility.Visible;
256
                btnWholeExport.Visibility = Visibility.Collapsed;
257
            }
258
259
            _initializeComponentFinished = true;
260
261
            //timm.Interval = 10;
262
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
263
            //timm.Enabled = true;
264
        }
265
266
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
267
        {
268
            timm.Enabled = false;
269
            PageChanged(_StartPageNo);
270
        }
271
        #endregion
272
273
        #region Control Event
274
        private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
275
        {
276
            if (_initializeComponentFinished)
277
            {
278
                if (!_IsDagSlider)
279
                {
280
                    this.CurrentPageNo = (int)this.sliderPages.Value;
281
                    PageChanged(this.CurrentPageNo);
282 481c3fb9 djkim
283
                    if (_ButtonName == "Current")
284 114015fd ljiyeon
                    {
285
                        stPageNo.Value = CurrentPageNo;
286
                        edPageNo.Value = CurrentPageNo;
287 481c3fb9 djkim
                    }
288 114015fd ljiyeon
289 787a4489 KangIngu
                    //CheckCommentPages();
290
                }
291
            }
292
        }
293
294
        private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
295
        {
296
            _IsDagSlider = false;
297
            this.CurrentPageNo = (int)this.sliderPages.Value;
298
            if (_initializeComponentFinished)
299
            {
300
                PageChanged(this.CurrentPageNo);
301
            }
302
        }
303
304
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
305
        {
306
            _IsDagSlider = true;
307
        }
308
309
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
310
        {
311
            if (_initializeComponentFinished)      //GridRangePages
312
            {
313
                CheckCommentPages();
314
            }
315
        }
316 114015fd ljiyeon
        string _ButtonName;
317 787a4489 KangIngu
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
318
        {
319
            if (!_initializeComponentFinished) return;
320
321 114015fd ljiyeon
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
322 787a4489 KangIngu
            CommentPageList.ItemsSource = null;
323
324
            switch (_ButtonName)
325
            {
326
                case "Current":
327
                    stPageNo.Value = CurrentPageNo;
328
                    edPageNo.Value = CurrentPageNo;
329
330
                    GridCurrentPage.Visibility = Visibility.Visible;
331
                    GridDefinePages.Visibility = Visibility.Collapsed;
332
                    GridRangePages.Visibility = Visibility.Collapsed;
333
                    GridAllPages.Visibility = Visibility.Collapsed;
334
335
                    break;
336
                case "RangePrint":
337
                    GridCurrentPage.Visibility = Visibility.Collapsed;
338
                    GridDefinePages.Visibility = Visibility.Visible;
339
                    GridRangePages.Visibility = Visibility.Collapsed;
340
                    GridAllPages.Visibility = Visibility.Collapsed;
341
                    break;
342
                case "UserDefined":
343
                    GridCurrentPage.Visibility = Visibility.Collapsed;
344
                    GridDefinePages.Visibility = Visibility.Collapsed;
345
                    GridRangePages.Visibility = Visibility.Visible;
346
                    GridAllPages.Visibility = Visibility.Collapsed;
347
                    break;
348
                case "AllPrint":
349
                    stPageNo.Value = 1;
350
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
351
                    GridCurrentPage.Visibility = Visibility.Collapsed;
352
                    GridDefinePages.Visibility = Visibility.Collapsed;
353
                    GridRangePages.Visibility = Visibility.Collapsed;
354
                    GridAllPages.Visibility = Visibility.Visible;
355
                    break;
356
            }
357
358
            CheckCommentPages();
359
        }
360
361
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
362
        {
363
            if (_initializeComponentFinished)      //GridRangePages
364
            {
365
                if (stPageNo.Value > edPageNo.Value)
366
                {
367
                    if (sender.Equals(stPageNo))
368
                        edPageNo.Value = stPageNo.Value;
369
                    else
370
                        stPageNo.Value = edPageNo.Value;
371
                }
372
373
                //뷰어잠시제외(강인구)
374
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
375
                //{
376
                CheckCommentPages();
377
                //});
378
            }
379
        }
380
381
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
382
        {
383
            CheckCommentPages();
384
        }
385
386
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
387
        {
388
            txtDefinedPages.Text = "";
389
        }
390
391
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
392
        {
393
            if (_initializeComponentFinished)
394
                if (CommentPageList.SelectedItem != null)
395
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
396
        }
397
398
        private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
399
        {
400
            if (_initializeComponentFinished)
401
            {
402
                PageChanged(this.CurrentPageNo);
403
            }
404
        }
405
406
        #endregion
407
408
        public void PageChanged(int PageNo, bool Flag = false)
409
        {
410
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
411
            {
412 481c3fb9 djkim
                try
413
                {
414
                    Load load = new Load();
415 787a4489 KangIngu
416 481c3fb9 djkim
                    _definePages.Back_Image = new ImageBrush();
417
                    //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
418
                    var buffer = new WebClient().DownloadData(_DefaultTileUri + PageNo + ".png");
419
                    var bitmap = new BitmapImage();
420
                    using (var stream = new MemoryStream(buffer))
421
                    {
422
                        bitmap.BeginInit();
423
                        bitmap.CacheOption = BitmapCacheOption.OnLoad;
424
                        bitmap.StreamSource = stream;
425
                        bitmap.EndInit();
426 787a4489 KangIngu
427 481c3fb9 djkim
                        printCanvas.Children.Clear();
428 787a4489 KangIngu
429 481c3fb9 djkim
                        ImageBrush background = new ImageBrush(bitmap);
430
                        printCanvas.Background = background;
431 787a4489 KangIngu
432 481c3fb9 djkim
                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
433
                        printCanvas.Width = image.Width;
434
                        printCanvas.Height = image.Height;
435
436
                        foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
437
                        {
438
                            load.User_Id = info.UserID;
439
                            load.document_id = _DocInfo.DOCUMENT_ID;
440
                            load.Page_No = PageNo;
441
                            load.DisplayColor = info.DisplayColor;
442
                            load.Markupinfoid = info.MarkupInfoID;
443
                            load.Markup_Load(printCanvas);
444
                        }
445
446
                        printCanvas.UpdateLayout();
447
448
                        if (Flag)
449
                        {
450 787a4489 KangIngu
451 481c3fb9 djkim
                            //MemoryStream ms = new MemoryStream();
452
                            //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
453
                            //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
454
                            //bbe.Save(ms);
455 787a4489 KangIngu
456 481c3fb9 djkim
                            //System.Drawing.Image.FromFile()
457
                            Printimg = System.Drawing.Image.FromStream(stream);
458
                            Export export = new Export();
459
                            p_img = export.Exporting(printCanvas, Printimg);
460
                            Printimg_List.Add(Printimg_List.Count() + 1, p_img);
461
                        }
462
                    }
463
464
                }
465
                catch (Exception ex)
466 787a4489 KangIngu
                {
467 481c3fb9 djkim
                    Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
468 787a4489 KangIngu
                }
469
            }));
470
        }
471 481c3fb9 djkim
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
472
        {
473
            var ms = new MemoryStream();
474
            var pngEncoder = new PngBitmapEncoder();
475
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
476
            pngEncoder.Save(ms);
477 787a4489 KangIngu
478 481c3fb9 djkim
            return ms;
479
        }
480 787a4489 KangIngu
        //Print 버튼 클릭 이벤트
481
        #region Method - 명령
482
        void PrintMethod(object sender, RoutedEventArgs e)
483
        {
484 481c3fb9 djkim
            try
485
            {
486
                if (this.printIndy.IsBusy == true)
487
                    return;
488 787a4489 KangIngu
489 481c3fb9 djkim
                System.Threading.Tasks.Task.Factory.StartNew(() =>
490
                {
491
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
492
                    {
493
                        this.printIndy.IsBusy = true;
494
                        printIndy.BusyContent = "Printing. . .";
495
                    }));
496
                });
497 787a4489 KangIngu
498 481c3fb9 djkim
499
                _lstPrintPageNo = PrintPageCreate();
500
501
                if (_lstPrintPageNo.Count == 0)
502 787a4489 KangIngu
                {
503 481c3fb9 djkim
                    RadWindow.Alert(new DialogParameters
504
                    {
505
                        Owner = Application.Current.MainWindow,
506
                        Theme = new VisualStudio2013Theme(),
507
                        Header = "안내",
508
                        Content = "페이지가 지정되지 않았습니다."
509
                    });
510
                    this.printIndy.IsBusy = false;
511
                    return;
512
                }
513
                int cnt = 0;
514
                List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
515 787a4489 KangIngu
516 481c3fb9 djkim
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
517 787a4489 KangIngu
518 481c3fb9 djkim
                foreach (int PageNo in _lstPrintPageNo)
519
                {
520
                    cnt++;
521
                    sliderPages.Value = PageNo;
522
                    PageChanged(PageNo, true);
523
                    //PageChanged(cnt, true);
524
                }
525
                PrintName = cbPrint.SelectedItem.ToString();
526 787a4489 KangIngu
527 481c3fb9 djkim
                System.Threading.Tasks.Task.Factory.StartNew(() =>
528 787a4489 KangIngu
                {
529 481c3fb9 djkim
                    if (cnt == _lstPrintPageNo.Count)
530
                    {
531
                        Printing();
532
                    }
533 787a4489 KangIngu
                });
534
            }
535 481c3fb9 djkim
            catch (Exception ex)
536 787a4489 KangIngu
            {
537 481c3fb9 djkim
                Logger.sendResLog("PrintMethod", ex.Message, 0);
538 787a4489 KangIngu
            }
539
540
        }
541
542
        //Export 버튼 클릭 이벤트
543
        void ExportMethod(object sender, RoutedEventArgs e)
544
        {
545 481c3fb9 djkim
            try
546
            {
547
                if (this.printIndy.IsBusy == true)
548
                    return;
549 787a4489 KangIngu
550 481c3fb9 djkim
                this.printIndy.IsBusy = true;
551
                printIndy.BusyContent = "Exporting. . .";
552 787a4489 KangIngu
553 481c3fb9 djkim
                Export export = new Export();
554
                _lstPrintPageNo = PrintPageCreate();
555 787a4489 KangIngu
556 481c3fb9 djkim
                if (_lstPrintPageNo.Count == 0)
557 787a4489 KangIngu
                {
558 481c3fb9 djkim
                    this.printIndy.IsBusy = false;
559
                    RadWindow.Alert(new DialogParameters
560 787a4489 KangIngu
                    {
561 481c3fb9 djkim
                        Owner = Application.Current.MainWindow,
562
                        Theme = new VisualStudio2013Theme(),
563
                        Header = "안내",
564
                        Content = "페이지가 지정되지 않았습니다.",
565
                    });
566
                    return;
567
                }
568 787a4489 KangIngu
569 481c3fb9 djkim
                //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
570 787a4489 KangIngu
571
                switch (cbPrint.SelectedIndex)
572
                {
573
                    case (0):
574
                        {
575 481c3fb9 djkim
                            SaveDig.Filter = "PDF file format|*.pdf";
576
                            break;
577
                        }
578
                    case (1):
579
                        {
580
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
581
                            break;
582
                        }
583
                }
584
585
                SaveDig.Title = "Save an PDF File";
586
                if(SaveDig.ShowDialog().Value)
587
                {
588
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
589
590
                    foreach (int PageNo in _lstPrintPageNo)
591
                    {
592
                        sliderPages.Value = PageNo;
593
                        PageChanged(PageNo, true);
594
                    }
595
596
                    //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
597
598
                    if (SaveDig.FileName != "")
599
                    {
600
                        switch (cbPrint.SelectedIndex)
601
                        {
602
                            case (0):
603 787a4489 KangIngu
                                {
604 481c3fb9 djkim
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
605 787a4489 KangIngu
                                    {
606 481c3fb9 djkim
                                        using (Document doc = new Document())
607 787a4489 KangIngu
                                        {
608 481c3fb9 djkim
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
609 e3a15e22 djkim
                                            {
610 481c3fb9 djkim
                                                doc.Open();
611
                                                float height = doc.PageSize.Height;
612
                                                float width = doc.PageSize.Width;
613
614
                                                foreach (var item in Printimg_List)
615
                                                {
616 787a4489 KangIngu
617 481c3fb9 djkim
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
618
619
620
                                                    if (Export_img.Width > Export_img.Height)
621
                                                    {
622
                                                        doc.SetPageSize(new Rectangle(height, width));
623
                                                        Export_img.ScaleToFit(height, width);
624
                                                    }
625
                                                    else
626
                                                    {
627
                                                        doc.SetPageSize(new Rectangle(width, height));
628
                                                        Export_img.ScaleToFit(width, height);
629
                                                    }
630
631
                                                    Export_img.SetAbsolutePosition(0, 0);
632
633
                                                    doc.NewPage();
634
                                                    doc.Add(Export_img);
635
                                                }
636
                                                doc.Close();
637
                                            }
638 787a4489 KangIngu
                                        }
639
                                    }
640 481c3fb9 djkim
                                    break;
641 787a4489 KangIngu
                                }
642 481c3fb9 djkim
                            case (1):
643 787a4489 KangIngu
                                {
644 481c3fb9 djkim
                                    foreach (var item in Printimg_List)
645
                                    {
646
                                        switch (SaveDig.FilterIndex)
647 787a4489 KangIngu
                                        {
648 481c3fb9 djkim
                                            case (1):
649
                                                {
650
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
651
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
652
                                                }
653
                                                break;
654
                                            case (2):
655
                                                {
656
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
657
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
658
                                                }
659
                                                break;
660 787a4489 KangIngu
                                        }
661 481c3fb9 djkim
                                    }
662
                                    break;
663 787a4489 KangIngu
                                }
664
                        }
665 481c3fb9 djkim
                    }
666
                    else
667
                    {
668
                        this.printIndy.IsBusy = false;
669
                        return;
670
                    }
671
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
672
                    {
673
                        printIndy.IsBusy = false;
674
                    }));
675
                    PageChanged(_StartPageNo);
676 787a4489 KangIngu
677 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
678
                }else
679
                {
680
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
681
                    {
682
                        printIndy.IsBusy = false;
683
                    }));
684 787a4489 KangIngu
685 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
686
                }                
687
            }
688
            catch (Exception ex)
689 787a4489 KangIngu
            {
690 481c3fb9 djkim
                Logger.sendResLog("Export Method", ex.Message, 0);
691
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
692
            }
693 787a4489 KangIngu
694
        }
695
        #endregion
696
697
        #region Method - 처리
698
        void CheckCommentPages()
699
        {
700
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
701
            DoubleCollection _Ticks = new DoubleCollection();
702
703
704
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
705
            {
706
707
                _pages = (from commPage in this._PageMarkupList
708
                          where commPage.PageNumber == CurrentPageNo
709
                          orderby commPage.PageNumber
710
                          select commPage).ToList();
711
            }
712
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
713
            {
714
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
715
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
716
717
                int _stPage = (int)stPageNo.Value;
718
                int _edPage = (int)edPageNo.Value;
719
720
                _pages = (from commPage in this._PageMarkupList
721
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
722
                          orderby commPage.PageNumber
723
                          select commPage).ToList();
724
            }
725
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
726
            {
727
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
728
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
729
730
                int _stPage = (int)stPageNo.Value;
731
                int _edPage = (int)edPageNo.Value;
732
733
                //Using DeepView.Common.RangeParser
734
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
735
                _pages = (from commPage in this._PageMarkupList
736
                          from compareData in lst
737
                          where commPage.PageNumber == compareData
738
                          orderby commPage.PageNumber
739
                          select commPage).ToList();
740
            }
741
            else
742
            {
743
                _pages = (from commPage in this._PageMarkupList
744
                          orderby commPage.PageNumber
745
                          select commPage).ToList();
746
            }
747
            CommentPageList.ItemsSource = _pages.ToList();
748
        }
749
750
        void SetLoadMakupList(int PageNo)
751
        {
752
            _LoadMakupList.Clear();
753
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
754
755
            if (_markupList.Count() > 0)
756
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
757
        }
758
759
        #region 프린트 리스트 가져오기
760
        public void GetPrint(bool flag)
761
        {
762
            if (flag)
763
            {
764
                foreach (string printer in PrinterSettings.InstalledPrinters)
765
                {
766
                    this.cbPrint.Items.Add(printer);
767
                }
768
                printDocument = new PrintDocument();
769
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
770
            }
771
            else
772
            {
773
                this.cbPrint.Items.Add("PDF");
774
                this.cbPrint.Items.Add("IMAGE");
775
776
                this.cbPrint.SelectedItem = "PDF";
777
            }
778
        }
779
        #endregion
780
781
        #region 프린트 실행
782
        public void Printing()
783
        {
784
            PageChanged(1);
785
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
786
            {
787 481c3fb9 djkim
                printDocument = new PrintDocument();
788 408e4218 ljiyeon
                printDocument.OriginAtMargins = true;
789 787a4489 KangIngu
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
790
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
791
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
792
            }
793
            else
794
                printDocument = null;
795
796
            #region 인쇄 미리보기 테스트
797
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
798
            {
799
                printDocument.PrinterSettings.MinimumPage = 1;
800
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
801
                printDocument.PrinterSettings.FromPage = 1;
802 408e4218 ljiyeon
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
803 787a4489 KangIngu
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
804 481c3fb9 djkim
                printDocument.PrinterSettings.PrinterName = PrintName;
805
                dlg.Document = printDocument;
806 787a4489 KangIngu
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
807
                dlg.ShowDialog();
808
            }
809
            #endregion
810
811
            #region 인쇄
812
            //printDocument.PrinterSettings.MinimumPage = 1;
813
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
814
            //printDocument.PrinterSettings.FromPage = 1;
815
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
816
817
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
818
            //printDocument.PrinterSettings.PrinterName = PrintName;
819
820
            //printDocument.Print();
821
            #endregion
822
        }
823
824
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
825
        {
826
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
827
            // This demo only loads one page at a time, so no need to re-set the print page number
828 481c3fb9 djkim
            PrintDocument document = sender as PrintDocument;
829 787a4489 KangIngu
            currentPage = document.PrinterSettings.FromPage;
830
        }
831 481c3fb9 djkim
832 787a4489 KangIngu
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
833
        {
834
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
835
836
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
837
            {
838
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
839 2024d8d1 ljiyeon
840 481c3fb9 djkim
                if (p_img.Width > p_img.Height)
841 2024d8d1 ljiyeon
                {
842
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
843
                }
844 408e4218 ljiyeon
845
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
846
                System.Drawing.Image pic = p_img;
847 787a4489 KangIngu
                System.Drawing.Rectangle m = e.MarginBounds;
848
849 408e4218 ljiyeon
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
850
                //{
851
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
852
                //}
853
                //else
854
                //{
855
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
856
                //}
857
                m.Width = (int)e.PageSettings.PrintableArea.Width;
858
                m.Height = (int)e.PageSettings.PrintableArea.Height;
859
                m.X = (int)e.PageSettings.HardMarginX;
860
                m.Y = (int)e.PageSettings.HardMarginY;
861
862
                e.Graphics.DrawImage(pic, m);
863 787a4489 KangIngu
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
864
                //e.Graphics.DrawImage(p_img, 0, 0);
865
            }));
866 481c3fb9 djkim
867 787a4489 KangIngu
            //다음 페이지
868
            currentPage++;
869 481c3fb9 djkim
870 787a4489 KangIngu
            ////인쇄를 계속 할지 말지 확인
871
            if (currentPage <= printDocument.PrinterSettings.ToPage)
872
                e.HasMorePages = true;
873
            else
874
                e.HasMorePages = false;
875
876
        }
877
878
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
879
        {
880
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
881
            {
882
                printIndy.IsBusy = false;
883
            }));
884
        }
885
        #endregion
886
887
        #region Selected Pages Check
888
        List<int> PrintPageCreate()
889
        {
890
            List<int> Result = new List<int>();
891
892
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
893
            {
894
                Result.Add(CurrentPageNo);
895
            }
896
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
897
            {
898
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
899
                {
900
                    Result.Add(i);
901
                }
902
            }
903
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
904
            {
905
                int _stPage = (int)stPageNo.Value;
906
                int _edPage = (int)edPageNo.Value;
907
908
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
909
                Result.AddRange(lst);
910
            }
911
            else
912
            {
913
                for (int i = 1; i <= _definePages.PagesCount; i++)
914
                {
915
                    Result.Add(i);
916
                }
917
            }
918
            if (currentPagePrint)
919
            {
920
                return Result;
921
            }
922
923
            if (chkOnlyMarkup.IsChecked.Value)
924
            {
925
                var _result = from result in Result
926
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
927
                              select result;
928
                Result = _result.ToList();
929
            }
930
            return Result;
931
        }
932
        #endregion
933
934
        #endregion
935
    }
936
}
클립보드 이미지 추가 (최대 크기: 500 MB)