프로젝트

일반

사용자정보

개정판 86bff326

ID86bff326fb25f02d809b59ae6219c9eeb230e0c9
상위 285635d3
하위 1e901a8d

김태성이(가) 약 5년 전에 추가함

- pdf export 수정

Change-Id: I44d70e1a8adce8d9b1dcaa92958594d1780fa02f

차이점 보기:

KCOM/Controls/PrintControl.xaml.cs
22 22
using iTextSharp.text.pdf;
23 23
using Microsoft.Office.Core;
24 24
using System.Net;
25
using Image = System.Windows.Controls.Image;
25 26

  
26 27
namespace KCOM.Control
27 28
{
28 29
    public class DefinedPages
29 30
    {
31
        public DOCINFO DocumentInfo { get; set; }
32

  
30 33
        public int PagesCount { get; set; }
31 34
        public string vpSlip { get; set; }
32 35
        public string vpTitle { get; set; }
33 36
        public string fileUrl { get; set; }
34 37
        public ImageBrush Back_Image { get; set; }
35 38

  
39
        public double CurrentValue { get; set; }
40

  
36 41
        string _DefinedPagesStrings;
37 42
        /// <summary>
38 43
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
......
221 226
                chkOnlyMarkup.IsChecked = false;
222 227

  
223 228
            this.CurrentPageNo = _StartPageNo;
224
            _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
229

  
230
            _definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo
231
                            , PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
232

  
225 233
            DocumentInfo = _definePages;
226 234
            this.DataContext = _definePages;
227 235

  
......
232 240
            {
233 241
                gridViewMarkup.SelectedItems.Add(item);
234 242
            }
235
            PageChanged(_StartPageNo);
236 243

  
244
            PageChangeAsync(_StartPageNo).ConfigureAwait(true);
237 245

  
238 246
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
239 247
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
......
265 273
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
266 274
        {
267 275
            timm.Enabled = false;
268
            PageChanged(_StartPageNo);
276
            PageChangeAsync(_StartPageNo);
269 277
        }
270 278
        #endregion
271 279

  
272 280
        #region Control Event
273
        private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
281
        private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
274 282
        {
275 283
            if (_initializeComponentFinished)
276 284
            {
277 285
                if (!_IsDagSlider)
278 286
                {
279 287
                    this.CurrentPageNo = (int)this.sliderPages.Value;
280
                    PageChanged(this.CurrentPageNo);
288

  
289
                    await PageChangeAsync(this.CurrentPageNo);
281 290

  
282 291
                    if (_ButtonName == "Current")
283 292
                    {
......
290 299
            }
291 300
        }
292 301

  
293
        private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
302
        private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
294 303
        {
295 304
            _IsDagSlider = false;
296 305
            this.CurrentPageNo = (int)this.sliderPages.Value;
297 306
            if (_initializeComponentFinished)
298 307
            {
299
                PageChanged(this.CurrentPageNo);
308
                await PageChangeAsync(this.CurrentPageNo);
300 309
            }
301 310
        }
302 311

  
......
394 403
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
395 404
        }
396 405

  
397
        private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
406
        private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
398 407
        {
399 408
            if (_initializeComponentFinished)
400 409
            {
401
                PageChanged(this.CurrentPageNo);
410
                await PageChangeAsync(this.CurrentPageNo);
402 411
            }
403 412
        }
404 413

  
405 414
        #endregion
406 415

  
407
        public void PageChanged(int PageNo, bool Flag = false)
416
        public async System.Threading.Tasks.Task<bool> PageChangeAsync(int PageNo, bool Flag = false)
408 417
        {
409
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
418
            bool result = false;
419
            //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
420
            //{
421
            try
410 422
            {
411
                try
423
                Load load = new Load();
424

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

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

  
430
                if(pages.Count() > 0)
412 431
                {
413
                    Load load = new Load();
432
                    var currentPage = pages.First();
414 433

  
415
                    _definePages.Back_Image = new ImageBrush();
416
                    //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
417
                    var buffer = new WebClient().DownloadData(_DefaultTileUri + PageNo + ".png");
418
                    var bitmap = new BitmapImage();
419
                    using (var stream = new MemoryStream(buffer))
420
                    {
421
                        bitmap.BeginInit();
422
                        bitmap.CacheOption = BitmapCacheOption.OnLoad;
423
                        bitmap.StreamSource = stream;
424
                        bitmap.EndInit();
434
                    //var buffer = await new WebClient().DownloadDataTaskAsync(_DefaultTileUri + PageNo + ".png");
435

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

  
426 444
                        printCanvas.Children.Clear();
445
                        var bitmapframe = await  App.PageStorage.GetPageAsync(PageNo);
446
                        Image bitmap = new Image();
427 447

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

  
431
                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
432
                        printCanvas.Width = image.Width;
433
                        printCanvas.Height = image.Height;
455
                        printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
456
                        printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
434 457

  
435 458
                        foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
436 459
                        {
......
439 462
                            load.Page_No = PageNo;
440 463
                            load.DisplayColor = info.DisplayColor;
441 464
                            load.Markupinfoid = info.MarkupInfoID;
442
                            load.Markup_Load(printCanvas);
465
                            await load.Markup_LoadAsync(printCanvas);
443 466
                        }
444 467

  
445 468
                        printCanvas.UpdateLayout();
446 469

  
447 470
                        if (Flag)
448 471
                        {
449

  
450 472
                            //MemoryStream ms = new MemoryStream();
451 473
                            //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
452 474
                            //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
453 475
                            //bbe.Save(ms);
454 476

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

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

  
493
            return result;
494
            //}));
469 495
        }
470 496
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
471 497
        {
......
478 504
        }
479 505
        //Print 버튼 클릭 이벤트
480 506
        #region Method - 명령
481
        void PrintMethod(object sender, RoutedEventArgs e)
507
        async void PrintMethod(object sender, RoutedEventArgs e)
482 508
        {
483 509
            try
484 510
            {
485 511
                if (this.printIndy.IsBusy == true)
486 512
                    return;
487 513

  
488
                System.Threading.Tasks.Task.Factory.StartNew(() =>
489
                {
490
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
491
                    {
514
                await this.Dispatcher.InvokeAsync(() => { 
492 515
                        this.printIndy.IsBusy = true;
493 516
                        printIndy.BusyContent = "Printing. . .";
494
                    }));
495 517
                });
496 518

  
497 519

  
......
509 531
                    this.printIndy.IsBusy = false;
510 532
                    return;
511 533
                }
534

  
512 535
                int cnt = 0;
513
                List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
514 536

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

  
......
518 540
                {
519 541
                    cnt++;
520 542
                    sliderPages.Value = PageNo;
521
                    PageChanged(PageNo, true);
543
                    await PageChangeAsync(PageNo, true);
522 544
                    //PageChanged(cnt, true);
523 545
                }
524 546
                PrintName = cbPrint.SelectedItem.ToString();
525 547

  
526
                System.Threading.Tasks.Task.Factory.StartNew(() =>
527
                {
548
                await this.Dispatcher.InvokeAsync(() => {
528 549
                    if (cnt == _lstPrintPageNo.Count)
529 550
                    {
530 551
                        Printing();
......
539 560
        }
540 561

  
541 562
        //Export 버튼 클릭 이벤트
542
        void ExportMethod(object sender, RoutedEventArgs e)
563
        async void ExportMethod(object sender, RoutedEventArgs e)
543 564
        {
544 565
            try
545 566
            {
......
589 610
                    foreach (int PageNo in _lstPrintPageNo)
590 611
                    {
591 612
                        sliderPages.Value = PageNo;
592
                        PageChanged(PageNo, true);
613
                        await PageChangeAsync(PageNo, true);
593 614
                    }
594 615

  
595 616
                    //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
......
667 688
                        this.printIndy.IsBusy = false;
668 689
                        return;
669 690
                    }
670
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
691

  
692
                    await this.Dispatcher.InvokeAsync(() =>
671 693
                    {
672 694
                        printIndy.IsBusy = false;
673
                    }));
674
                    PageChanged(_StartPageNo);
695
                    });
696

  
697
                    await PageChangeAsync(_StartPageNo);
675 698

  
676 699
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
677 700
                }else
......
686 709
            }
687 710
            catch (Exception ex)
688 711
            {
712
                printIndy.IsBusy = false;
713

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

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

  
784 810
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
785 811
            {
786 812
                printDocument = new PrintDocument();

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)