개정판 77cdac33
벽산 수정 후 백업
Change-Id: I8e3eb48f615478a49efa0ab4014a8ef17d273d0a
KCOM/Controls/PrintControl.xaml.cs | ||
---|---|---|
138 | 138 |
System.Drawing.Image p_img; //프린트 이미지 |
139 | 139 |
iTextSharp.text.Image Export_img; |
140 | 140 |
Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지 |
141 |
Dictionary<int, string> PrintimgPath_List; //프린트 이미지 파일 경로 |
|
142 |
string TempImageDir = null; |
|
141 | 143 |
|
142 | 144 |
//RasterCodecs codecs; |
143 | 145 |
int currentPage; |
... | ... | |
242 | 244 |
gridViewMarkup.SelectedItems.Add(item); |
243 | 245 |
} |
244 | 246 |
|
245 |
PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), _StartPageNo).ConfigureAwait(true); |
|
247 |
PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), _StartPageNo,false).ConfigureAwait(true);
|
|
246 | 248 |
|
247 | 249 |
sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
248 | 250 |
this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
... | ... | |
284 | 286 |
|
285 | 287 |
if (!IsExportOrPrint) |
286 | 288 |
{ |
287 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), this.CurrentPageNo); |
|
289 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), this.CurrentPageNo, false);
|
|
288 | 290 |
} |
289 | 291 |
//await App.PageStorage.GetPageUriAsync(this.CurrentPageNo); |
290 | 292 |
|
... | ... | |
407 | 409 |
{ |
408 | 410 |
if (_initializeComponentFinished) |
409 | 411 |
{ |
410 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(),this.CurrentPageNo); |
|
412 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(),this.CurrentPageNo, false);
|
|
411 | 413 |
} |
412 | 414 |
} |
413 | 415 |
|
414 | 416 |
#endregion |
415 | 417 |
|
416 |
public async System.Threading.Tasks.Task<bool> PageChangeAsync(System.Threading.CancellationToken cts, int PageNo, bool Flag = false) |
|
418 |
public async System.Threading.Tasks.Task<bool> PageChangeAsync(System.Threading.CancellationToken cts, int PageNo,bool saveFile, bool Flag = false)
|
|
417 | 419 |
{ |
418 | 420 |
System.Diagnostics.Debug.WriteLine("PageChangeAsync " + PageNo); |
419 | 421 |
bool result = false; |
... | ... | |
498 | 500 |
await Dispatcher.InvokeAsync(() => |
499 | 501 |
{ |
500 | 502 |
Export export = new Export(); |
501 |
p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height); |
|
502 |
Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
|
503 |
|
|
504 |
if (saveFile) |
|
505 |
{ |
|
506 |
var filepath = Path.Combine(TempImageDir, $"{PrintimgPath_List.Count() + 1}.png"); |
|
507 |
|
|
508 |
if (export.ExportingFile(PrintView, printCanvas.Width, printCanvas.Height, filepath)) |
|
509 |
{ |
|
510 |
PrintimgPath_List.Add(PrintimgPath_List.Count() + 1, filepath); |
|
511 |
} |
|
512 |
else |
|
513 |
{ |
|
514 |
throw new Exception($"Export Image Save File Error :{filepath}"); |
|
515 |
} |
|
516 |
} |
|
517 |
else |
|
518 |
{ |
|
519 |
p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height); |
|
520 |
Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
|
521 |
} |
|
522 |
|
|
503 | 523 |
},System.Windows.Threading.DispatcherPriority.SystemIdle); |
504 | 524 |
//}); |
505 | 525 |
} |
... | ... | |
567 | 587 |
IsExportOrPrint = true; |
568 | 588 |
|
569 | 589 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
590 |
PrintimgPath_List = new Dictionary<int, string>(); |
|
591 |
TempImageDir = Path.Combine(Path.GetTempPath(), "Markus", Common.Commons.shortGuid()); |
|
592 |
|
|
593 |
if (Directory.Exists(TempImageDir)) |
|
594 |
{ |
|
595 |
Directory.Delete(TempImageDir, true); |
|
596 |
} |
|
597 |
|
|
598 |
Directory.CreateDirectory(TempImageDir); |
|
570 | 599 |
|
571 | 600 |
foreach (int PageNo in _lstPrintPageNo) |
572 | 601 |
{ |
573 | 602 |
cnt++; |
574 | 603 |
sliderPages.Value = PageNo; |
575 |
await PageChangeAsync(token,PageNo, true); |
|
604 |
await PageChangeAsync(token,PageNo, true, true);
|
|
576 | 605 |
//PageChanged(cnt, true); |
577 | 606 |
} |
578 | 607 |
PrintName = cbPrint.SelectedItem.ToString(); |
... | ... | |
640 | 669 |
} |
641 | 670 |
case (1): |
642 | 671 |
{ |
643 |
SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
|
|
672 |
SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg"; |
|
644 | 673 |
break; |
645 | 674 |
} |
646 | 675 |
} |
... | ... | |
649 | 678 |
if(SaveDig.ShowDialog().Value) |
650 | 679 |
{ |
651 | 680 |
IsExportOrPrint = true; |
652 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
|
681 |
|
|
682 |
PrintimgPath_List = new Dictionary<int, string>(); |
|
683 |
TempImageDir = Path.Combine(Path.GetTempPath(), "Markus", Common.Commons.shortGuid()); |
|
684 |
|
|
685 |
if (Directory.Exists(TempImageDir)) |
|
686 |
{ |
|
687 |
Directory.Delete(TempImageDir, true); |
|
688 |
} |
|
689 |
|
|
690 |
Directory.CreateDirectory(TempImageDir); |
|
653 | 691 |
|
654 | 692 |
foreach (int PageNo in _lstPrintPageNo) |
655 | 693 |
{ |
... | ... | |
658 | 696 |
sliderPages.Value = PageNo; |
659 | 697 |
}); |
660 | 698 |
|
661 |
await PageChangeAsync(token, PageNo, true); |
|
699 |
await PageChangeAsync(token, PageNo, true, true);
|
|
662 | 700 |
|
663 | 701 |
System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo); |
664 | 702 |
} |
... | ... | |
671 | 709 |
{ |
672 | 710 |
case (0): |
673 | 711 |
{ |
674 |
using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
|
|
712 |
using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create)) |
|
675 | 713 |
{ |
676 | 714 |
using (Document doc = new Document()) |
677 | 715 |
{ |
678 |
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) |
|
679 |
{ |
|
680 |
doc.Open(); |
|
681 |
|
|
682 |
float height = doc.PageSize.Height; |
|
683 |
float width = doc.PageSize.Width; |
|
716 |
PdfWriter writer = PdfWriter.GetInstance(doc, fs); |
|
684 | 717 |
|
685 |
foreach (var item in Printimg_List) |
|
686 |
{ |
|
687 |
Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png); |
|
718 |
doc.Open(); |
|
688 | 719 |
|
689 |
if (Export_img.Width > Export_img.Height) |
|
690 |
{ |
|
691 |
doc.SetPageSize(new Rectangle(height, width)); |
|
692 |
Export_img.ScaleToFit(height, width); |
|
693 |
} |
|
694 |
else |
|
695 |
{ |
|
696 |
doc.SetPageSize(new Rectangle(width, height)); |
|
697 |
Export_img.ScaleToFit(width, height); |
|
698 |
} |
|
720 |
float height = doc.PageSize.Height; |
|
721 |
float width = doc.PageSize.Width; |
|
699 | 722 |
|
700 |
Export_img.SetAbsolutePosition(0, 0); |
|
723 |
foreach (var item in PrintimgPath_List) |
|
724 |
{ |
|
725 |
System.Drawing.Image image = System.Drawing.Image.FromFile(item.Value); |
|
726 |
Export_img = iTextSharp.text.Image.GetInstance(image,System.Drawing.Imaging.ImageFormat.Jpeg); |
|
701 | 727 |
|
702 |
doc.NewPage(); |
|
703 |
doc.Add(Export_img); |
|
728 |
if (Export_img.Width > Export_img.Height) |
|
729 |
{ |
|
730 |
doc.SetPageSize(new Rectangle(height, width)); |
|
731 |
Export_img.ScaleToFit(height, width); |
|
732 |
} |
|
733 |
else |
|
734 |
{ |
|
735 |
doc.SetPageSize(new Rectangle(width, height)); |
|
736 |
Export_img.ScaleToFit(width, height); |
|
737 |
} |
|
704 | 738 |
|
705 |
await System.Threading.Tasks.Task.Delay(100);
|
|
739 |
Export_img.SetAbsolutePosition(0, 0);
|
|
706 | 740 |
|
707 |
}
|
|
708 |
doc.Close();
|
|
741 |
doc.NewPage();
|
|
742 |
doc.Add(Export_img);
|
|
709 | 743 |
} |
710 | 744 |
} |
711 | 745 |
} |
... | ... | |
713 | 747 |
} |
714 | 748 |
case (1): |
715 | 749 |
{ |
716 |
foreach (var item in Printimg_List) |
|
750 |
foreach (var item in PrintimgPath_List)
|
|
717 | 751 |
{ |
718 |
switch (SaveDig.FilterIndex) |
|
719 |
{ |
|
720 |
case (1): |
|
721 |
{ |
|
722 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg); |
|
723 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); |
|
724 |
} |
|
725 |
break; |
|
726 |
case (2): |
|
727 |
{ |
|
728 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png); |
|
729 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png); |
|
730 |
} |
|
731 |
break; |
|
732 |
} |
|
752 |
File.Copy(item.Value, SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg"); |
|
733 | 753 |
} |
734 | 754 |
break; |
735 | 755 |
} |
... | ... | |
748 | 768 |
printIndy.IsBusy = false; |
749 | 769 |
}); |
750 | 770 |
|
751 |
await PageChangeAsync(token,_StartPageNo); |
|
771 |
await PageChangeAsync(token,_StartPageNo, false);
|
|
752 | 772 |
|
753 | 773 |
IsExportOrPrint = false; |
754 | 774 |
|
... | ... | |
774 | 794 |
} |
775 | 795 |
finally |
776 | 796 |
{ |
777 |
(this.Parent as RadWindow).CanClose = true;
|
|
778 |
}
|
|
797 |
if(Directory.Exists(TempImageDir))
|
|
798 |
Directory.Delete(TempImageDir, true);
|
|
779 | 799 |
|
800 |
GC.Collect(); |
|
801 |
GC.WaitForPendingFinalizers(); |
|
802 |
GC.Collect(); |
|
780 | 803 |
|
804 |
(this.Parent as RadWindow).CanClose = true; |
|
805 |
} |
|
781 | 806 |
} |
807 |
|
|
782 | 808 |
#endregion |
783 | 809 |
|
784 | 810 |
#region Method - 처리 |
... | ... | |
870 | 896 |
{ |
871 | 897 |
var token = Common.ViewerDataModel.Instance.NewCancellationToken(); |
872 | 898 |
|
873 |
await PageChangeAsync(token,1); |
|
899 |
await PageChangeAsync(token,1, false);
|
|
874 | 900 |
|
875 | 901 |
if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
876 | 902 |
{ |
... | ... | |
925 | 951 |
|
926 | 952 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
927 | 953 |
{ |
928 |
p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
|
954 |
//p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
|
955 |
p_img = System.Drawing.Image.FromFile(PrintimgPath_List.Where(data => data.Key == currentPage).FirstOrDefault().Value); |
|
929 | 956 |
|
930 | 957 |
if (p_img.Width > p_img.Height) |
931 | 958 |
{ |
... | ... | |
969 | 996 |
{ |
970 | 997 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
971 | 998 |
{ |
999 |
if (Directory.Exists(TempImageDir)) |
|
1000 |
Directory.Delete(TempImageDir, true); |
|
1001 |
|
|
972 | 1002 |
sliderPages.Value = 1; |
973 | 1003 |
printIndy.IsBusy = false; |
1004 |
|
|
974 | 1005 |
})); |
975 | 1006 |
} |
976 | 1007 |
#endregion |
내보내기 Unified diff