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