markus / KCOM / Controls / PrintControl.xaml.cs @ 91c5e7a1
이력 | 보기 | 이력해설 | 다운로드 (37.5 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 System.Reactive.Linq; |
12 |
using KCOMDataModel.DataModel; |
13 |
using Microsoft.Win32; |
14 |
using System.IO; |
15 |
using System.Timers; |
16 |
//using IKCOM.Common; |
17 |
using KCOM.Event; |
18 |
using iTextSharp; |
19 |
using iTextSharp.text; |
20 |
//using Leadtools.Windows.Controls; |
21 |
using IKCOM; |
22 |
using iTextSharp.text.pdf; |
23 |
using Microsoft.Office.Core; |
24 |
using System.Net; |
25 |
using KCOM; |
26 |
|
27 |
namespace KCOM.Control |
28 |
{ |
29 |
public class DefinedPages |
30 |
{ |
31 |
public int PagesCount { get; set; } |
32 |
public string vpSlip { get; set; } |
33 |
public string vpTitle { get; set; } |
34 |
public string fileUrl { get; set; } |
35 |
public ImageBrush Back_Image { get; set; } |
36 |
|
37 |
string _DefinedPagesStrings; |
38 |
/// <summary> |
39 |
/// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용 |
40 |
/// </summary> |
41 |
public string DefinedPagesStrings |
42 |
{ |
43 |
get { return _DefinedPagesStrings; } |
44 |
set |
45 |
{ |
46 |
if (string.IsNullOrWhiteSpace(value)) return; |
47 |
|
48 |
var _definedPages = value.Replace('-', ',').Split(','); |
49 |
List<char> _NotEx = new List<char>(); |
50 |
|
51 |
foreach (var item in _definedPages) |
52 |
{ |
53 |
bool _isNum = true; |
54 |
|
55 |
foreach (var chr in item) |
56 |
{ |
57 |
if (!char.IsNumber(chr)) |
58 |
{ |
59 |
_NotEx.Add(chr); |
60 |
_isNum = false; |
61 |
} |
62 |
} |
63 |
|
64 |
if (_isNum) |
65 |
{ |
66 |
if (Convert.ToInt32(item) > PagesCount) |
67 |
throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount)); |
68 |
} |
69 |
} |
70 |
|
71 |
if (_NotEx.Count() > 0) |
72 |
{ |
73 |
string _notString = ""; |
74 |
_NotEx.ForEach(s => _notString += s.ToString()); |
75 |
throw new Exception(string.Format("'{0}' Can not be added.", _notString)); |
76 |
} |
77 |
|
78 |
|
79 |
try |
80 |
{ |
81 |
|
82 |
string _notString2 = ""; |
83 |
_NotEx.ForEach(s => _notString2 += s.ToString()); |
84 |
_DefinedPagesStrings = value; |
85 |
} |
86 |
catch (Exception) |
87 |
{ |
88 |
throw new Exception(string.Format("Can not be added.")); |
89 |
} |
90 |
|
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
/// <summary> |
96 |
/// Interaction logic for Print.xaml |
97 |
/// </summary> |
98 |
public partial class PrintControl : UserControl |
99 |
{ |
100 |
#region Data |
101 |
|
102 |
string ProjectNo = null; //프로젝트 넘버 |
103 |
string _DefaultTileUri = null; //기본 타일 경로 |
104 |
int _StartPageNo; //시작페이지 |
105 |
DOCINFO _DocInfo; //문서 정보 |
106 |
//DocInfo _DocInfo; //문서 정보 |
107 |
bool currentPagePrint = false; //현재 페이지 수 |
108 |
int PageCount { get; set; } //총 페이지수 |
109 |
DefinedPages _definePages = null; //인쇄 설정 범위 지정 |
110 |
public bool IsPrint { get; set; } |
111 |
|
112 |
private List<PemssService.Requirement> requirementList = new List<PemssService.Requirement>(); |
113 |
|
114 |
PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성 |
115 |
|
116 |
//LayerControl LayerControl = null; // 레이어 컨트롤 |
117 |
ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보 |
118 |
List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>(); |
119 |
List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>(); |
120 |
List<int> _lstPrintPageNo = new List<int>(); |
121 |
|
122 |
System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer(); |
123 |
bool _initializeComponentFinished; //이벤트 |
124 |
bool _IsDagSlider = false; //드래그 상태인가 |
125 |
List<DisplayColorInfo> colorList = new List<DisplayColorInfo>(); |
126 |
DefinedPages DocumentInfo { get; set; } //문서정보 정의 |
127 |
//PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 |
128 |
delegate void PrintEventHandler(); //프린트 핸들러 |
129 |
SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그 |
130 |
//SaveFileDialog SaveFile { get; set; } //저장할 때 사용 |
131 |
|
132 |
//RasterImageViewer _viewer; //이미지 뷰어 |
133 |
//System.Windows.Controls.Image backimg; //백그라운드 이미지 |
134 |
System.Drawing.Image Printimg; //프린트 이미지 |
135 |
System.Drawing.Image p_img; //프린트 이미지 |
136 |
iTextSharp.text.Image Export_img; |
137 |
Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지 |
138 |
|
139 |
//RasterCodecs codecs; |
140 |
int currentPage; |
141 |
public string PrintName; |
142 |
public string Type; |
143 |
|
144 |
public System.Timers.Timer timm = new System.Timers.Timer(); |
145 |
|
146 |
|
147 |
#endregion |
148 |
|
149 |
#region Static Property Defines |
150 |
public static readonly DependencyProperty CurrentPageNoProperty = |
151 |
DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
152 |
new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
153 |
#endregion |
154 |
|
155 |
#region Property |
156 |
public int CurrentPageNo |
157 |
{ |
158 |
get { return (int)GetValue(CurrentPageNoProperty); } |
159 |
set { SetValue(CurrentPageNoProperty, value); } |
160 |
} |
161 |
#endregion |
162 |
|
163 |
#region PropertyChangeMethod |
164 |
private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
165 |
{ |
166 |
var printPage = (PrintControl)d; |
167 |
var newValue = (int)e.NewValue; |
168 |
|
169 |
printPage.sliderPages.Value = newValue; |
170 |
printPage.SetLoadMakupList(newValue); |
171 |
|
172 |
} |
173 |
#endregion |
174 |
|
175 |
#region 생성자 |
176 |
|
177 |
public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
178 |
{ |
179 |
InitializeComponent(); |
180 |
|
181 |
this.IsEnabled = true; |
182 |
|
183 |
//Layer Control을 통째로 가져와야 하는건가 |
184 |
//this.LayerControl = LayerControl; |
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 |
_definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl }; |
229 |
DocumentInfo = _definePages; |
230 |
this.DataContext = _definePages; |
231 |
|
232 |
CheckCommentPages(); |
233 |
|
234 |
//초기화면 Comment Check된 상태로 보여주기 |
235 |
foreach (var item in _markupInfo) |
236 |
{ |
237 |
gridViewMarkup.SelectedItems.Add(item); |
238 |
} |
239 |
PageChanged(_StartPageNo); |
240 |
|
241 |
|
242 |
sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
243 |
this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
244 |
this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
245 |
this.IsPrint = isPrint; |
246 |
|
247 |
if (!IsPrint) |
248 |
{ |
249 |
GetPrint(false); |
250 |
btnWholeExport.Visibility = Visibility.Visible; |
251 |
btnWholePrint.Visibility = Visibility.Collapsed; |
252 |
Selected_Print.Header = "Export Type"; |
253 |
} |
254 |
else |
255 |
{ |
256 |
//PrintList 가져오기 |
257 |
GetPrint(true); |
258 |
btnWholePrint.Visibility = Visibility.Visible; |
259 |
btnWholeExport.Visibility = Visibility.Collapsed; |
260 |
} |
261 |
|
262 |
var pemssServiceClient = new PemssService.PemssServiceClient(App._binding, App._PemssEndPoint); |
263 |
var result = pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID).ConfigureAwait(false); |
264 |
|
265 |
requirementList = result.GetAwaiter().GetResult(); |
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 |
private void _Timer_Elapsed(object sender, ElapsedEventArgs e) |
275 |
{ |
276 |
timm.Enabled = false; |
277 |
PageChanged(_StartPageNo); |
278 |
} |
279 |
#endregion |
280 |
|
281 |
#region Control Event |
282 |
private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
283 |
{ |
284 |
if (_initializeComponentFinished) |
285 |
{ |
286 |
if (!_IsDagSlider) |
287 |
{ |
288 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
289 |
PageChanged(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 void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
303 |
{ |
304 |
_IsDagSlider = false; |
305 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
306 |
if (_initializeComponentFinished) |
307 |
{ |
308 |
PageChanged(this.CurrentPageNo); |
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 void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
407 |
{ |
408 |
if (_initializeComponentFinished) |
409 |
{ |
410 |
PageChanged(this.CurrentPageNo); |
411 |
} |
412 |
} |
413 |
|
414 |
#endregion |
415 |
|
416 |
public void PageChanged(int PageNo, bool Flag = false) |
417 |
{ |
418 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
419 |
{ |
420 |
try |
421 |
{ |
422 |
Load load = new Load(); |
423 |
|
424 |
_definePages.Back_Image = new ImageBrush(); |
425 |
//var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png")); |
426 |
var buffer = new WebClient().DownloadData(_DefaultTileUri + PageNo + ".png"); |
427 |
var bitmap = new BitmapImage(); |
428 |
using (var stream = new MemoryStream(buffer)) |
429 |
{ |
430 |
bitmap.BeginInit(); |
431 |
bitmap.CacheOption = BitmapCacheOption.OnLoad; |
432 |
bitmap.StreamSource = stream; |
433 |
bitmap.EndInit(); |
434 |
|
435 |
printCanvas.Children.Clear(); |
436 |
|
437 |
ImageBrush background = new ImageBrush(bitmap); |
438 |
printCanvas.Background = background; |
439 |
|
440 |
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png")); |
441 |
printCanvas.Width = image.Width; |
442 |
printCanvas.Height = image.Height; |
443 |
|
444 |
List<string> removeMarkupItems = new List<string>(); |
445 |
|
446 |
foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
447 |
{ |
448 |
if (IsRequirement.IsChecked != true) |
449 |
{ |
450 |
removeMarkupItems =requirementList.SelectMany(x => x.VpComments.SelectMany(c => c.commentId.Split(','))).ToList(); |
451 |
} |
452 |
|
453 |
load.User_Id = info.UserID; |
454 |
load.document_id = _DocInfo.DOCUMENT_ID; |
455 |
load.Page_No = PageNo; |
456 |
load.DisplayColor = info.DisplayColor; |
457 |
load.Markupinfoid = info.MarkupInfoID; |
458 |
load.Markup_Load(printCanvas, removeMarkupItems); |
459 |
} |
460 |
|
461 |
printCanvas.UpdateLayout(); |
462 |
|
463 |
if (Flag) |
464 |
{ |
465 |
|
466 |
//MemoryStream ms = new MemoryStream(); |
467 |
//BmpBitmapEncoder bbe = new BmpBitmapEncoder(); |
468 |
//bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png"))); |
469 |
//bbe.Save(ms); |
470 |
|
471 |
//System.Drawing.Image.FromFile() |
472 |
Printimg = System.Drawing.Image.FromStream(stream); |
473 |
Export export = new Export(); |
474 |
p_img = export.Exporting(printCanvas, Printimg); |
475 |
Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
476 |
} |
477 |
} |
478 |
|
479 |
} |
480 |
catch (Exception ex) |
481 |
{ |
482 |
Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0); |
483 |
} |
484 |
})); |
485 |
} |
486 |
public static MemoryStream ByteBufferFromImage(BitmapImage imageSource) |
487 |
{ |
488 |
var ms = new MemoryStream(); |
489 |
var pngEncoder = new PngBitmapEncoder(); |
490 |
pngEncoder.Frames.Add(BitmapFrame.Create(imageSource)); |
491 |
pngEncoder.Save(ms); |
492 |
|
493 |
return ms; |
494 |
} |
495 |
//Print 버튼 클릭 이벤트 |
496 |
#region Method - 명령 |
497 |
void PrintMethod(object sender, RoutedEventArgs e) |
498 |
{ |
499 |
try |
500 |
{ |
501 |
if (this.printIndy.IsBusy == true) |
502 |
return; |
503 |
|
504 |
System.Threading.Tasks.Task.Factory.StartNew(() => |
505 |
{ |
506 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
507 |
{ |
508 |
this.printIndy.IsBusy = true; |
509 |
printIndy.BusyContent = "Printing. . ."; |
510 |
})); |
511 |
}); |
512 |
|
513 |
|
514 |
_lstPrintPageNo = PrintPageCreate(); |
515 |
|
516 |
if (_lstPrintPageNo.Count == 0) |
517 |
{ |
518 |
RadWindow.Alert(new DialogParameters |
519 |
{ |
520 |
Owner = Application.Current.MainWindow, |
521 |
Theme = new VisualStudio2013Theme(), |
522 |
Header = "안내", |
523 |
Content = "페이지가 지정되지 않았습니다." |
524 |
}); |
525 |
this.printIndy.IsBusy = false; |
526 |
return; |
527 |
} |
528 |
int cnt = 0; |
529 |
List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>(); |
530 |
|
531 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
532 |
|
533 |
foreach (int PageNo in _lstPrintPageNo) |
534 |
{ |
535 |
cnt++; |
536 |
sliderPages.Value = PageNo; |
537 |
PageChanged(PageNo, true); |
538 |
//PageChanged(cnt, true); |
539 |
} |
540 |
PrintName = cbPrint.SelectedItem.ToString(); |
541 |
|
542 |
System.Threading.Tasks.Task.Factory.StartNew(() => |
543 |
{ |
544 |
if (cnt == _lstPrintPageNo.Count) |
545 |
{ |
546 |
Printing(); |
547 |
} |
548 |
}); |
549 |
} |
550 |
catch (Exception ex) |
551 |
{ |
552 |
Logger.sendResLog("PrintMethod", ex.Message, 0); |
553 |
} |
554 |
|
555 |
} |
556 |
|
557 |
//Export 버튼 클릭 이벤트 |
558 |
void ExportMethod(object sender, RoutedEventArgs e) |
559 |
{ |
560 |
try |
561 |
{ |
562 |
if (this.printIndy.IsBusy == true) |
563 |
return; |
564 |
|
565 |
this.printIndy.IsBusy = true; |
566 |
printIndy.BusyContent = "Exporting. . ."; |
567 |
|
568 |
Export export = new Export(); |
569 |
_lstPrintPageNo = PrintPageCreate(); |
570 |
|
571 |
if (_lstPrintPageNo.Count == 0) |
572 |
{ |
573 |
this.printIndy.IsBusy = false; |
574 |
RadWindow.Alert(new DialogParameters |
575 |
{ |
576 |
Owner = Application.Current.MainWindow, |
577 |
Theme = new VisualStudio2013Theme(), |
578 |
Header = "안내", |
579 |
Content = "페이지가 지정되지 않았습니다.", |
580 |
}); |
581 |
return; |
582 |
} |
583 |
|
584 |
//FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png"); |
585 |
|
586 |
switch (cbPrint.SelectedIndex) |
587 |
{ |
588 |
case (0): |
589 |
{ |
590 |
SaveDig.Filter = "PDF file format|*.pdf"; |
591 |
break; |
592 |
} |
593 |
case (1): |
594 |
{ |
595 |
SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png"; |
596 |
break; |
597 |
} |
598 |
} |
599 |
|
600 |
SaveDig.Title = "Save an PDF File"; |
601 |
var mainwindow = (RadWindowManager.Current.GetWindows().Find(x => x is MainWindow) as MainWindow); |
602 |
|
603 |
if (SaveDig.ShowDialog().Value) |
604 |
{ |
605 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
606 |
|
607 |
foreach (int PageNo in _lstPrintPageNo) |
608 |
{ |
609 |
sliderPages.Value = PageNo; |
610 |
PageChanged(PageNo, true); |
611 |
} |
612 |
|
613 |
//using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
614 |
|
615 |
if (SaveDig.FileName != "") |
616 |
{ |
617 |
switch (cbPrint.SelectedIndex) |
618 |
{ |
619 |
case (0): |
620 |
{ |
621 |
using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None)) |
622 |
{ |
623 |
using (Document doc = new Document()) |
624 |
{ |
625 |
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) |
626 |
{ |
627 |
doc.Open(); |
628 |
float height = doc.PageSize.Height; |
629 |
float width = doc.PageSize.Width; |
630 |
|
631 |
foreach (var item in Printimg_List) |
632 |
{ |
633 |
|
634 |
Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png); |
635 |
|
636 |
|
637 |
if (Export_img.Width > Export_img.Height) |
638 |
{ |
639 |
doc.SetPageSize(new Rectangle(height, width)); |
640 |
Export_img.ScaleToFit(height, width); |
641 |
} |
642 |
else |
643 |
{ |
644 |
doc.SetPageSize(new Rectangle(width, height)); |
645 |
Export_img.ScaleToFit(width, height); |
646 |
} |
647 |
|
648 |
Export_img.SetAbsolutePosition(0, 0); |
649 |
|
650 |
doc.NewPage(); |
651 |
doc.Add(Export_img); |
652 |
} |
653 |
doc.Close(); |
654 |
} |
655 |
} |
656 |
} |
657 |
break; |
658 |
} |
659 |
case (1): |
660 |
{ |
661 |
foreach (var item in Printimg_List) |
662 |
{ |
663 |
switch (SaveDig.FilterIndex) |
664 |
{ |
665 |
case (1): |
666 |
{ |
667 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg); |
668 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); |
669 |
} |
670 |
break; |
671 |
case (2): |
672 |
{ |
673 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png); |
674 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png); |
675 |
} |
676 |
break; |
677 |
} |
678 |
} |
679 |
break; |
680 |
} |
681 |
} |
682 |
} |
683 |
else |
684 |
{ |
685 |
this.printIndy.IsBusy = false; |
686 |
return; |
687 |
} |
688 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
689 |
{ |
690 |
printIndy.IsBusy = false; |
691 |
})); |
692 |
PageChanged(_StartPageNo); |
693 |
|
694 |
(RadWindowManager.Current.GetWindows().Find(x=>x is MainWindow) as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert"); |
695 |
}else |
696 |
{ |
697 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
698 |
{ |
699 |
printIndy.IsBusy = false; |
700 |
})); |
701 |
|
702 |
mainwindow.dzMainMenu.DialogMessage_Alert("Cancel", "Alert"); |
703 |
} |
704 |
} |
705 |
catch (Exception ex) |
706 |
{ |
707 |
Logger.sendResLog("Export Method", ex.Message, 0); |
708 |
//(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message); |
709 |
} |
710 |
|
711 |
} |
712 |
#endregion |
713 |
|
714 |
#region Method - 처리 |
715 |
void CheckCommentPages() |
716 |
{ |
717 |
List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
718 |
DoubleCollection _Ticks = new DoubleCollection(); |
719 |
|
720 |
|
721 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
722 |
{ |
723 |
|
724 |
_pages = (from commPage in this._PageMarkupList |
725 |
where commPage.PageNumber == CurrentPageNo |
726 |
orderby commPage.PageNumber |
727 |
select commPage).ToList(); |
728 |
} |
729 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
730 |
{ |
731 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
732 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
733 |
|
734 |
int _stPage = (int)stPageNo.Value; |
735 |
int _edPage = (int)edPageNo.Value; |
736 |
|
737 |
_pages = (from commPage in this._PageMarkupList |
738 |
where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
739 |
orderby commPage.PageNumber |
740 |
select commPage).ToList(); |
741 |
} |
742 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
743 |
{ |
744 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
745 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
746 |
|
747 |
int _stPage = (int)stPageNo.Value; |
748 |
int _edPage = (int)edPageNo.Value; |
749 |
|
750 |
//Using DeepView.Common.RangeParser |
751 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
752 |
_pages = (from commPage in this._PageMarkupList |
753 |
from compareData in lst |
754 |
where commPage.PageNumber == compareData |
755 |
orderby commPage.PageNumber |
756 |
select commPage).ToList(); |
757 |
} |
758 |
else |
759 |
{ |
760 |
_pages = (from commPage in this._PageMarkupList |
761 |
orderby commPage.PageNumber |
762 |
select commPage).ToList(); |
763 |
} |
764 |
CommentPageList.ItemsSource = _pages.ToList(); |
765 |
} |
766 |
|
767 |
void SetLoadMakupList(int PageNo) |
768 |
{ |
769 |
_LoadMakupList.Clear(); |
770 |
var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
771 |
|
772 |
if (_markupList.Count() > 0) |
773 |
_LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
774 |
} |
775 |
|
776 |
#region 프린트 리스트 가져오기 |
777 |
public void GetPrint(bool flag) |
778 |
{ |
779 |
if (flag) |
780 |
{ |
781 |
foreach (string printer in PrinterSettings.InstalledPrinters) |
782 |
{ |
783 |
this.cbPrint.Items.Add(printer); |
784 |
} |
785 |
printDocument = new PrintDocument(); |
786 |
this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
787 |
} |
788 |
else |
789 |
{ |
790 |
this.cbPrint.Items.Add("PDF"); |
791 |
this.cbPrint.Items.Add("IMAGE"); |
792 |
|
793 |
this.cbPrint.SelectedItem = "PDF"; |
794 |
} |
795 |
} |
796 |
#endregion |
797 |
|
798 |
#region 프린트 실행 |
799 |
public void Printing() |
800 |
{ |
801 |
PageChanged(1); |
802 |
if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
803 |
{ |
804 |
printDocument = new PrintDocument(); |
805 |
printDocument.OriginAtMargins = true; |
806 |
printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
807 |
printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
808 |
printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
809 |
} |
810 |
else |
811 |
printDocument = null; |
812 |
|
813 |
#region 인쇄 미리보기 테스트 |
814 |
using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
815 |
{ |
816 |
printDocument.PrinterSettings.MinimumPage = 1; |
817 |
printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
818 |
printDocument.PrinterSettings.FromPage = 1; |
819 |
printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
820 |
printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
821 |
printDocument.PrinterSettings.PrinterName = PrintName; |
822 |
dlg.Document = printDocument; |
823 |
dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
824 |
dlg.ShowDialog(); |
825 |
} |
826 |
#endregion |
827 |
|
828 |
#region 인쇄 |
829 |
//printDocument.PrinterSettings.MinimumPage = 1; |
830 |
//printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
831 |
//printDocument.PrinterSettings.FromPage = 1; |
832 |
//printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
833 |
|
834 |
//printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
835 |
//printDocument.PrinterSettings.PrinterName = PrintName; |
836 |
|
837 |
//printDocument.Print(); |
838 |
#endregion |
839 |
} |
840 |
|
841 |
private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
842 |
{ |
843 |
//Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
844 |
// This demo only loads one page at a time, so no need to re-set the print page number |
845 |
PrintDocument document = sender as PrintDocument; |
846 |
currentPage = document.PrinterSettings.FromPage; |
847 |
} |
848 |
|
849 |
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
850 |
{ |
851 |
//e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0); |
852 |
|
853 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
854 |
{ |
855 |
p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
856 |
|
857 |
if (p_img.Width > p_img.Height) |
858 |
{ |
859 |
p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); |
860 |
} |
861 |
|
862 |
//iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg); |
863 |
System.Drawing.Image pic = p_img; |
864 |
System.Drawing.Rectangle m = e.MarginBounds; |
865 |
|
866 |
//if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider |
867 |
//{ |
868 |
// m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16; |
869 |
//} |
870 |
//else |
871 |
//{ |
872 |
// m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16; |
873 |
//} |
874 |
m.Width = (int)e.PageSettings.PrintableArea.Width; |
875 |
m.Height = (int)e.PageSettings.PrintableArea.Height; |
876 |
m.X = (int)e.PageSettings.HardMarginX; |
877 |
m.Y = (int)e.PageSettings.HardMarginY; |
878 |
|
879 |
e.Graphics.DrawImage(pic, m); |
880 |
//e.Graphics.DrawImage(p_img, e.MarginBounds); |
881 |
//e.Graphics.DrawImage(p_img, 0, 0); |
882 |
})); |
883 |
|
884 |
//다음 페이지 |
885 |
currentPage++; |
886 |
|
887 |
////인쇄를 계속 할지 말지 확인 |
888 |
if (currentPage <= printDocument.PrinterSettings.ToPage) |
889 |
e.HasMorePages = true; |
890 |
else |
891 |
e.HasMorePages = false; |
892 |
|
893 |
} |
894 |
|
895 |
private void printDocument_EndPrint(object sender, PrintEventArgs e) |
896 |
{ |
897 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
898 |
{ |
899 |
printIndy.IsBusy = false; |
900 |
})); |
901 |
} |
902 |
#endregion |
903 |
|
904 |
#region Selected Pages Check |
905 |
List<int> PrintPageCreate() |
906 |
{ |
907 |
List<int> Result = new List<int>(); |
908 |
|
909 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
910 |
{ |
911 |
Result.Add(CurrentPageNo); |
912 |
} |
913 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
914 |
{ |
915 |
for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
916 |
{ |
917 |
Result.Add(i); |
918 |
} |
919 |
} |
920 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
921 |
{ |
922 |
int _stPage = (int)stPageNo.Value; |
923 |
int _edPage = (int)edPageNo.Value; |
924 |
|
925 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
926 |
Result.AddRange(lst); |
927 |
} |
928 |
else |
929 |
{ |
930 |
for (int i = 1; i <= _definePages.PagesCount; i++) |
931 |
{ |
932 |
Result.Add(i); |
933 |
} |
934 |
} |
935 |
if (currentPagePrint) |
936 |
{ |
937 |
return Result; |
938 |
} |
939 |
|
940 |
if (chkOnlyMarkup.IsChecked.Value) |
941 |
{ |
942 |
var _result = from result in Result |
943 |
where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
944 |
select result; |
945 |
Result = _result.ToList(); |
946 |
} |
947 |
return Result; |
948 |
} |
949 |
#endregion |
950 |
|
951 |
#endregion |
952 |
} |
953 |
} |