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