markus / KCOM / Controls / PrintControl.xaml.cs @ 77cdac33
이력 | 보기 | 이력해설 | 다운로드 (40.7 KB)
1 |
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 |
using Microsoft.Office.Core; |
23 |
using System.Net; |
24 |
using Image = System.Windows.Controls.Image; |
25 |
|
26 |
namespace KCOM.Control |
27 |
{ |
28 |
public class DefinedPages |
29 |
{ |
30 |
public DOCINFO DocumentInfo { get; set; } |
31 |
|
32 |
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 |
public double CurrentValue { get; set; } |
39 |
|
40 |
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 |
bool IsExportOrPrint = false; |
127 |
|
128 |
List<DisplayColorInfo> colorList = new List<DisplayColorInfo>(); |
129 |
DefinedPages DocumentInfo { get; set; } //문서정보 정의 |
130 |
//PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 |
131 |
delegate void PrintEventHandler(); //프린트 핸들러 |
132 |
SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그 |
133 |
//SaveFileDialog SaveFile { get; set; } //저장할 때 사용 |
134 |
|
135 |
//RasterImageViewer _viewer; //이미지 뷰어 |
136 |
//System.Windows.Controls.Image backimg; //백그라운드 이미지 |
137 |
System.Drawing.Image Printimg; //프린트 이미지 |
138 |
System.Drawing.Image p_img; //프린트 이미지 |
139 |
iTextSharp.text.Image Export_img; |
140 |
Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지 |
141 |
Dictionary<int, string> PrintimgPath_List; //프린트 이미지 파일 경로 |
142 |
string TempImageDir = null; |
143 |
|
144 |
//RasterCodecs codecs; |
145 |
int currentPage; |
146 |
public string PrintName; |
147 |
public string Type; |
148 |
|
149 |
public System.Timers.Timer timm = new System.Timers.Timer(); |
150 |
|
151 |
|
152 |
#endregion |
153 |
|
154 |
#region Static Property Defines |
155 |
public static readonly DependencyProperty CurrentPageNoProperty = |
156 |
DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
157 |
new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
158 |
#endregion |
159 |
|
160 |
#region Property |
161 |
public int CurrentPageNo |
162 |
{ |
163 |
get { return (int)GetValue(CurrentPageNoProperty); } |
164 |
set { SetValue(CurrentPageNoProperty, value); } |
165 |
} |
166 |
#endregion |
167 |
|
168 |
#region PropertyChangeMethod |
169 |
private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
170 |
{ |
171 |
var printPage = (PrintControl)d; |
172 |
var newValue = (int)e.NewValue; |
173 |
|
174 |
printPage.sliderPages.Value = newValue; |
175 |
printPage.SetLoadMakupList(newValue); |
176 |
|
177 |
} |
178 |
#endregion |
179 |
|
180 |
#region 생성자 |
181 |
|
182 |
public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
183 |
{ |
184 |
InitializeComponent(); |
185 |
|
186 |
this.IsEnabled = true; |
187 |
|
188 |
//Layer Control을 통째로 가져와야 하는건가 |
189 |
this._DocInfo = DocInfo; |
190 |
this._DefaultTileUri = TileSourceUri; |
191 |
this.ProjectNo = ProjectNo; |
192 |
this._StartPageNo = CurrentPageNo; |
193 |
|
194 |
markupInfo.ForEach(info => this._markupInfo.Add(info)); |
195 |
|
196 |
foreach (var info in _markupInfo) |
197 |
{ |
198 |
if (info.Consolidate == 1) |
199 |
{ |
200 |
info.UserName = "Consolidation"; |
201 |
} |
202 |
info.MarkupList.ForEach(makup => |
203 |
{ |
204 |
var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber); |
205 |
var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor }; |
206 |
|
207 |
if (_pageMarkup.Count() > 0) |
208 |
_pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem); |
209 |
else |
210 |
_PageMarkupList.Add(new MarkupPageItem |
211 |
{ |
212 |
PageNumber = makup.PageNumber, |
213 |
DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem } |
214 |
}); |
215 |
}); |
216 |
|
217 |
colorList.Add(new DisplayColorInfo |
218 |
{ |
219 |
UserID = info.UserID, |
220 |
DisplayColor = info.DisplayColor, |
221 |
Department = info.Depatment, |
222 |
UserName = info.UserName, |
223 |
}); |
224 |
} |
225 |
|
226 |
gridViewMarkup.ItemsSource = this._markupInfo; |
227 |
SetLoadMakupList(this._StartPageNo); |
228 |
if (_LoadMakupList.Count() == 0) |
229 |
chkOnlyMarkup.IsChecked = false; |
230 |
|
231 |
this.CurrentPageNo = _StartPageNo; |
232 |
|
233 |
_definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo |
234 |
, PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl }; |
235 |
|
236 |
DocumentInfo = _definePages; |
237 |
this.DataContext = _definePages; |
238 |
|
239 |
CheckCommentPages(); |
240 |
|
241 |
//초기화면 Comment Check된 상태로 보여주기 |
242 |
foreach (var item in _markupInfo) |
243 |
{ |
244 |
gridViewMarkup.SelectedItems.Add(item); |
245 |
} |
246 |
|
247 |
PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), _StartPageNo,false).ConfigureAwait(true); |
248 |
|
249 |
sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
250 |
this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
251 |
this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
252 |
this.IsPrint = isPrint; |
253 |
|
254 |
if (!IsPrint) |
255 |
{ |
256 |
GetPrint(false); |
257 |
btnWholeExport.Visibility = Visibility.Visible; |
258 |
btnWholePrint.Visibility = Visibility.Collapsed; |
259 |
Selected_Print.Header = "Export Type"; |
260 |
} |
261 |
else |
262 |
{ |
263 |
//PrintList 가져오기 |
264 |
GetPrint(true); |
265 |
btnWholePrint.Visibility = Visibility.Visible; |
266 |
btnWholeExport.Visibility = Visibility.Collapsed; |
267 |
} |
268 |
|
269 |
_initializeComponentFinished = true; |
270 |
|
271 |
//timm.Interval = 10; |
272 |
//timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed); |
273 |
//timm.Enabled = true; |
274 |
} |
275 |
|
276 |
#endregion |
277 |
|
278 |
#region Control Event |
279 |
private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
280 |
{ |
281 |
if (_initializeComponentFinished) |
282 |
{ |
283 |
if (!_IsDagSlider) |
284 |
{ |
285 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
286 |
|
287 |
if (!IsExportOrPrint) |
288 |
{ |
289 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(), this.CurrentPageNo, false); |
290 |
} |
291 |
//await App.PageStorage.GetPageUriAsync(this.CurrentPageNo); |
292 |
|
293 |
if (_ButtonName == "Current") |
294 |
{ |
295 |
stPageNo.Value = CurrentPageNo; |
296 |
edPageNo.Value = CurrentPageNo; |
297 |
} |
298 |
|
299 |
//CheckCommentPages(); |
300 |
} |
301 |
} |
302 |
} |
303 |
|
304 |
private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
305 |
{ |
306 |
_IsDagSlider = false; |
307 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
308 |
if (_initializeComponentFinished) |
309 |
{ |
310 |
|
311 |
} |
312 |
} |
313 |
|
314 |
private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e) |
315 |
{ |
316 |
_IsDagSlider = true; |
317 |
} |
318 |
|
319 |
private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e) |
320 |
{ |
321 |
if (_initializeComponentFinished) //GridRangePages |
322 |
{ |
323 |
CheckCommentPages(); |
324 |
} |
325 |
} |
326 |
string _ButtonName; |
327 |
private void PageSelect_Checked(object sender, RoutedEventArgs e) |
328 |
{ |
329 |
if (!_initializeComponentFinished) return; |
330 |
|
331 |
_ButtonName = (sender as RadRadioButton).Tag.ToString(); |
332 |
CommentPageList.ItemsSource = null; |
333 |
|
334 |
switch (_ButtonName) |
335 |
{ |
336 |
case "Current": |
337 |
stPageNo.Value = CurrentPageNo; |
338 |
edPageNo.Value = CurrentPageNo; |
339 |
|
340 |
GridCurrentPage.Visibility = Visibility.Visible; |
341 |
GridDefinePages.Visibility = Visibility.Collapsed; |
342 |
GridRangePages.Visibility = Visibility.Collapsed; |
343 |
GridAllPages.Visibility = Visibility.Collapsed; |
344 |
|
345 |
break; |
346 |
case "RangePrint": |
347 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
348 |
GridDefinePages.Visibility = Visibility.Visible; |
349 |
GridRangePages.Visibility = Visibility.Collapsed; |
350 |
GridAllPages.Visibility = Visibility.Collapsed; |
351 |
break; |
352 |
case "UserDefined": |
353 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
354 |
GridDefinePages.Visibility = Visibility.Collapsed; |
355 |
GridRangePages.Visibility = Visibility.Visible; |
356 |
GridAllPages.Visibility = Visibility.Collapsed; |
357 |
break; |
358 |
case "AllPrint": |
359 |
stPageNo.Value = 1; |
360 |
edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT); |
361 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
362 |
GridDefinePages.Visibility = Visibility.Collapsed; |
363 |
GridRangePages.Visibility = Visibility.Collapsed; |
364 |
GridAllPages.Visibility = Visibility.Visible; |
365 |
break; |
366 |
} |
367 |
|
368 |
CheckCommentPages(); |
369 |
} |
370 |
|
371 |
private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e) |
372 |
{ |
373 |
if (_initializeComponentFinished) //GridRangePages |
374 |
{ |
375 |
if (stPageNo.Value > edPageNo.Value) |
376 |
{ |
377 |
if (sender.Equals(stPageNo)) |
378 |
edPageNo.Value = stPageNo.Value; |
379 |
else |
380 |
stPageNo.Value = edPageNo.Value; |
381 |
} |
382 |
|
383 |
//뷰어잠시제외(강인구) |
384 |
//this.LayoutRoot.Dispatcher.BeginInvoke(delegate() |
385 |
//{ |
386 |
CheckCommentPages(); |
387 |
//}); |
388 |
} |
389 |
} |
390 |
|
391 |
private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e) |
392 |
{ |
393 |
CheckCommentPages(); |
394 |
} |
395 |
|
396 |
private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e) |
397 |
{ |
398 |
txtDefinedPages.Text = ""; |
399 |
} |
400 |
|
401 |
private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
402 |
{ |
403 |
if (_initializeComponentFinished) |
404 |
if (CommentPageList.SelectedItem != null) |
405 |
this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber; |
406 |
} |
407 |
|
408 |
private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
409 |
{ |
410 |
if (_initializeComponentFinished) |
411 |
{ |
412 |
await PageChangeAsync(Common.ViewerDataModel.Instance.NewCancellationToken(),this.CurrentPageNo, false); |
413 |
} |
414 |
} |
415 |
|
416 |
#endregion |
417 |
|
418 |
public async System.Threading.Tasks.Task<bool> PageChangeAsync(System.Threading.CancellationToken cts, int PageNo,bool saveFile, bool Flag = false) |
419 |
{ |
420 |
System.Diagnostics.Debug.WriteLine("PageChangeAsync " + PageNo); |
421 |
bool result = false; |
422 |
//Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
423 |
//{ |
424 |
try |
425 |
{ |
426 |
Load load = new Load(); |
427 |
|
428 |
_definePages.Back_Image = new ImageBrush(); |
429 |
//var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png")); |
430 |
|
431 |
var pages = _definePages.DocumentInfo.DOCPAGE.Where(x => x.PAGE_NUMBER == PageNo); |
432 |
|
433 |
if(pages.Count() > 0) |
434 |
{ |
435 |
var currentPage = pages.First(); |
436 |
|
437 |
//var buffer = await new WebClient().DownloadDataTaskAsync(_DefaultTileUri + PageNo + ".png"); |
438 |
|
439 |
//var bitmap = new BitmapImage(); |
440 |
//using (var stream = new MemoryStream(buffer)) |
441 |
//{ |
442 |
//bitmap.BeginInit(); |
443 |
//bitmap.CacheOption = BitmapCacheOption.OnLoad; |
444 |
//bitmap.StreamSource = stream; |
445 |
//bitmap.EndInit(); |
446 |
|
447 |
|
448 |
var uri = await App.PageStorage.GetPageUriAsync(cts, currentPage.PAGE_NUMBER); |
449 |
//Image bitmap = new Image(); |
450 |
//bitmap.Stretch = Stretch.Fill; |
451 |
//bitmap.Source = bitmapframe; |
452 |
//bitmap.Width = Convert.ToDouble(currentPage.PAGE_WIDTH); |
453 |
//bitmap.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT); |
454 |
|
455 |
if (uri.Scheme == Uri.UriSchemeFile) |
456 |
{ |
457 |
var cloneUri = new Uri(System.IO.Path.Combine(System.IO.Path.GetTempPath(),System.IO.Path.GetRandomFileName()),UriKind.Absolute); |
458 |
File.Copy(uri.LocalPath, cloneUri.LocalPath); |
459 |
|
460 |
uri = cloneUri; |
461 |
} |
462 |
|
463 |
printCanvas.Children.Clear(); |
464 |
printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH); |
465 |
printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT); |
466 |
|
467 |
printCanvas.Background = new ImageBrush{ ImageSource = new BitmapImage(uri)}; |
468 |
|
469 |
//printCanvas.RenderTransformOrigin = new Point(0.5, 0.5); |
470 |
//printCanvas.RenderTransform = new RotateTransform(currentPage.PAGE_ANGLE); |
471 |
//ImageBrush background = new ImageBrush(bitmap); |
472 |
//printCanvas.Background = background; |
473 |
//printCanvas.Background = new SolidColorBrush(Colors.Transparent); |
474 |
|
475 |
|
476 |
foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
477 |
{ |
478 |
load.User_Id = info.UserID; |
479 |
load.document_id = _DocInfo.DOCUMENT_ID; |
480 |
load.Page_No = PageNo; |
481 |
load.DisplayColor = info.DisplayColor; |
482 |
load.Markupinfoid = info.MarkupInfoID; |
483 |
var IsLoad = await load.Markup_LoadAsync(printCanvas, 0); |
484 |
} |
485 |
//await Dispatcher.InvokeAsync(() => { |
486 |
// printCanvas.UpdateLayout(); |
487 |
//}); |
488 |
|
489 |
if (Flag) |
490 |
{ |
491 |
//MemoryStream ms = new MemoryStream(); |
492 |
//BmpBitmapEncoder bbe = new BmpBitmapEncoder(); |
493 |
//bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png"))); |
494 |
//bbe.Save(ms); |
495 |
|
496 |
//System.Drawing.Image.FromFile() |
497 |
//Printimg = System.Drawing.Image.FromStream(stream); |
498 |
//await System.Threading.Tasks.Task.Run(() => |
499 |
//{ |
500 |
await Dispatcher.InvokeAsync(() => |
501 |
{ |
502 |
Export export = new Export(); |
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 |
|
523 |
},System.Windows.Threading.DispatcherPriority.SystemIdle); |
524 |
//}); |
525 |
} |
526 |
|
527 |
result = true; |
528 |
//} |
529 |
} |
530 |
} |
531 |
catch (Exception ex) |
532 |
{ |
533 |
//Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0); |
534 |
} |
535 |
|
536 |
return result; |
537 |
//})); |
538 |
} |
539 |
|
540 |
|
541 |
public static MemoryStream ByteBufferFromImage(BitmapImage imageSource) |
542 |
{ |
543 |
var ms = new MemoryStream(); |
544 |
var pngEncoder = new PngBitmapEncoder(); |
545 |
pngEncoder.Frames.Add(BitmapFrame.Create(imageSource)); |
546 |
pngEncoder.Save(ms); |
547 |
|
548 |
return ms; |
549 |
} |
550 |
//Print 버튼 클릭 이벤트 |
551 |
#region Method - 명령 |
552 |
async void PrintMethod(object sender, RoutedEventArgs e) |
553 |
{ |
554 |
try |
555 |
{ |
556 |
var token = Common.ViewerDataModel.Instance.NewCancellationToken(); |
557 |
|
558 |
if (this.printIndy.IsBusy == true) |
559 |
return; |
560 |
|
561 |
(this.Parent as RadWindow).CanClose = false; |
562 |
|
563 |
await this.Dispatcher.InvokeAsync(() => { |
564 |
this.printIndy.IsBusy = true; |
565 |
printIndy.BusyContent = "Printing. . ."; |
566 |
}); |
567 |
|
568 |
|
569 |
_lstPrintPageNo = PrintPageCreate(); |
570 |
|
571 |
if (_lstPrintPageNo.Count == 0) |
572 |
{ |
573 |
RadWindow.Alert(new DialogParameters |
574 |
{ |
575 |
Owner = Application.Current.MainWindow, |
576 |
Theme = new VisualStudio2013Theme(), |
577 |
Header = "Info", |
578 |
Content = "Not specified the page." |
579 |
}); |
580 |
sliderPages.Value = 1; |
581 |
this.printIndy.IsBusy = false; |
582 |
return; |
583 |
} |
584 |
|
585 |
int cnt = 0; |
586 |
|
587 |
IsExportOrPrint = true; |
588 |
|
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); |
599 |
|
600 |
foreach (int PageNo in _lstPrintPageNo) |
601 |
{ |
602 |
cnt++; |
603 |
sliderPages.Value = PageNo; |
604 |
await PageChangeAsync(token,PageNo, true, true); |
605 |
//PageChanged(cnt, true); |
606 |
} |
607 |
PrintName = cbPrint.SelectedItem.ToString(); |
608 |
|
609 |
await this.Dispatcher.InvokeAsync(() => { |
610 |
if (cnt == _lstPrintPageNo.Count) |
611 |
{ |
612 |
Printing(); |
613 |
} |
614 |
}); |
615 |
|
616 |
IsExportOrPrint = false; |
617 |
} |
618 |
catch (Exception ex) |
619 |
{ |
620 |
//Logger.sendResLog("PrintMethod", ex.Message, 0); |
621 |
} |
622 |
finally |
623 |
{ |
624 |
(this.Parent as RadWindow).CanClose = true; |
625 |
} |
626 |
|
627 |
} |
628 |
|
629 |
//Export 버튼 클릭 이벤트 |
630 |
async void ExportMethod(object sender, RoutedEventArgs e) |
631 |
{ |
632 |
try |
633 |
{ |
634 |
if (this.printIndy.IsBusy == true) |
635 |
return; |
636 |
|
637 |
var token = Common.ViewerDataModel.Instance.NewCancellationToken(); |
638 |
|
639 |
(this.Parent as RadWindow).CanClose = false; |
640 |
|
641 |
this.printIndy.IsBusy = true; |
642 |
printIndy.BusyContent = "Exporting. . ."; |
643 |
|
644 |
Export export = new Export(); |
645 |
_lstPrintPageNo = PrintPageCreate(); |
646 |
|
647 |
if (_lstPrintPageNo.Count == 0) |
648 |
{ |
649 |
sliderPages.Value = 1; |
650 |
this.printIndy.IsBusy = false; |
651 |
RadWindow.Alert(new DialogParameters |
652 |
{ |
653 |
Owner = Application.Current.MainWindow, |
654 |
Theme = new VisualStudio2013Theme(), |
655 |
Header = "Info", |
656 |
Content = "Not specified the page.", |
657 |
}); |
658 |
return; |
659 |
} |
660 |
|
661 |
//FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png"); |
662 |
|
663 |
switch (cbPrint.SelectedIndex) |
664 |
{ |
665 |
case (0): |
666 |
{ |
667 |
SaveDig.Filter = "PDF file format|*.pdf"; |
668 |
break; |
669 |
} |
670 |
case (1): |
671 |
{ |
672 |
SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg"; |
673 |
break; |
674 |
} |
675 |
} |
676 |
|
677 |
SaveDig.Title = "Save an PDF File"; |
678 |
if(SaveDig.ShowDialog().Value) |
679 |
{ |
680 |
IsExportOrPrint = true; |
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); |
691 |
|
692 |
foreach (int PageNo in _lstPrintPageNo) |
693 |
{ |
694 |
await Dispatcher.InvokeAsync(() => |
695 |
{ |
696 |
sliderPages.Value = PageNo; |
697 |
}); |
698 |
|
699 |
await PageChangeAsync(token, PageNo, true, true); |
700 |
|
701 |
System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo); |
702 |
} |
703 |
|
704 |
//using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
705 |
|
706 |
if (SaveDig.FileName != "") |
707 |
{ |
708 |
switch (cbPrint.SelectedIndex) |
709 |
{ |
710 |
case (0): |
711 |
{ |
712 |
using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create)) |
713 |
{ |
714 |
using (Document doc = new Document()) |
715 |
{ |
716 |
PdfWriter writer = PdfWriter.GetInstance(doc, fs); |
717 |
|
718 |
doc.Open(); |
719 |
|
720 |
float height = doc.PageSize.Height; |
721 |
float width = doc.PageSize.Width; |
722 |
|
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); |
727 |
|
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 |
} |
738 |
|
739 |
Export_img.SetAbsolutePosition(0, 0); |
740 |
|
741 |
doc.NewPage(); |
742 |
doc.Add(Export_img); |
743 |
} |
744 |
} |
745 |
} |
746 |
break; |
747 |
} |
748 |
case (1): |
749 |
{ |
750 |
foreach (var item in PrintimgPath_List) |
751 |
{ |
752 |
File.Copy(item.Value, SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg"); |
753 |
} |
754 |
break; |
755 |
} |
756 |
} |
757 |
} |
758 |
else |
759 |
{ |
760 |
sliderPages.Value = 1; |
761 |
this.printIndy.IsBusy = false; |
762 |
return; |
763 |
} |
764 |
|
765 |
await this.Dispatcher.InvokeAsync(() => |
766 |
{ |
767 |
sliderPages.Value = 1; |
768 |
printIndy.IsBusy = false; |
769 |
}); |
770 |
|
771 |
await PageChangeAsync(token,_StartPageNo, false); |
772 |
|
773 |
IsExportOrPrint = false; |
774 |
|
775 |
(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert"); |
776 |
}else |
777 |
{ |
778 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
779 |
{ |
780 |
sliderPages.Value = 1; |
781 |
printIndy.IsBusy = false; |
782 |
})); |
783 |
|
784 |
//(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert"); |
785 |
} |
786 |
} |
787 |
catch (Exception ex) |
788 |
{ |
789 |
sliderPages.Value = 1; |
790 |
printIndy.IsBusy = false; |
791 |
|
792 |
//Logger.sendResLog("Export Method", ex.Message, 0); |
793 |
//(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message); |
794 |
} |
795 |
finally |
796 |
{ |
797 |
if(Directory.Exists(TempImageDir)) |
798 |
Directory.Delete(TempImageDir, true); |
799 |
|
800 |
GC.Collect(); |
801 |
GC.WaitForPendingFinalizers(); |
802 |
GC.Collect(); |
803 |
|
804 |
(this.Parent as RadWindow).CanClose = true; |
805 |
} |
806 |
} |
807 |
|
808 |
#endregion |
809 |
|
810 |
#region Method - 처리 |
811 |
void CheckCommentPages() |
812 |
{ |
813 |
List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
814 |
DoubleCollection _Ticks = new DoubleCollection(); |
815 |
|
816 |
|
817 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
818 |
{ |
819 |
|
820 |
_pages = (from commPage in this._PageMarkupList |
821 |
where commPage.PageNumber == CurrentPageNo |
822 |
orderby commPage.PageNumber |
823 |
select commPage).ToList(); |
824 |
} |
825 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
826 |
{ |
827 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
828 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
829 |
|
830 |
int _stPage = (int)stPageNo.Value; |
831 |
int _edPage = (int)edPageNo.Value; |
832 |
|
833 |
_pages = (from commPage in this._PageMarkupList |
834 |
where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
835 |
orderby commPage.PageNumber |
836 |
select commPage).ToList(); |
837 |
} |
838 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
839 |
{ |
840 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
841 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
842 |
|
843 |
int _stPage = (int)stPageNo.Value; |
844 |
int _edPage = (int)edPageNo.Value; |
845 |
|
846 |
//Using DeepView.Common.RangeParser |
847 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
848 |
_pages = (from commPage in this._PageMarkupList |
849 |
from compareData in lst |
850 |
where commPage.PageNumber == compareData |
851 |
orderby commPage.PageNumber |
852 |
select commPage).ToList(); |
853 |
} |
854 |
else |
855 |
{ |
856 |
_pages = (from commPage in this._PageMarkupList |
857 |
orderby commPage.PageNumber |
858 |
select commPage).ToList(); |
859 |
} |
860 |
CommentPageList.ItemsSource = _pages.ToList(); |
861 |
} |
862 |
|
863 |
void SetLoadMakupList(int PageNo) |
864 |
{ |
865 |
_LoadMakupList.Clear(); |
866 |
var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
867 |
|
868 |
if (_markupList.Count() > 0) |
869 |
_LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
870 |
} |
871 |
|
872 |
#region 프린트 리스트 가져오기 |
873 |
public void GetPrint(bool flag) |
874 |
{ |
875 |
if (flag) |
876 |
{ |
877 |
foreach (string printer in PrinterSettings.InstalledPrinters) |
878 |
{ |
879 |
this.cbPrint.Items.Add(printer); |
880 |
} |
881 |
printDocument = new PrintDocument(); |
882 |
this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
883 |
} |
884 |
else |
885 |
{ |
886 |
this.cbPrint.Items.Add("PDF"); |
887 |
this.cbPrint.Items.Add("IMAGE"); |
888 |
|
889 |
this.cbPrint.SelectedItem = "PDF"; |
890 |
} |
891 |
} |
892 |
#endregion |
893 |
|
894 |
#region 프린트 실행 |
895 |
public async void Printing() |
896 |
{ |
897 |
var token = Common.ViewerDataModel.Instance.NewCancellationToken(); |
898 |
|
899 |
await PageChangeAsync(token,1, false); |
900 |
|
901 |
if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
902 |
{ |
903 |
printDocument = new PrintDocument(); |
904 |
printDocument.OriginAtMargins = true; |
905 |
printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
906 |
printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
907 |
printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
908 |
} |
909 |
else |
910 |
printDocument = null; |
911 |
|
912 |
#region 인쇄 미리보기 테스트 |
913 |
using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
914 |
{ |
915 |
printDocument.PrinterSettings.MinimumPage = 1; |
916 |
printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
917 |
printDocument.PrinterSettings.FromPage = 1; |
918 |
printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
919 |
printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
920 |
printDocument.PrinterSettings.PrinterName = PrintName; |
921 |
dlg.Document = printDocument; |
922 |
dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
923 |
dlg.ShowDialog(); |
924 |
} |
925 |
#endregion |
926 |
|
927 |
#region 인쇄 |
928 |
//printDocument.PrinterSettings.MinimumPage = 1; |
929 |
//printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
930 |
//printDocument.PrinterSettings.FromPage = 1; |
931 |
//printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
932 |
|
933 |
//printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
934 |
//printDocument.PrinterSettings.PrinterName = PrintName; |
935 |
|
936 |
//printDocument.Print(); |
937 |
#endregion |
938 |
} |
939 |
|
940 |
private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
941 |
{ |
942 |
//Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
943 |
// This demo only loads one page at a time, so no need to re-set the print page number |
944 |
PrintDocument document = sender as PrintDocument; |
945 |
currentPage = document.PrinterSettings.FromPage; |
946 |
} |
947 |
|
948 |
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
949 |
{ |
950 |
//e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0); |
951 |
|
952 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
953 |
{ |
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); |
956 |
|
957 |
if (p_img.Width > p_img.Height) |
958 |
{ |
959 |
p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); |
960 |
} |
961 |
|
962 |
//iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg); |
963 |
System.Drawing.Image pic = p_img; |
964 |
System.Drawing.Rectangle m = e.MarginBounds; |
965 |
|
966 |
//if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider |
967 |
//{ |
968 |
// m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16; |
969 |
//} |
970 |
//else |
971 |
//{ |
972 |
// m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16; |
973 |
//} |
974 |
m.Width = (int)e.PageSettings.PrintableArea.Width; |
975 |
m.Height = (int)e.PageSettings.PrintableArea.Height; |
976 |
m.X = (int)e.PageSettings.HardMarginX; |
977 |
m.Y = (int)e.PageSettings.HardMarginY; |
978 |
|
979 |
e.Graphics.DrawImage(pic, m); |
980 |
//e.Graphics.DrawImage(p_img, e.MarginBounds); |
981 |
//e.Graphics.DrawImage(p_img, 0, 0); |
982 |
})); |
983 |
|
984 |
//다음 페이지 |
985 |
currentPage++; |
986 |
|
987 |
////인쇄를 계속 할지 말지 확인 |
988 |
if (currentPage <= printDocument.PrinterSettings.ToPage) |
989 |
e.HasMorePages = true; |
990 |
else |
991 |
e.HasMorePages = false; |
992 |
|
993 |
} |
994 |
|
995 |
private void printDocument_EndPrint(object sender, PrintEventArgs e) |
996 |
{ |
997 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
998 |
{ |
999 |
if (Directory.Exists(TempImageDir)) |
1000 |
Directory.Delete(TempImageDir, true); |
1001 |
|
1002 |
sliderPages.Value = 1; |
1003 |
printIndy.IsBusy = false; |
1004 |
|
1005 |
})); |
1006 |
} |
1007 |
#endregion |
1008 |
|
1009 |
#region Selected Pages Check |
1010 |
List<int> PrintPageCreate() |
1011 |
{ |
1012 |
List<int> Result = new List<int>(); |
1013 |
|
1014 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
1015 |
{ |
1016 |
Result.Add(CurrentPageNo); |
1017 |
} |
1018 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
1019 |
{ |
1020 |
for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
1021 |
{ |
1022 |
Result.Add(i); |
1023 |
} |
1024 |
} |
1025 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
1026 |
{ |
1027 |
int _stPage = (int)stPageNo.Value; |
1028 |
int _edPage = (int)edPageNo.Value; |
1029 |
|
1030 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
1031 |
Result.AddRange(lst); |
1032 |
} |
1033 |
else |
1034 |
{ |
1035 |
for (int i = 1; i <= _definePages.PagesCount; i++) |
1036 |
{ |
1037 |
Result.Add(i); |
1038 |
} |
1039 |
} |
1040 |
if (currentPagePrint) |
1041 |
{ |
1042 |
return Result; |
1043 |
} |
1044 |
|
1045 |
if (chkOnlyMarkup.IsChecked.Value) |
1046 |
{ |
1047 |
var _result = from result in Result |
1048 |
where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
1049 |
select result; |
1050 |
Result = _result.ToList(); |
1051 |
} |
1052 |
return Result; |
1053 |
} |
1054 |
#endregion |
1055 |
|
1056 |
#endregion |
1057 |
} |
1058 |
} |