프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (37.7 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 86bff326 taeseongkim
using Image = System.Windows.Controls.Image;
26 e3a15e22 djkim
27 787a4489 KangIngu
namespace KCOM.Control
28
{
29
    public class DefinedPages
30
    {
31 86bff326 taeseongkim
        public DOCINFO DocumentInfo { get; set; }
32
33 787a4489 KangIngu
        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 86bff326 taeseongkim
        public double CurrentValue { get; set; }
40
41 787a4489 KangIngu
        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 53880c83 ljiyeon
        //System.Windows.Controls.Image backimg; //백그라운드 이미지
136 787a4489 KangIngu
        System.Drawing.Image Printimg; //프린트 이미지
137
        System.Drawing.Image p_img; //프린트 이미지
138
        iTextSharp.text.Image Export_img;
139 481c3fb9 djkim
        Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지
140 787a4489 KangIngu
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 481c3fb9 djkim
179 787a4489 KangIngu
        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 481c3fb9 djkim
183 787a4489 KangIngu
            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 86bff326 taeseongkim
230
            _definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo
231
                            , PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
232
233 787a4489 KangIngu
            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 86bff326 taeseongkim
            PageChangeAsync(_StartPageNo).ConfigureAwait(true);
245 787a4489 KangIngu
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 86bff326 taeseongkim
            PageChangeAsync(_StartPageNo);
277 787a4489 KangIngu
        }
278
        #endregion
279
280
        #region Control Event
281 86bff326 taeseongkim
        private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
282 787a4489 KangIngu
        {
283
            if (_initializeComponentFinished)
284
            {
285
                if (!_IsDagSlider)
286
                {
287
                    this.CurrentPageNo = (int)this.sliderPages.Value;
288 86bff326 taeseongkim
289
                    await PageChangeAsync(this.CurrentPageNo);
290 481c3fb9 djkim
291
                    if (_ButtonName == "Current")
292 114015fd ljiyeon
                    {
293
                        stPageNo.Value = CurrentPageNo;
294
                        edPageNo.Value = CurrentPageNo;
295 481c3fb9 djkim
                    }
296 114015fd ljiyeon
297 787a4489 KangIngu
                    //CheckCommentPages();
298
                }
299
            }
300
        }
301
302 86bff326 taeseongkim
        private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
303 787a4489 KangIngu
        {
304
            _IsDagSlider = false;
305
            this.CurrentPageNo = (int)this.sliderPages.Value;
306
            if (_initializeComponentFinished)
307
            {
308 86bff326 taeseongkim
                await PageChangeAsync(this.CurrentPageNo);
309 787a4489 KangIngu
            }
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 114015fd ljiyeon
        string _ButtonName;
325 787a4489 KangIngu
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
326
        {
327
            if (!_initializeComponentFinished) return;
328
329 114015fd ljiyeon
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
330 787a4489 KangIngu
            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 86bff326 taeseongkim
        private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
407 787a4489 KangIngu
        {
408
            if (_initializeComponentFinished)
409
            {
410 86bff326 taeseongkim
                await PageChangeAsync(this.CurrentPageNo);
411 787a4489 KangIngu
            }
412
        }
413
414
        #endregion
415
416 86bff326 taeseongkim
        public async System.Threading.Tasks.Task<bool> PageChangeAsync(int PageNo, bool Flag = false)
417 787a4489 KangIngu
        {
418 86bff326 taeseongkim
            bool result = false;
419
            //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
420
            //{
421
            try
422 787a4489 KangIngu
            {
423 86bff326 taeseongkim
                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 481c3fb9 djkim
                {
432 86bff326 taeseongkim
                    var currentPage = pages.First();
433 787a4489 KangIngu
434 86bff326 taeseongkim
                    //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 787a4489 KangIngu
444 481c3fb9 djkim
                        printCanvas.Children.Clear();
445 86bff326 taeseongkim
                        var bitmapframe = await  App.PageStorage.GetPageAsync(PageNo);
446
                        Image bitmap = new Image();
447 787a4489 KangIngu
448 86bff326 taeseongkim
                        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 787a4489 KangIngu
455 86bff326 taeseongkim
                        printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
456
                        printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
457 481c3fb9 djkim
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 86bff326 taeseongkim
                            await load.Markup_LoadAsync(printCanvas);
466 481c3fb9 djkim
                        }
467
468 d04e8ee9 taeseongkim
                    await Dispatcher.InvokeAsync(() => {
469 481c3fb9 djkim
                        printCanvas.UpdateLayout();
470 d04e8ee9 taeseongkim
                    });
471 481c3fb9 djkim
472 d04e8ee9 taeseongkim
                    if (Flag)
473 481c3fb9 djkim
                        {
474 d04e8ee9 taeseongkim
                        //MemoryStream ms = new MemoryStream();
475
                        //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
476
                        //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
477
                        //bbe.Save(ms);
478
479
                        //System.Drawing.Image.FromFile()
480
                        //Printimg = System.Drawing.Image.FromStream(stream);
481
                        await System.Threading.Tasks.Task.Run(() =>
482
                        {
483
                            Dispatcher.InvokeAsync(() =>
484
                            {
485
                          
486
                                Export export = new Export();
487
                                p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height);
488
                                Printimg_List.Add(Printimg_List.Count() + 1, p_img);
489
                            });
490
                        });
491
                    }
492 481c3fb9 djkim
493 86bff326 taeseongkim
                        result = true;
494
                    //}
495
                } 
496
            }
497
            catch (Exception ex)
498
            {
499
                Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
500
            }
501
502
            return result;
503
            //}));
504 787a4489 KangIngu
        }
505 481c3fb9 djkim
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
506
        {
507
            var ms = new MemoryStream();
508
            var pngEncoder = new PngBitmapEncoder();
509
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
510
            pngEncoder.Save(ms);
511 787a4489 KangIngu
512 481c3fb9 djkim
            return ms;
513
        }
514 787a4489 KangIngu
        //Print 버튼 클릭 이벤트
515
        #region Method - 명령
516 86bff326 taeseongkim
        async void PrintMethod(object sender, RoutedEventArgs e)
517 787a4489 KangIngu
        {
518 481c3fb9 djkim
            try
519
            {
520
                if (this.printIndy.IsBusy == true)
521
                    return;
522 787a4489 KangIngu
523 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => { 
524 481c3fb9 djkim
                        this.printIndy.IsBusy = true;
525
                        printIndy.BusyContent = "Printing. . .";
526
                });
527 787a4489 KangIngu
528 481c3fb9 djkim
529
                _lstPrintPageNo = PrintPageCreate();
530
531
                if (_lstPrintPageNo.Count == 0)
532 787a4489 KangIngu
                {
533 481c3fb9 djkim
                    RadWindow.Alert(new DialogParameters
534
                    {
535
                        Owner = Application.Current.MainWindow,
536
                        Theme = new VisualStudio2013Theme(),
537 eeb0a39c taeseongkim
                        Header = "Info",
538
                        Content = "Not specified the page."
539 481c3fb9 djkim
                    });
540
                    this.printIndy.IsBusy = false;
541
                    return;
542
                }
543 86bff326 taeseongkim
544 481c3fb9 djkim
                int cnt = 0;
545 787a4489 KangIngu
546 481c3fb9 djkim
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
547 787a4489 KangIngu
548 481c3fb9 djkim
                foreach (int PageNo in _lstPrintPageNo)
549
                {
550
                    cnt++;
551
                    sliderPages.Value = PageNo;
552 86bff326 taeseongkim
                    await PageChangeAsync(PageNo, true);
553 481c3fb9 djkim
                    //PageChanged(cnt, true);
554
                }
555
                PrintName = cbPrint.SelectedItem.ToString();
556 787a4489 KangIngu
557 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => {
558 481c3fb9 djkim
                    if (cnt == _lstPrintPageNo.Count)
559
                    {
560
                        Printing();
561
                    }
562 787a4489 KangIngu
                });
563
            }
564 481c3fb9 djkim
            catch (Exception ex)
565 787a4489 KangIngu
            {
566 481c3fb9 djkim
                Logger.sendResLog("PrintMethod", ex.Message, 0);
567 787a4489 KangIngu
            }
568
569
        }
570
571
        //Export 버튼 클릭 이벤트
572 86bff326 taeseongkim
        async void ExportMethod(object sender, RoutedEventArgs e)
573 787a4489 KangIngu
        {
574 481c3fb9 djkim
            try
575
            {
576
                if (this.printIndy.IsBusy == true)
577
                    return;
578 787a4489 KangIngu
579 481c3fb9 djkim
                this.printIndy.IsBusy = true;
580
                printIndy.BusyContent = "Exporting. . .";
581 787a4489 KangIngu
582 481c3fb9 djkim
                Export export = new Export();
583
                _lstPrintPageNo = PrintPageCreate();
584 787a4489 KangIngu
585 481c3fb9 djkim
                if (_lstPrintPageNo.Count == 0)
586 787a4489 KangIngu
                {
587 481c3fb9 djkim
                    this.printIndy.IsBusy = false;
588
                    RadWindow.Alert(new DialogParameters
589 787a4489 KangIngu
                    {
590 481c3fb9 djkim
                        Owner = Application.Current.MainWindow,
591
                        Theme = new VisualStudio2013Theme(),
592 eeb0a39c taeseongkim
                        Header = "Info",
593
                        Content = "Not specified the page.",
594 481c3fb9 djkim
                    });
595
                    return;
596
                }
597 787a4489 KangIngu
598 481c3fb9 djkim
                //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
599 787a4489 KangIngu
600
                switch (cbPrint.SelectedIndex)
601
                {
602
                    case (0):
603
                        {
604 481c3fb9 djkim
                            SaveDig.Filter = "PDF file format|*.pdf";
605
                            break;
606
                        }
607
                    case (1):
608
                        {
609
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
610
                            break;
611
                        }
612
                }
613
614
                SaveDig.Title = "Save an PDF File";
615
                if(SaveDig.ShowDialog().Value)
616
                {
617
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
618
619
                    foreach (int PageNo in _lstPrintPageNo)
620
                    {
621 d04e8ee9 taeseongkim
                        await Dispatcher.InvokeAsync(() =>
622
                        {
623
                            sliderPages.Value = PageNo;
624
                        });
625 86bff326 taeseongkim
                        await PageChangeAsync(PageNo, true);
626 d04e8ee9 taeseongkim
                      
627 481c3fb9 djkim
                    }
628
629
                    //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
630
631
                    if (SaveDig.FileName != "")
632
                    {
633
                        switch (cbPrint.SelectedIndex)
634
                        {
635
                            case (0):
636 787a4489 KangIngu
                                {
637 481c3fb9 djkim
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
638 787a4489 KangIngu
                                    {
639 481c3fb9 djkim
                                        using (Document doc = new Document())
640 787a4489 KangIngu
                                        {
641 481c3fb9 djkim
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
642 e3a15e22 djkim
                                            {
643 481c3fb9 djkim
                                                doc.Open();
644
                                                float height = doc.PageSize.Height;
645
                                                float width = doc.PageSize.Width;
646
647
                                                foreach (var item in Printimg_List)
648
                                                {
649
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
650
651
                                                    if (Export_img.Width > Export_img.Height)
652
                                                    {
653
                                                        doc.SetPageSize(new Rectangle(height, width));
654
                                                        Export_img.ScaleToFit(height, width);
655
                                                    }
656
                                                    else
657
                                                    {
658
                                                        doc.SetPageSize(new Rectangle(width, height));
659
                                                        Export_img.ScaleToFit(width, height);
660
                                                    }
661
662
                                                    Export_img.SetAbsolutePosition(0, 0);
663
664
                                                    doc.NewPage();
665
                                                    doc.Add(Export_img);
666
                                                }
667
                                                doc.Close();
668
                                            }
669 787a4489 KangIngu
                                        }
670
                                    }
671 481c3fb9 djkim
                                    break;
672 787a4489 KangIngu
                                }
673 481c3fb9 djkim
                            case (1):
674 787a4489 KangIngu
                                {
675 481c3fb9 djkim
                                    foreach (var item in Printimg_List)
676
                                    {
677
                                        switch (SaveDig.FilterIndex)
678 787a4489 KangIngu
                                        {
679 481c3fb9 djkim
                                            case (1):
680
                                                {
681
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
682
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
683
                                                }
684
                                                break;
685
                                            case (2):
686
                                                {
687
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
688
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
689
                                                }
690
                                                break;
691 787a4489 KangIngu
                                        }
692 481c3fb9 djkim
                                    }
693
                                    break;
694 787a4489 KangIngu
                                }
695
                        }
696 481c3fb9 djkim
                    }
697
                    else
698
                    {
699
                        this.printIndy.IsBusy = false;
700
                        return;
701
                    }
702 86bff326 taeseongkim
703
                    await this.Dispatcher.InvokeAsync(() =>
704 481c3fb9 djkim
                    {
705
                        printIndy.IsBusy = false;
706 86bff326 taeseongkim
                    });
707
708
                    await PageChangeAsync(_StartPageNo);
709 787a4489 KangIngu
710 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
711
                }else
712
                {
713
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
714
                    {
715
                        printIndy.IsBusy = false;
716
                    }));
717 787a4489 KangIngu
718 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
719
                }                
720
            }
721
            catch (Exception ex)
722 787a4489 KangIngu
            {
723 86bff326 taeseongkim
                printIndy.IsBusy = false;
724
725 481c3fb9 djkim
                Logger.sendResLog("Export Method", ex.Message, 0);
726
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
727
            }
728 787a4489 KangIngu
729
        }
730
        #endregion
731
732
        #region Method - 처리
733
        void CheckCommentPages()
734
        {
735
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
736
            DoubleCollection _Ticks = new DoubleCollection();
737
738
739
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
740
            {
741
742
                _pages = (from commPage in this._PageMarkupList
743
                          where commPage.PageNumber == CurrentPageNo
744
                          orderby commPage.PageNumber
745
                          select commPage).ToList();
746
            }
747
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
748
            {
749
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
750
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
751
752
                int _stPage = (int)stPageNo.Value;
753
                int _edPage = (int)edPageNo.Value;
754
755
                _pages = (from commPage in this._PageMarkupList
756
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
757
                          orderby commPage.PageNumber
758
                          select commPage).ToList();
759
            }
760
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
761
            {
762
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
763
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
764
765
                int _stPage = (int)stPageNo.Value;
766
                int _edPage = (int)edPageNo.Value;
767
768
                //Using DeepView.Common.RangeParser
769
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
770
                _pages = (from commPage in this._PageMarkupList
771
                          from compareData in lst
772
                          where commPage.PageNumber == compareData
773
                          orderby commPage.PageNumber
774
                          select commPage).ToList();
775
            }
776
            else
777
            {
778
                _pages = (from commPage in this._PageMarkupList
779
                          orderby commPage.PageNumber
780
                          select commPage).ToList();
781
            }
782
            CommentPageList.ItemsSource = _pages.ToList();
783
        }
784
785
        void SetLoadMakupList(int PageNo)
786
        {
787
            _LoadMakupList.Clear();
788
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
789
790
            if (_markupList.Count() > 0)
791
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
792
        }
793
794
        #region 프린트 리스트 가져오기
795
        public void GetPrint(bool flag)
796
        {
797
            if (flag)
798
            {
799
                foreach (string printer in PrinterSettings.InstalledPrinters)
800
                {
801
                    this.cbPrint.Items.Add(printer);
802
                }
803
                printDocument = new PrintDocument();
804
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
805
            }
806
            else
807
            {
808
                this.cbPrint.Items.Add("PDF");
809
                this.cbPrint.Items.Add("IMAGE");
810
811
                this.cbPrint.SelectedItem = "PDF";
812
            }
813
        }
814
        #endregion
815
816
        #region 프린트 실행
817 86bff326 taeseongkim
        public async void Printing()
818 787a4489 KangIngu
        {
819 86bff326 taeseongkim
            await PageChangeAsync(1);
820
821 787a4489 KangIngu
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
822
            {
823 481c3fb9 djkim
                printDocument = new PrintDocument();
824 408e4218 ljiyeon
                printDocument.OriginAtMargins = true;
825 787a4489 KangIngu
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
826
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
827
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
828
            }
829
            else
830
                printDocument = null;
831
832
            #region 인쇄 미리보기 테스트
833
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
834
            {
835
                printDocument.PrinterSettings.MinimumPage = 1;
836
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
837
                printDocument.PrinterSettings.FromPage = 1;
838 408e4218 ljiyeon
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
839 787a4489 KangIngu
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
840 481c3fb9 djkim
                printDocument.PrinterSettings.PrinterName = PrintName;
841
                dlg.Document = printDocument;
842 787a4489 KangIngu
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
843
                dlg.ShowDialog();
844
            }
845
            #endregion
846
847
            #region 인쇄
848
            //printDocument.PrinterSettings.MinimumPage = 1;
849
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
850
            //printDocument.PrinterSettings.FromPage = 1;
851
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
852
853
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
854
            //printDocument.PrinterSettings.PrinterName = PrintName;
855
856
            //printDocument.Print();
857
            #endregion
858
        }
859
860
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
861
        {
862
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
863
            // This demo only loads one page at a time, so no need to re-set the print page number
864 481c3fb9 djkim
            PrintDocument document = sender as PrintDocument;
865 787a4489 KangIngu
            currentPage = document.PrinterSettings.FromPage;
866
        }
867 481c3fb9 djkim
868 787a4489 KangIngu
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
869
        {
870
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
871
872
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
873
            {
874
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
875 2024d8d1 ljiyeon
876 481c3fb9 djkim
                if (p_img.Width > p_img.Height)
877 2024d8d1 ljiyeon
                {
878
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
879
                }
880 408e4218 ljiyeon
881
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
882
                System.Drawing.Image pic = p_img;
883 787a4489 KangIngu
                System.Drawing.Rectangle m = e.MarginBounds;
884
885 408e4218 ljiyeon
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
886
                //{
887
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
888
                //}
889
                //else
890
                //{
891
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
892
                //}
893
                m.Width = (int)e.PageSettings.PrintableArea.Width;
894
                m.Height = (int)e.PageSettings.PrintableArea.Height;
895
                m.X = (int)e.PageSettings.HardMarginX;
896
                m.Y = (int)e.PageSettings.HardMarginY;
897
898
                e.Graphics.DrawImage(pic, m);
899 787a4489 KangIngu
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
900
                //e.Graphics.DrawImage(p_img, 0, 0);
901
            }));
902 481c3fb9 djkim
903 787a4489 KangIngu
            //다음 페이지
904
            currentPage++;
905 481c3fb9 djkim
906 787a4489 KangIngu
            ////인쇄를 계속 할지 말지 확인
907
            if (currentPage <= printDocument.PrinterSettings.ToPage)
908
                e.HasMorePages = true;
909
            else
910
                e.HasMorePages = false;
911
912
        }
913
914
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
915
        {
916
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
917
            {
918
                printIndy.IsBusy = false;
919
            }));
920
        }
921
        #endregion
922
923
        #region Selected Pages Check
924
        List<int> PrintPageCreate()
925
        {
926
            List<int> Result = new List<int>();
927
928
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
929
            {
930
                Result.Add(CurrentPageNo);
931
            }
932
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
933
            {
934
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
935
                {
936
                    Result.Add(i);
937
                }
938
            }
939
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
940
            {
941
                int _stPage = (int)stPageNo.Value;
942
                int _edPage = (int)edPageNo.Value;
943
944
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
945
                Result.AddRange(lst);
946
            }
947
            else
948
            {
949
                for (int i = 1; i <= _definePages.PagesCount; i++)
950
                {
951
                    Result.Add(i);
952
                }
953
            }
954
            if (currentPagePrint)
955
            {
956
                return Result;
957
            }
958
959
            if (chkOnlyMarkup.IsChecked.Value)
960
            {
961
                var _result = from result in Result
962
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
963
                              select result;
964
                Result = _result.ToList();
965
            }
966
            return Result;
967
        }
968
        #endregion
969
970
        #endregion
971
    }
972
}
클립보드 이미지 추가 (최대 크기: 500 MB)