프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (44.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 KCOMDataModel.DataModel;
12
using Microsoft.Win32;
13
using System.IO;
14
using System.Timers;
15
//using IKCOM.Common;
16
using KCOM.Event;
17
using iTextSharp;
18
using iTextSharp.text;
19
//using Leadtools.Windows.Controls;
20
using IKCOM;
21
using iTextSharp.text.pdf;
22 481c3fb9 djkim
using System.Net;
23 86bff326 taeseongkim
using Image = System.Windows.Controls.Image;
24 e6c46927 taeseongkim
using System.ComponentModel;
25 e3a15e22 djkim
26 787a4489 KangIngu
namespace KCOM.Control
27
{
28
    public class DefinedPages
29
    {
30 86bff326 taeseongkim
        public DOCINFO DocumentInfo { get; set; }
31
32 787a4489 KangIngu
        public int PagesCount { get; set; }
33
        public string vpSlip { get; set; }
34
        public string vpTitle { get; set; }
35
        public string fileUrl { get; set; }
36
        public ImageBrush Back_Image { get; set; }
37
38 86bff326 taeseongkim
        public double CurrentValue { get; set; }
39
40 787a4489 KangIngu
        string _DefinedPagesStrings;
41
        /// <summary>
42
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
43
        /// </summary>
44
        public string DefinedPagesStrings
45
        {
46
            get { return _DefinedPagesStrings; }
47
            set
48
            {
49
                if (string.IsNullOrWhiteSpace(value)) return;
50
51
                var _definedPages = value.Replace('-', ',').Split(',');
52
                List<char> _NotEx = new List<char>();
53
54
                foreach (var item in _definedPages)
55
                {
56
                    bool _isNum = true;
57
58
                    foreach (var chr in item)
59
                    {
60
                        if (!char.IsNumber(chr))
61
                        {
62
                            _NotEx.Add(chr);
63
                            _isNum = false;
64
                        }
65
                    }
66
67
                    if (_isNum)
68
                    {
69
                        if (Convert.ToInt32(item) > PagesCount)
70
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
71
                    }
72
                }
73
74
                if (_NotEx.Count() > 0)
75
                {
76
                    string _notString = "";
77
                    _NotEx.ForEach(s => _notString += s.ToString());
78
                    throw new Exception(string.Format("'{0}' Can not be added.", _notString));
79
                }
80
81
82
                try
83
                {
84
85
                    string _notString2 = "";
86
                    _NotEx.ForEach(s => _notString2 += s.ToString());
87
                    _DefinedPagesStrings = value;
88
                }
89
                catch (Exception)
90
                {
91
                    throw new Exception(string.Format("Can not be added."));
92
                }
93
94
            }
95
        }
96
    }
97
98
    /// <summary>
99
    /// Interaction logic for Print.xaml
100
    /// </summary>
101
    public partial class PrintControl : UserControl
102
    {
103
        #region Data
104
105
        string ProjectNo = null; //프로젝트 넘버
106
        string _DefaultTileUri = null; //기본 타일 경로
107
        int _StartPageNo; //시작페이지 
108
        DOCINFO _DocInfo; //문서 정보
109
        //DocInfo _DocInfo; //문서 정보
110
        bool currentPagePrint = false; //현재 페이지 수
111
        int PageCount { get; set; } //총 페이지수 
112
        DefinedPages _definePages = null; //인쇄 설정 범위 지정
113
        public bool IsPrint { get; set; }
114
115
        PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성
116
117
        //LayerControl LayerControl = null; // 레이어 컨트롤
118
        ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보
119
        List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>();
120
        List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>();
121
        List<int> _lstPrintPageNo = new List<int>();
122
123
        System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer();
124
        bool _initializeComponentFinished; //이벤트
125
        bool _IsDagSlider = false; //드래그 상태인가
126 e6c46927 taeseongkim
        bool IsExportOrPrint = false;
127
        bool IsStop = false;
128 ca49aa5b taeseongkim
129 787a4489 KangIngu
        List<DisplayColorInfo> colorList = new List<DisplayColorInfo>();
130
        DefinedPages DocumentInfo { get; set; } //문서정보 정의        
131
        //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 
132
        delegate void PrintEventHandler(); //프린트 핸들러
133
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
134
        //SaveFileDialog SaveFile { get; set; } //저장할 때 사용
135
136
        //RasterImageViewer _viewer; //이미지 뷰어
137 53880c83 ljiyeon
        //System.Windows.Controls.Image backimg; //백그라운드 이미지
138 787a4489 KangIngu
        System.Drawing.Image Printimg; //프린트 이미지
139
        System.Drawing.Image p_img; //프린트 이미지
140
        iTextSharp.text.Image Export_img;
141 481c3fb9 djkim
        Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지
142 77cdac33 taeseongkim
        Dictionary<int, string> PrintimgPath_List; //프린트 이미지 파일 경로
143
        string TempImageDir = null;
144 787a4489 KangIngu
145
        //RasterCodecs codecs;
146
        int currentPage;
147
        public string PrintName;
148
        public string Type;
149
150
        public System.Timers.Timer timm = new System.Timers.Timer();
151
152
153
        #endregion
154
155
        #region Static Property Defines
156 e6c46927 taeseongkim
157
        public static readonly DependencyProperty BusyContentProperty =
158
            DependencyProperty.RegisterAttached("BusyContent", typeof(string), typeof(PrintControl),
159
            new PropertyMetadata(new PropertyChangedCallback(BusyContentPropertyChanged)));
160
        #endregion
161
162
        #region Property
163
        public string BusyContent
164
        {
165
            get { return (string)GetValue(BusyContentProperty); }
166
            set { SetValue(BusyContentProperty, value); }
167
        }
168
        #endregion
169
170
        #region PropertyChangeMethod
171
        private static void BusyContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
172
        {
173
        }
174
175 787a4489 KangIngu
        public static readonly DependencyProperty CurrentPageNoProperty =
176
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
177
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
178
        #endregion
179
180
        #region Property
181
        public int CurrentPageNo
182
        {
183
            get { return (int)GetValue(CurrentPageNoProperty); }
184
            set { SetValue(CurrentPageNoProperty, value); }
185
        }
186
        #endregion
187
188
        #region PropertyChangeMethod
189
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
190
        {
191
            var printPage = (PrintControl)d;
192
            var newValue = (int)e.NewValue;
193
194
            printPage.sliderPages.Value = newValue;
195
            printPage.SetLoadMakupList(newValue);
196
197
        }
198
        #endregion
199
200
        #region 생성자
201 481c3fb9 djkim
202 787a4489 KangIngu
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
203
        {
204
            InitializeComponent();
205 481c3fb9 djkim
206 2b1f30fe taeseongkim
            this.Unloaded += (snd, evt) =>
207
            {
208
                try
209
                {
210
                    if (Directory.Exists(TempImageDir))
211
                        Directory.Delete(TempImageDir, true);
212
                }
213
                catch (Exception)
214
                {
215
                }
216
            };
217
218 787a4489 KangIngu
            this.IsEnabled = true;
219
220
            //Layer Control을 통째로 가져와야 하는건가
221
            this._DocInfo = DocInfo;
222
            this._DefaultTileUri = TileSourceUri;
223
            this.ProjectNo = ProjectNo;
224
            this._StartPageNo = CurrentPageNo;
225
226
            markupInfo.ForEach(info => this._markupInfo.Add(info));
227
228
            foreach (var info in _markupInfo)
229
            {
230
                if (info.Consolidate == 1)
231
                {
232
                    info.UserName = "Consolidation";
233
                }
234
                info.MarkupList.ForEach(makup =>
235
                {
236
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
237
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
238
239
                    if (_pageMarkup.Count() > 0)
240
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
241
                    else
242
                        _PageMarkupList.Add(new MarkupPageItem
243
                        {
244
                            PageNumber = makup.PageNumber,
245
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
246
                        });
247
                });
248
249
                colorList.Add(new DisplayColorInfo
250
                {
251
                    UserID = info.UserID,
252
                    DisplayColor = info.DisplayColor,
253
                    Department = info.Depatment,
254
                    UserName = info.UserName,
255
                });
256
            }
257
258
            gridViewMarkup.ItemsSource = this._markupInfo;
259
            SetLoadMakupList(this._StartPageNo);
260
            if (_LoadMakupList.Count() == 0)
261
                chkOnlyMarkup.IsChecked = false;
262
263
            this.CurrentPageNo = _StartPageNo;
264 86bff326 taeseongkim
265
            _definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo
266
                            , PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
267
268 787a4489 KangIngu
            DocumentInfo = _definePages;
269
            this.DataContext = _definePages;
270
271
            CheckCommentPages();
272
273
            //초기화면 Comment Check된 상태로 보여주기
274
            foreach (var item in _markupInfo)
275
            {
276
                gridViewMarkup.SelectedItems.Add(item);
277
            }
278
279 d2050059 taeseongkim
            PageChangeAsync(Common.ViewerDataModel.Instance.NewPagImageCancelToken(), _StartPageNo,false).ConfigureAwait(true);
280 787a4489 KangIngu
281
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
282
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
283
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
284
            this.IsPrint = isPrint;
285
286
            if (!IsPrint)
287
            {
288
                GetPrint(false);
289
                btnWholeExport.Visibility = Visibility.Visible;
290
                btnWholePrint.Visibility = Visibility.Collapsed;
291
                Selected_Print.Header = "Export Type";
292
            }
293
            else
294
            {
295
                //PrintList 가져오기
296
                GetPrint(true);
297
                btnWholePrint.Visibility = Visibility.Visible;
298
                btnWholeExport.Visibility = Visibility.Collapsed;
299
            }
300
301
            _initializeComponentFinished = true;
302
303
            //timm.Interval = 10;
304
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
305
            //timm.Enabled = true;
306
        }
307
308
        #endregion
309
310
        #region Control Event
311 86bff326 taeseongkim
        private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
312 787a4489 KangIngu
        {
313
            if (_initializeComponentFinished)
314
            {
315
                if (!_IsDagSlider)
316
                {
317
                    this.CurrentPageNo = (int)this.sliderPages.Value;
318 24c5e56c taeseongkim
319 ca49aa5b taeseongkim
                    if (!IsExportOrPrint)
320
                    {
321 d2050059 taeseongkim
                        await PageChangeAsync(Common.ViewerDataModel.Instance.NewPagImageCancelToken(), this.CurrentPageNo, false);
322 ca49aa5b taeseongkim
                    }
323 90865212 taeseongkim
                    //await App.PageStorage.GetPageUriAsync(this.CurrentPageNo);
324 53deabaf taeseongkim
                
325 481c3fb9 djkim
                    if (_ButtonName == "Current")
326 114015fd ljiyeon
                    {
327
                        stPageNo.Value = CurrentPageNo;
328
                        edPageNo.Value = CurrentPageNo;
329 481c3fb9 djkim
                    }
330 114015fd ljiyeon
331 787a4489 KangIngu
                    //CheckCommentPages();
332
                }
333
            }
334
        }
335
336 86bff326 taeseongkim
        private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
337 787a4489 KangIngu
        {
338
            _IsDagSlider = false;
339
            this.CurrentPageNo = (int)this.sliderPages.Value;
340
            if (_initializeComponentFinished)
341
            {
342 90865212 taeseongkim
               
343 787a4489 KangIngu
            }
344
        }
345
346
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
347
        {
348
            _IsDagSlider = true;
349
        }
350
351
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
352
        {
353
            if (_initializeComponentFinished)      //GridRangePages
354
            {
355
                CheckCommentPages();
356
            }
357
        }
358 2b1f30fe taeseongkim
359
        private void chkOnlyRedColor_Checked(object sender, RoutedEventArgs e)
360
        {
361
            if (_initializeComponentFinished)      //GridRangePages
362
            {
363
                CheckCommentPages();
364
            }
365
        }
366
        
367
368 114015fd ljiyeon
        string _ButtonName;
369 787a4489 KangIngu
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
370
        {
371
            if (!_initializeComponentFinished) return;
372
373 114015fd ljiyeon
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
374 787a4489 KangIngu
            CommentPageList.ItemsSource = null;
375
376
            switch (_ButtonName)
377
            {
378
                case "Current":
379
                    stPageNo.Value = CurrentPageNo;
380
                    edPageNo.Value = CurrentPageNo;
381
382
                    GridCurrentPage.Visibility = Visibility.Visible;
383
                    GridDefinePages.Visibility = Visibility.Collapsed;
384
                    GridRangePages.Visibility = Visibility.Collapsed;
385
                    GridAllPages.Visibility = Visibility.Collapsed;
386
387
                    break;
388
                case "RangePrint":
389
                    GridCurrentPage.Visibility = Visibility.Collapsed;
390
                    GridDefinePages.Visibility = Visibility.Visible;
391
                    GridRangePages.Visibility = Visibility.Collapsed;
392
                    GridAllPages.Visibility = Visibility.Collapsed;
393
                    break;
394
                case "UserDefined":
395
                    GridCurrentPage.Visibility = Visibility.Collapsed;
396
                    GridDefinePages.Visibility = Visibility.Collapsed;
397
                    GridRangePages.Visibility = Visibility.Visible;
398
                    GridAllPages.Visibility = Visibility.Collapsed;
399
                    break;
400
                case "AllPrint":
401
                    stPageNo.Value = 1;
402
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
403
                    GridCurrentPage.Visibility = Visibility.Collapsed;
404
                    GridDefinePages.Visibility = Visibility.Collapsed;
405
                    GridRangePages.Visibility = Visibility.Collapsed;
406
                    GridAllPages.Visibility = Visibility.Visible;
407
                    break;
408
            }
409
410
            CheckCommentPages();
411
        }
412
413
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
414
        {
415
            if (_initializeComponentFinished)      //GridRangePages
416
            {
417
                if (stPageNo.Value > edPageNo.Value)
418
                {
419
                    if (sender.Equals(stPageNo))
420
                        edPageNo.Value = stPageNo.Value;
421
                    else
422
                        stPageNo.Value = edPageNo.Value;
423
                }
424
425
                //뷰어잠시제외(강인구)
426
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
427
                //{
428
                CheckCommentPages();
429
                //});
430
            }
431
        }
432
433
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
434
        {
435
            CheckCommentPages();
436
        }
437
438
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
439
        {
440
            txtDefinedPages.Text = "";
441
        }
442
443
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
444
        {
445
            if (_initializeComponentFinished)
446
                if (CommentPageList.SelectedItem != null)
447
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
448
        }
449
450 86bff326 taeseongkim
        private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
451 787a4489 KangIngu
        {
452
            if (_initializeComponentFinished)
453
            {
454 d2050059 taeseongkim
                await PageChangeAsync(Common.ViewerDataModel.Instance.NewPagImageCancelToken(),this.CurrentPageNo, false);
455 787a4489 KangIngu
            }
456
        }
457
458
        #endregion
459
460 77cdac33 taeseongkim
        public async System.Threading.Tasks.Task<bool> PageChangeAsync(System.Threading.CancellationToken cts, int PageNo,bool saveFile, bool Flag = false)
461 787a4489 KangIngu
        {
462 53deabaf taeseongkim
            System.Diagnostics.Debug.WriteLine("PageChangeAsync " + PageNo);
463 86bff326 taeseongkim
            bool result = false;
464
            //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
465
            //{
466
            try
467 787a4489 KangIngu
            {
468 86bff326 taeseongkim
                _definePages.Back_Image = new ImageBrush();
469
                //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
470
471
                var pages = _definePages.DocumentInfo.DOCPAGE.Where(x => x.PAGE_NUMBER == PageNo);
472
473
                if(pages.Count() > 0)
474 481c3fb9 djkim
                {
475 86bff326 taeseongkim
                    var currentPage = pages.First();
476 787a4489 KangIngu
477 86bff326 taeseongkim
                    //var buffer = await new WebClient().DownloadDataTaskAsync(_DefaultTileUri + PageNo + ".png");
478
479
                    //var bitmap = new BitmapImage();
480
                    //using (var stream = new MemoryStream(buffer))
481
                    //{
482 90865212 taeseongkim
                    //bitmap.BeginInit();
483
                    //bitmap.CacheOption = BitmapCacheOption.OnLoad;
484
                    //bitmap.StreamSource = stream;
485
                    //bitmap.EndInit();
486
487
                        
488 43a743e4 taeseongkim
                    var uri = await App.PageStorage.GetPageUriAsync(cts, currentPage.PAGE_NUMBER);
489 90865212 taeseongkim
                    //Image bitmap = new Image();
490
                    //bitmap.Stretch = Stretch.Fill;
491
                    //bitmap.Source = bitmapframe;
492
                    //bitmap.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
493
                    //bitmap.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
494 89971d17 taeseongkim
495 43e1d368 taeseongkim
                    //if (uri.Scheme == Uri.UriSchemeFile)
496
                    //{
497
                    //    var cloneUri = new Uri(System.IO.Path.Combine(System.IO.Path.GetTempPath(),System.IO.Path.GetRandomFileName()),UriKind.Absolute);
498
                    //    File.Copy(uri.LocalPath, cloneUri.LocalPath);
499 89971d17 taeseongkim
500 43e1d368 taeseongkim
                    //    uri = cloneUri;
501
                    //}
502 89971d17 taeseongkim
503 00143658 taeseongkim
                    printCanvas.Children.Clear();
504
                    printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
505
                    printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
506 89971d17 taeseongkim
                    printCanvas.Background = new ImageBrush{ ImageSource = new BitmapImage(uri)};
507 a9a82876 taeseongkim
                    printCanvas.SnapsToDevicePixels = false;
508
                    printCanvas.UseLayoutRounding = false;
509
                    printCanvas.CacheMode = new BitmapCache(50);
510
                    RenderOptions.SetBitmapScalingMode(printCanvas, BitmapScalingMode.HighQuality);
511 00143658 taeseongkim
                    //printCanvas.RenderTransformOrigin = new Point(0.5, 0.5);
512
                    //printCanvas.RenderTransform = new RotateTransform(currentPage.PAGE_ANGLE);
513
                    //ImageBrush background = new ImageBrush(bitmap);
514
                    //printCanvas.Background = background;
515
                    //printCanvas.Background = new SolidColorBrush(Colors.Transparent);
516 787a4489 KangIngu
517 a1cc6e1f taeseongkim
                    Canvas canvas = new Canvas();
518 a9a82876 taeseongkim
                    canvas.CacheMode = new BitmapCache(50);
519
                    canvas.SnapsToDevicePixels = false;
520
                    RenderOptions.SetBitmapScalingMode(canvas, BitmapScalingMode.HighQuality);
521 a1cc6e1f taeseongkim
                    //foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
522
                    //{
523
                    //    load.User_Id = info.UserID;
524
                    //    load.document_id = _DocInfo.DOCUMENT_ID;
525
                    //    load.Page_No = PageNo;
526
527
                    //    if (chkOnlyRedColor.IsChecked == true)
528
                    //    {
529
                    //        load.DisplayColor = "#FFFF0000";
530
                    //    }
531
                    //    else
532
                    //    {
533
                    //        load.DisplayColor = info.DisplayColor;
534
                    //    }
535
536
                    //    load.Markupinfoid = info.MarkupInfoID;
537
                    //    var IsLoad = await load.Markup_LoadAsync(canvas, 0);
538
                    //}
539 2b1f30fe taeseongkim
540 a1cc6e1f taeseongkim
                    var tasks = gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()
541
                                        .Select(async info =>
542
                                        {
543 a9a82876 taeseongkim
                                            Load load = new Load();
544 a1cc6e1f taeseongkim
                                            load.User_Id = info.UserID;
545
                                            load.document_id = _DocInfo.DOCUMENT_ID;
546
                                            load.Page_No = PageNo;
547
                                            load.DisplayColor = chkOnlyRedColor.IsChecked == true ? "#FFFF0000" : info.DisplayColor;
548
                                            load.Markupinfoid = info.MarkupInfoID;
549
                                            return await load.Markup_LoadAsync(canvas, 0);
550
                                        });
551
552
                    var results = await System.Threading.Tasks.Task.WhenAll(tasks);
553
554
                    //printCanvas.Children.Add(canvas);
555
556
                    printCanvas.Children.Add(canvas);
557 2b1f30fe taeseongkim
558 90865212 taeseongkim
                    //await Dispatcher.InvokeAsync(() => {
559
                    //    printCanvas.UpdateLayout();
560
                    //});
561 481c3fb9 djkim
562 d04e8ee9 taeseongkim
                    if (Flag)
563 481c3fb9 djkim
                        {
564 d04e8ee9 taeseongkim
                        //MemoryStream ms = new MemoryStream();
565
                        //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
566
                        //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
567
                        //bbe.Save(ms);
568
569
                        //System.Drawing.Image.FromFile()
570
                        //Printimg = System.Drawing.Image.FromStream(stream);
571 53deabaf taeseongkim
                        //await System.Threading.Tasks.Task.Run(() =>
572
                        //{
573
                           await Dispatcher.InvokeAsync(() =>
574 d04e8ee9 taeseongkim
                            {
575
                                Export export = new Export();
576 77cdac33 taeseongkim
577
                                if (saveFile)
578
                                {
579
                                    var filepath = Path.Combine(TempImageDir, $"{PrintimgPath_List.Count() + 1}.png");
580
581 a9a82876 taeseongkim
                                    if (export.ExportingFile(printCanvas, printCanvas.Width, printCanvas.Height, filepath))
582 77cdac33 taeseongkim
                                    {
583
                                        PrintimgPath_List.Add(PrintimgPath_List.Count() + 1, filepath);
584
                                    }
585
                                    else
586
                                    {
587
                                        throw new Exception($"Export Image Save File Error :{filepath}");
588
                                    }
589
                                }
590
                                else
591
                                {
592
                                    p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height);
593
                                    Printimg_List.Add(Printimg_List.Count() + 1, p_img);
594
                                }
595
596 43a743e4 taeseongkim
                            },System.Windows.Threading.DispatcherPriority.SystemIdle);
597 53deabaf taeseongkim
                        //});
598 d04e8ee9 taeseongkim
                    }
599 481c3fb9 djkim
600 86bff326 taeseongkim
                        result = true;
601
                    //}
602
                } 
603
            }
604
            catch (Exception ex)
605
            {
606 664ea2e1 taeseongkim
                //Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
607 86bff326 taeseongkim
            }
608
609
            return result;
610
            //}));
611 787a4489 KangIngu
        }
612 89971d17 taeseongkim
613
614 481c3fb9 djkim
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
615
        {
616
            var ms = new MemoryStream();
617
            var pngEncoder = new PngBitmapEncoder();
618
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
619
            pngEncoder.Save(ms);
620 787a4489 KangIngu
621 481c3fb9 djkim
            return ms;
622
        }
623 787a4489 KangIngu
        //Print 버튼 클릭 이벤트
624
        #region Method - 명령
625 86bff326 taeseongkim
        async void PrintMethod(object sender, RoutedEventArgs e)
626 787a4489 KangIngu
        {
627 481c3fb9 djkim
            try
628
            {
629 d2050059 taeseongkim
                var token = Common.ViewerDataModel.Instance.NewPagImageCancelToken();
630 24c5e56c taeseongkim
631 481c3fb9 djkim
                if (this.printIndy.IsBusy == true)
632
                    return;
633 787a4489 KangIngu
634 00143658 taeseongkim
                (this.Parent as RadWindow).CanClose = false;
635
636 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => { 
637 481c3fb9 djkim
                        this.printIndy.IsBusy = true;
638 e6c46927 taeseongkim
                        this.BusyContent = "Printing. . .";
639 481c3fb9 djkim
                });
640 787a4489 KangIngu
641 481c3fb9 djkim
642
                _lstPrintPageNo = PrintPageCreate();
643
644
                if (_lstPrintPageNo.Count == 0)
645 787a4489 KangIngu
                {
646 481c3fb9 djkim
                    RadWindow.Alert(new DialogParameters
647
                    {
648
                        Owner = Application.Current.MainWindow,
649
                        Theme = new VisualStudio2013Theme(),
650 eeb0a39c taeseongkim
                        Header = "Info",
651
                        Content = "Not specified the page."
652 481c3fb9 djkim
                    });
653 9d5b4bc2 taeseongkim
                    sliderPages.Value = 1;
654 481c3fb9 djkim
                    this.printIndy.IsBusy = false;
655
                    return;
656
                }
657 86bff326 taeseongkim
658 481c3fb9 djkim
                int cnt = 0;
659 787a4489 KangIngu
660 ca49aa5b taeseongkim
                IsExportOrPrint = true;
661
662 481c3fb9 djkim
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
663 77cdac33 taeseongkim
                PrintimgPath_List = new Dictionary<int, string>();
664 5a223b60 humkyung
                TempImageDir = Path.Combine(Path.GetTempPath(), "Markus", Common.Commons.ShortGuid());
665 77cdac33 taeseongkim
666
                if (Directory.Exists(TempImageDir))
667
                {
668
                    Directory.Delete(TempImageDir, true);
669
                }
670
671
                Directory.CreateDirectory(TempImageDir);
672 787a4489 KangIngu
673 481c3fb9 djkim
                foreach (int PageNo in _lstPrintPageNo)
674
                {
675 e6c46927 taeseongkim
                    if (IsStop)
676
                        break;
677
678 481c3fb9 djkim
                    cnt++;
679
                    sliderPages.Value = PageNo;
680 77cdac33 taeseongkim
                    await PageChangeAsync(token,PageNo, true, true);
681 481c3fb9 djkim
                    //PageChanged(cnt, true);
682
                }
683
                PrintName = cbPrint.SelectedItem.ToString();
684 787a4489 KangIngu
685 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => {
686 e6c46927 taeseongkim
                    if (cnt == _lstPrintPageNo.Count && !IsStop)
687 481c3fb9 djkim
                    {
688
                        Printing();
689
                    }
690 787a4489 KangIngu
                });
691 ca49aa5b taeseongkim
692
                IsExportOrPrint = false;
693 787a4489 KangIngu
            }
694 481c3fb9 djkim
            catch (Exception ex)
695 787a4489 KangIngu
            {
696 664ea2e1 taeseongkim
                //Logger.sendResLog("PrintMethod", ex.Message, 0);
697 787a4489 KangIngu
            }
698 00143658 taeseongkim
            finally
699
            {
700 e6c46927 taeseongkim
                if (IsStop)
701
                {
702
                    printIndy.IsBusy = false;
703
                    IsStop = false;
704
                }
705 00143658 taeseongkim
                (this.Parent as RadWindow).CanClose = true;
706
            }
707 787a4489 KangIngu
708
        }
709
710
        //Export 버튼 클릭 이벤트
711 43e1d368 taeseongkim
        [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
712 6a19b48d taeseongkim
        //[System.Security.Permissions.FileIOPermission(System.Security.Permissions.SecurityAction.LinkDemand)]
713 86bff326 taeseongkim
        async void ExportMethod(object sender, RoutedEventArgs e)
714 787a4489 KangIngu
        {
715 481c3fb9 djkim
            try
716
            {
717
                if (this.printIndy.IsBusy == true)
718
                    return;
719 787a4489 KangIngu
720 d2050059 taeseongkim
                var token = Common.ViewerDataModel.Instance.NewPagImageCancelToken();
721 24c5e56c taeseongkim
722 00143658 taeseongkim
                (this.Parent as RadWindow).CanClose = false;
723
724 481c3fb9 djkim
                this.printIndy.IsBusy = true;
725 e6c46927 taeseongkim
                this.BusyContent = "Exporting. . .";
726 787a4489 KangIngu
727 481c3fb9 djkim
                Export export = new Export();
728
                _lstPrintPageNo = PrintPageCreate();
729 787a4489 KangIngu
730 481c3fb9 djkim
                if (_lstPrintPageNo.Count == 0)
731 787a4489 KangIngu
                {
732 9d5b4bc2 taeseongkim
                    sliderPages.Value = 1;
733 481c3fb9 djkim
                    this.printIndy.IsBusy = false;
734
                    RadWindow.Alert(new DialogParameters
735 787a4489 KangIngu
                    {
736 481c3fb9 djkim
                        Owner = Application.Current.MainWindow,
737
                        Theme = new VisualStudio2013Theme(),
738 eeb0a39c taeseongkim
                        Header = "Info",
739
                        Content = "Not specified the page.",
740 481c3fb9 djkim
                    });
741
                    return;
742
                }
743 787a4489 KangIngu
744 481c3fb9 djkim
                //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
745 787a4489 KangIngu
746
                switch (cbPrint.SelectedIndex)
747
                {
748
                    case (0):
749
                        {
750 481c3fb9 djkim
                            SaveDig.Filter = "PDF file format|*.pdf";
751
                            break;
752
                        }
753
                    case (1):
754
                        {
755 77cdac33 taeseongkim
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg";
756 481c3fb9 djkim
                            break;
757
                        }
758
                }
759
760
                SaveDig.Title = "Save an PDF File";
761
                if(SaveDig.ShowDialog().Value)
762
                {
763 ca49aa5b taeseongkim
                    IsExportOrPrint = true;
764 77cdac33 taeseongkim
765
                    PrintimgPath_List = new Dictionary<int, string>();
766 5a223b60 humkyung
                    TempImageDir = Path.Combine(Path.GetTempPath(), "Markus", Common.Commons.ShortGuid());
767 77cdac33 taeseongkim
768
                    if (Directory.Exists(TempImageDir))
769
                    {
770
                        Directory.Delete(TempImageDir, true);
771
                    }
772
773
                    Directory.CreateDirectory(TempImageDir);
774 481c3fb9 djkim
775
                    foreach (int PageNo in _lstPrintPageNo)
776
                    {
777 e6c46927 taeseongkim
                        if (IsStop)
778
                            break;
779
780 d04e8ee9 taeseongkim
                        await Dispatcher.InvokeAsync(() =>
781
                        {
782
                            sliderPages.Value = PageNo;
783
                        });
784 53deabaf taeseongkim
785 77cdac33 taeseongkim
                        await PageChangeAsync(token, PageNo, true, true);
786 43a743e4 taeseongkim
787 53deabaf taeseongkim
                        System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo);
788 481c3fb9 djkim
                    }
789
790
                    //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
791
792
                    if (SaveDig.FileName != "")
793
                    {
794
                        switch (cbPrint.SelectedIndex)
795
                        {
796
                            case (0):
797 787a4489 KangIngu
                                {
798 43e1d368 taeseongkim
                                    FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write);
799
800
                                    Document doc = new Document();
801 6a19b48d taeseongkim
                                    try
802
                                    {
803
                                        iTextSharp.text.Version.GetInstance();
804
                                    }
805
                                    catch (System.NullReferenceException ex)
806
                                    {
807
808
                                    }
809
810 43e1d368 taeseongkim
                                    PdfWriter writer = PdfWriter.GetInstance(doc, fs);
811
812
                                    doc.Open();
813 6a19b48d taeseongkim
                                    
814 43e1d368 taeseongkim
                                    float height = doc.PageSize.Height;
815
                                    float width = doc.PageSize.Width;
816
817
                                    foreach (var item in PrintimgPath_List)
818 787a4489 KangIngu
                                    {
819 e6c46927 taeseongkim
                                        if (IsStop)
820
                                            break;
821
822 43e1d368 taeseongkim
                                        System.Drawing.Image image = System.Drawing.Image.FromFile(item.Value);
823
                                        Export_img = iTextSharp.text.Image.GetInstance(image,System.Drawing.Imaging.ImageFormat.Jpeg);
824
825
                                        if (Export_img.Width > Export_img.Height)
826
                                        {
827
                                            doc.SetPageSize(new Rectangle(height, width));
828
                                            Export_img.ScaleToFit(height, width);
829
                                        }
830
                                        else
831 787a4489 KangIngu
                                        {
832 43e1d368 taeseongkim
                                            doc.SetPageSize(new Rectangle(width, height));
833
                                            Export_img.ScaleToFit(width, height);
834 787a4489 KangIngu
                                        }
835 43e1d368 taeseongkim
836
                                        Export_img.SetAbsolutePosition(0, 0);
837
838
                                        doc.NewPage();
839
                                        doc.Add(Export_img);
840 787a4489 KangIngu
                                    }
841 6a19b48d taeseongkim
                                    doc.Close();
842
                                    writer.Close();
843 481c3fb9 djkim
                                    break;
844 787a4489 KangIngu
                                }
845 481c3fb9 djkim
                            case (1):
846 787a4489 KangIngu
                                {
847 77cdac33 taeseongkim
                                    foreach (var item in PrintimgPath_List)
848 481c3fb9 djkim
                                    {
849 e6c46927 taeseongkim
                                        if (IsStop)
850
                                            break;
851
852 77cdac33 taeseongkim
                                        File.Copy(item.Value, SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg");
853 481c3fb9 djkim
                                    }
854
                                    break;
855 787a4489 KangIngu
                                }
856
                        }
857 481c3fb9 djkim
                    }
858
                    else
859
                    {
860 9d5b4bc2 taeseongkim
                        sliderPages.Value = 1;
861 481c3fb9 djkim
                        this.printIndy.IsBusy = false;
862
                        return;
863
                    }
864 86bff326 taeseongkim
865
                    await this.Dispatcher.InvokeAsync(() =>
866 481c3fb9 djkim
                    {
867 9d5b4bc2 taeseongkim
                        sliderPages.Value = 1;
868 481c3fb9 djkim
                        printIndy.IsBusy = false;
869 86bff326 taeseongkim
                    });
870
871 77cdac33 taeseongkim
                    await PageChangeAsync(token,_StartPageNo, false);
872 787a4489 KangIngu
873 ca49aa5b taeseongkim
                    IsExportOrPrint = false;
874
875 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
876
                }else
877
                {
878
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
879
                    {
880 9d5b4bc2 taeseongkim
                        sliderPages.Value = 1;
881 481c3fb9 djkim
                        printIndy.IsBusy = false;
882
                    }));
883 787a4489 KangIngu
884 ca49aa5b taeseongkim
                    //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
885 481c3fb9 djkim
                }                
886
            }
887
            catch (Exception ex)
888 787a4489 KangIngu
            {
889 9d5b4bc2 taeseongkim
                sliderPages.Value = 1;
890 86bff326 taeseongkim
                printIndy.IsBusy = false;
891
892 664ea2e1 taeseongkim
                //Logger.sendResLog("Export Method", ex.Message, 0);
893 481c3fb9 djkim
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
894
            }
895 00143658 taeseongkim
            finally
896
            {
897 77cdac33 taeseongkim
                GC.Collect();
898
                GC.WaitForPendingFinalizers();
899
                GC.Collect();
900 e6c46927 taeseongkim
                IsStop = false;
901 77cdac33 taeseongkim
                (this.Parent as RadWindow).CanClose = true;
902
            }
903 787a4489 KangIngu
        }
904 77cdac33 taeseongkim
905 787a4489 KangIngu
        #endregion
906
907
        #region Method - 처리
908
        void CheckCommentPages()
909
        {
910
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
911
            DoubleCollection _Ticks = new DoubleCollection();
912
913
914
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
915
            {
916
917
                _pages = (from commPage in this._PageMarkupList
918
                          where commPage.PageNumber == CurrentPageNo
919
                          orderby commPage.PageNumber
920
                          select commPage).ToList();
921
            }
922
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
923
            {
924
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
925
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
926
927
                int _stPage = (int)stPageNo.Value;
928
                int _edPage = (int)edPageNo.Value;
929
930
                _pages = (from commPage in this._PageMarkupList
931
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
932
                          orderby commPage.PageNumber
933
                          select commPage).ToList();
934
            }
935
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
936
            {
937
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
938
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
939
940
                int _stPage = (int)stPageNo.Value;
941
                int _edPage = (int)edPageNo.Value;
942
943
                //Using DeepView.Common.RangeParser
944
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
945
                _pages = (from commPage in this._PageMarkupList
946
                          from compareData in lst
947
                          where commPage.PageNumber == compareData
948
                          orderby commPage.PageNumber
949
                          select commPage).ToList();
950
            }
951
            else
952
            {
953
                _pages = (from commPage in this._PageMarkupList
954
                          orderby commPage.PageNumber
955
                          select commPage).ToList();
956
            }
957 2b1f30fe taeseongkim
958 787a4489 KangIngu
            CommentPageList.ItemsSource = _pages.ToList();
959
        }
960
961
        void SetLoadMakupList(int PageNo)
962
        {
963
            _LoadMakupList.Clear();
964
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
965
966
            if (_markupList.Count() > 0)
967
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
968
        }
969
970
        #region 프린트 리스트 가져오기
971
        public void GetPrint(bool flag)
972
        {
973
            if (flag)
974
            {
975
                foreach (string printer in PrinterSettings.InstalledPrinters)
976
                {
977
                    this.cbPrint.Items.Add(printer);
978
                }
979
                printDocument = new PrintDocument();
980
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
981
            }
982
            else
983
            {
984
                this.cbPrint.Items.Add("PDF");
985
                this.cbPrint.Items.Add("IMAGE");
986
987
                this.cbPrint.SelectedItem = "PDF";
988
            }
989
        }
990
        #endregion
991
992
        #region 프린트 실행
993 86bff326 taeseongkim
        public async void Printing()
994 787a4489 KangIngu
        {
995 d2050059 taeseongkim
            var token = Common.ViewerDataModel.Instance.NewPagImageCancelToken ();
996 24c5e56c taeseongkim
997 77cdac33 taeseongkim
            await PageChangeAsync(token,1, false);
998 86bff326 taeseongkim
999 787a4489 KangIngu
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
1000
            {
1001 481c3fb9 djkim
                printDocument = new PrintDocument();
1002 408e4218 ljiyeon
                printDocument.OriginAtMargins = true;
1003 787a4489 KangIngu
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
1004
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
1005
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
1006
            }
1007
            else
1008
                printDocument = null;
1009
1010
            #region 인쇄 미리보기 테스트
1011
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
1012
            {
1013
                printDocument.PrinterSettings.MinimumPage = 1;
1014
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
1015
                printDocument.PrinterSettings.FromPage = 1;
1016 408e4218 ljiyeon
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
1017 787a4489 KangIngu
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
1018 481c3fb9 djkim
                printDocument.PrinterSettings.PrinterName = PrintName;
1019
                dlg.Document = printDocument;
1020 787a4489 KangIngu
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
1021
                dlg.ShowDialog();
1022
            }
1023
            #endregion
1024
1025
            #region 인쇄
1026
            //printDocument.PrinterSettings.MinimumPage = 1;
1027
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
1028
            //printDocument.PrinterSettings.FromPage = 1;
1029
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
1030
1031
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
1032
            //printDocument.PrinterSettings.PrinterName = PrintName;
1033
1034
            //printDocument.Print();
1035
            #endregion
1036
        }
1037
1038
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
1039
        {
1040
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
1041
            // This demo only loads one page at a time, so no need to re-set the print page number
1042 481c3fb9 djkim
            PrintDocument document = sender as PrintDocument;
1043 787a4489 KangIngu
            currentPage = document.PrinterSettings.FromPage;
1044
        }
1045 481c3fb9 djkim
1046 787a4489 KangIngu
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
1047
        {
1048
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
1049
1050
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
1051
            {
1052 77cdac33 taeseongkim
                //p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
1053
                p_img = System.Drawing.Image.FromFile(PrintimgPath_List.Where(data => data.Key == currentPage).FirstOrDefault().Value);
1054 2024d8d1 ljiyeon
1055 481c3fb9 djkim
                if (p_img.Width > p_img.Height)
1056 2024d8d1 ljiyeon
                {
1057
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
1058
                }
1059 408e4218 ljiyeon
1060
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
1061
                System.Drawing.Image pic = p_img;
1062 787a4489 KangIngu
                System.Drawing.Rectangle m = e.MarginBounds;
1063
1064 408e4218 ljiyeon
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
1065
                //{
1066
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
1067
                //}
1068
                //else
1069
                //{
1070
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
1071
                //}
1072
                m.Width = (int)e.PageSettings.PrintableArea.Width;
1073
                m.Height = (int)e.PageSettings.PrintableArea.Height;
1074
                m.X = (int)e.PageSettings.HardMarginX;
1075
                m.Y = (int)e.PageSettings.HardMarginY;
1076
1077
                e.Graphics.DrawImage(pic, m);
1078 787a4489 KangIngu
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
1079
                //e.Graphics.DrawImage(p_img, 0, 0);
1080
            }));
1081 481c3fb9 djkim
1082 787a4489 KangIngu
            //다음 페이지
1083
            currentPage++;
1084 481c3fb9 djkim
1085 787a4489 KangIngu
            ////인쇄를 계속 할지 말지 확인
1086 e6c46927 taeseongkim
            if (currentPage <= printDocument.PrinterSettings.ToPage && !IsStop)
1087 787a4489 KangIngu
                e.HasMorePages = true;
1088
            else
1089
                e.HasMorePages = false;
1090
1091
        }
1092
1093
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
1094
        {
1095
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
1096
            {
1097 43e1d368 taeseongkim
                //if (Directory.Exists(TempImageDir))
1098
                //    Directory.Delete(TempImageDir, true);
1099 77cdac33 taeseongkim
1100 9d5b4bc2 taeseongkim
                sliderPages.Value = 1;
1101 787a4489 KangIngu
                printIndy.IsBusy = false;
1102 e6c46927 taeseongkim
                IsStop = false;
1103 787a4489 KangIngu
            }));
1104
        }
1105
        #endregion
1106
1107
        #region Selected Pages Check
1108
        List<int> PrintPageCreate()
1109
        {
1110
            List<int> Result = new List<int>();
1111
1112
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
1113
            {
1114
                Result.Add(CurrentPageNo);
1115
            }
1116
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
1117
            {
1118
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
1119
                {
1120
                    Result.Add(i);
1121
                }
1122
            }
1123
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
1124
            {
1125
                int _stPage = (int)stPageNo.Value;
1126
                int _edPage = (int)edPageNo.Value;
1127
1128
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
1129
                Result.AddRange(lst);
1130
            }
1131
            else
1132
            {
1133
                for (int i = 1; i <= _definePages.PagesCount; i++)
1134
                {
1135
                    Result.Add(i);
1136
                }
1137
            }
1138
            if (currentPagePrint)
1139
            {
1140
                return Result;
1141
            }
1142
1143
            if (chkOnlyMarkup.IsChecked.Value)
1144
            {
1145
                var _result = from result in Result
1146
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
1147
                              select result;
1148
                Result = _result.ToList();
1149
            }
1150
            return Result;
1151
        }
1152
        #endregion
1153
1154
        #endregion
1155 e6c46927 taeseongkim
1156
        private void btPrintCancel_click(object sender, RoutedEventArgs e)
1157
        {
1158
            IsStop = true;
1159
        }
1160 787a4489 KangIngu
    }
1161
}
클립보드 이미지 추가 (최대 크기: 500 MB)