markus / KCOM / Controls / PrintControl.xaml.cs @ b200de5a
이력 | 보기 | 이력해설 | 다운로드 (32.3 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 |
//강인구 추가 |
25 |
namespace KCOM.Control |
26 |
{ |
27 |
//문서 정보 모음 클래스? |
28 |
public class DefinedPages |
29 |
{ |
30 |
public int PagesCount { get; set; } |
31 |
public string vpSlip { get; set; } |
32 |
public string vpTitle { get; set; } |
33 |
public string fileUrl { get; set; } |
34 |
public ImageBrush Back_Image { get; set; } |
35 |
|
36 |
string _DefinedPagesStrings; |
37 |
/// <summary> |
38 |
/// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용 |
39 |
/// </summary> |
40 |
public string DefinedPagesStrings |
41 |
{ |
42 |
get { return _DefinedPagesStrings; } |
43 |
set |
44 |
{ |
45 |
if (string.IsNullOrWhiteSpace(value)) return; |
46 |
|
47 |
var _definedPages = value.Replace('-', ',').Split(','); |
48 |
List<char> _NotEx = new List<char>(); |
49 |
|
50 |
foreach (var item in _definedPages) |
51 |
{ |
52 |
bool _isNum = true; |
53 |
|
54 |
foreach (var chr in item) |
55 |
{ |
56 |
if (!char.IsNumber(chr)) |
57 |
{ |
58 |
_NotEx.Add(chr); |
59 |
_isNum = false; |
60 |
} |
61 |
} |
62 |
|
63 |
if (_isNum) |
64 |
{ |
65 |
if (Convert.ToInt32(item) > PagesCount) |
66 |
throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount)); |
67 |
} |
68 |
} |
69 |
|
70 |
if (_NotEx.Count() > 0) |
71 |
{ |
72 |
string _notString = ""; |
73 |
_NotEx.ForEach(s => _notString += s.ToString()); |
74 |
throw new Exception(string.Format("'{0}' Can not be added.", _notString)); |
75 |
} |
76 |
|
77 |
|
78 |
try |
79 |
{ |
80 |
|
81 |
string _notString2 = ""; |
82 |
_NotEx.ForEach(s => _notString2 += s.ToString()); |
83 |
_DefinedPagesStrings = value; |
84 |
} |
85 |
catch (Exception) |
86 |
{ |
87 |
throw new Exception(string.Format("Can not be added.")); |
88 |
} |
89 |
|
90 |
} |
91 |
} |
92 |
} |
93 |
|
94 |
/// <summary> |
95 |
/// Interaction logic for Print.xaml |
96 |
/// </summary> |
97 |
public partial class PrintControl : UserControl |
98 |
{ |
99 |
#region Data |
100 |
|
101 |
string ProjectNo = null; //프로젝트 넘버 |
102 |
string _DefaultTileUri = null; //기본 타일 경로 |
103 |
int _StartPageNo; //시작페이지 |
104 |
DOCINFO _DocInfo; //문서 정보 |
105 |
//DocInfo _DocInfo; //문서 정보 |
106 |
bool currentPagePrint = false; //현재 페이지 수 |
107 |
int PageCount { get; set; } //총 페이지수 |
108 |
DefinedPages _definePages = null; //인쇄 설정 범위 지정 |
109 |
public bool IsPrint { get; set; } |
110 |
|
111 |
PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성 |
112 |
|
113 |
//LayerControl LayerControl = null; // 레이어 컨트롤 |
114 |
ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보 |
115 |
List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>(); |
116 |
List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>(); |
117 |
List<int> _lstPrintPageNo = new List<int>(); |
118 |
|
119 |
System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer(); |
120 |
bool _initializeComponentFinished; //이벤트 |
121 |
bool _IsDagSlider = false; //드래그 상태인가 |
122 |
List<DisplayColorInfo> colorList = new List<DisplayColorInfo>(); |
123 |
DefinedPages DocumentInfo { get; set; } //문서정보 정의 |
124 |
//PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 |
125 |
delegate void PrintEventHandler(); //프린트 핸들러 |
126 |
SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그 |
127 |
//SaveFileDialog SaveFile { get; set; } //저장할 때 사용 |
128 |
|
129 |
//RasterImageViewer _viewer; //이미지 뷰어 |
130 |
System.Windows.Controls.Image backimg; //백그라운드 이미지 |
131 |
System.Drawing.Image Printimg; //프린트 이미지 |
132 |
System.Drawing.Image p_img; //프린트 이미지 |
133 |
iTextSharp.text.Image Export_img; |
134 |
Dictionary<int,System.Drawing.Image> Printimg_List; //프린트 이미지 |
135 |
|
136 |
//RasterCodecs codecs; |
137 |
int currentPage; |
138 |
public string PrintName; |
139 |
public string Type; |
140 |
|
141 |
public System.Timers.Timer timm = new System.Timers.Timer(); |
142 |
|
143 |
|
144 |
#endregion |
145 |
|
146 |
#region Static Property Defines |
147 |
public static readonly DependencyProperty CurrentPageNoProperty = |
148 |
DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
149 |
new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
150 |
#endregion |
151 |
|
152 |
#region Property |
153 |
public int CurrentPageNo |
154 |
{ |
155 |
get { return (int)GetValue(CurrentPageNoProperty); } |
156 |
set { SetValue(CurrentPageNoProperty, value); } |
157 |
} |
158 |
#endregion |
159 |
|
160 |
#region PropertyChangeMethod |
161 |
private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
162 |
{ |
163 |
var printPage = (PrintControl)d; |
164 |
var newValue = (int)e.NewValue; |
165 |
|
166 |
printPage.sliderPages.Value = newValue; |
167 |
printPage.SetLoadMakupList(newValue); |
168 |
|
169 |
} |
170 |
#endregion |
171 |
|
172 |
#region 생성자 |
173 |
//public PrintControl() |
174 |
//{ |
175 |
//} |
176 |
//public PrintControl(LayerControl LayerControl, string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<ServiceInterface.MarkupInfoItem> |
177 |
// markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
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.LayerControl = LayerControl; |
186 |
this._DocInfo = DocInfo; |
187 |
this._DefaultTileUri = TileSourceUri; |
188 |
this.ProjectNo = ProjectNo; |
189 |
this._StartPageNo = CurrentPageNo; |
190 |
|
191 |
markupInfo.ForEach(info => this._markupInfo.Add(info)); |
192 |
|
193 |
foreach (var info in _markupInfo) |
194 |
{ |
195 |
if (info.Consolidate == 1) |
196 |
{ |
197 |
info.UserName = "Consolidation"; |
198 |
} |
199 |
info.MarkupList.ForEach(makup => |
200 |
{ |
201 |
var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber); |
202 |
var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor }; |
203 |
|
204 |
if (_pageMarkup.Count() > 0) |
205 |
_pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem); |
206 |
else |
207 |
_PageMarkupList.Add(new MarkupPageItem |
208 |
{ |
209 |
PageNumber = makup.PageNumber, |
210 |
DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem } |
211 |
}); |
212 |
}); |
213 |
|
214 |
colorList.Add(new DisplayColorInfo |
215 |
{ |
216 |
UserID = info.UserID, |
217 |
DisplayColor = info.DisplayColor, |
218 |
Department = info.Depatment, |
219 |
UserName = info.UserName, |
220 |
}); |
221 |
} |
222 |
|
223 |
gridViewMarkup.ItemsSource = this._markupInfo; |
224 |
SetLoadMakupList(this._StartPageNo); |
225 |
if (_LoadMakupList.Count() == 0) |
226 |
chkOnlyMarkup.IsChecked = false; |
227 |
|
228 |
this.CurrentPageNo = _StartPageNo; |
229 |
_definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl }; |
230 |
DocumentInfo = _definePages; |
231 |
this.DataContext = _definePages; |
232 |
|
233 |
CheckCommentPages(); |
234 |
|
235 |
//초기화면 Comment Check된 상태로 보여주기 |
236 |
foreach (var item in _markupInfo) |
237 |
{ |
238 |
gridViewMarkup.SelectedItems.Add(item); |
239 |
} |
240 |
PageChanged(_StartPageNo); |
241 |
|
242 |
|
243 |
sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
244 |
this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
245 |
this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
246 |
this.IsPrint = isPrint; |
247 |
|
248 |
if (!IsPrint) |
249 |
{ |
250 |
GetPrint(false); |
251 |
btnWholeExport.Visibility = Visibility.Visible; |
252 |
btnWholePrint.Visibility = Visibility.Collapsed; |
253 |
Selected_Print.Header = "Export Type"; |
254 |
} |
255 |
else |
256 |
{ |
257 |
//PrintList 가져오기 |
258 |
GetPrint(true); |
259 |
btnWholePrint.Visibility = Visibility.Visible; |
260 |
btnWholeExport.Visibility = Visibility.Collapsed; |
261 |
} |
262 |
|
263 |
_initializeComponentFinished = true; |
264 |
|
265 |
//timm.Interval = 10; |
266 |
//timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed); |
267 |
//timm.Enabled = true; |
268 |
} |
269 |
|
270 |
private void _Timer_Elapsed(object sender, ElapsedEventArgs e) |
271 |
{ |
272 |
timm.Enabled = false; |
273 |
PageChanged(_StartPageNo); |
274 |
} |
275 |
#endregion |
276 |
|
277 |
#region Control Event |
278 |
private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
279 |
{ |
280 |
if (_initializeComponentFinished) |
281 |
{ |
282 |
if (!_IsDagSlider) |
283 |
{ |
284 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
285 |
PageChanged(this.CurrentPageNo); |
286 |
//CheckCommentPages(); |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
292 |
{ |
293 |
_IsDagSlider = false; |
294 |
this.CurrentPageNo = (int)this.sliderPages.Value; |
295 |
if (_initializeComponentFinished) |
296 |
{ |
297 |
PageChanged(this.CurrentPageNo); |
298 |
} |
299 |
} |
300 |
|
301 |
private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e) |
302 |
{ |
303 |
_IsDagSlider = true; |
304 |
} |
305 |
|
306 |
private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e) |
307 |
{ |
308 |
if (_initializeComponentFinished) //GridRangePages |
309 |
{ |
310 |
CheckCommentPages(); |
311 |
} |
312 |
} |
313 |
|
314 |
private void PageSelect_Checked(object sender, RoutedEventArgs e) |
315 |
{ |
316 |
if (!_initializeComponentFinished) return; |
317 |
|
318 |
string _ButtonName = (sender as RadRadioButton).Tag.ToString(); |
319 |
CommentPageList.ItemsSource = null; |
320 |
|
321 |
switch (_ButtonName) |
322 |
{ |
323 |
case "Current": |
324 |
stPageNo.Value = CurrentPageNo; |
325 |
edPageNo.Value = CurrentPageNo; |
326 |
|
327 |
GridCurrentPage.Visibility = Visibility.Visible; |
328 |
GridDefinePages.Visibility = Visibility.Collapsed; |
329 |
GridRangePages.Visibility = Visibility.Collapsed; |
330 |
GridAllPages.Visibility = Visibility.Collapsed; |
331 |
|
332 |
break; |
333 |
case "RangePrint": |
334 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
335 |
GridDefinePages.Visibility = Visibility.Visible; |
336 |
GridRangePages.Visibility = Visibility.Collapsed; |
337 |
GridAllPages.Visibility = Visibility.Collapsed; |
338 |
break; |
339 |
case "UserDefined": |
340 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
341 |
GridDefinePages.Visibility = Visibility.Collapsed; |
342 |
GridRangePages.Visibility = Visibility.Visible; |
343 |
GridAllPages.Visibility = Visibility.Collapsed; |
344 |
break; |
345 |
case "AllPrint": |
346 |
stPageNo.Value = 1; |
347 |
edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT); |
348 |
GridCurrentPage.Visibility = Visibility.Collapsed; |
349 |
GridDefinePages.Visibility = Visibility.Collapsed; |
350 |
GridRangePages.Visibility = Visibility.Collapsed; |
351 |
GridAllPages.Visibility = Visibility.Visible; |
352 |
break; |
353 |
} |
354 |
|
355 |
CheckCommentPages(); |
356 |
} |
357 |
|
358 |
private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e) |
359 |
{ |
360 |
if (_initializeComponentFinished) //GridRangePages |
361 |
{ |
362 |
if (stPageNo.Value > edPageNo.Value) |
363 |
{ |
364 |
if (sender.Equals(stPageNo)) |
365 |
edPageNo.Value = stPageNo.Value; |
366 |
else |
367 |
stPageNo.Value = edPageNo.Value; |
368 |
} |
369 |
|
370 |
//뷰어잠시제외(강인구) |
371 |
//this.LayoutRoot.Dispatcher.BeginInvoke(delegate() |
372 |
//{ |
373 |
CheckCommentPages(); |
374 |
//}); |
375 |
} |
376 |
} |
377 |
|
378 |
private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e) |
379 |
{ |
380 |
CheckCommentPages(); |
381 |
} |
382 |
|
383 |
private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e) |
384 |
{ |
385 |
txtDefinedPages.Text = ""; |
386 |
} |
387 |
|
388 |
private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
389 |
{ |
390 |
if (_initializeComponentFinished) |
391 |
if (CommentPageList.SelectedItem != null) |
392 |
this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber; |
393 |
} |
394 |
|
395 |
private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
396 |
{ |
397 |
if (_initializeComponentFinished) |
398 |
{ |
399 |
PageChanged(this.CurrentPageNo); |
400 |
} |
401 |
} |
402 |
|
403 |
#endregion |
404 |
|
405 |
public void PageChanged(int PageNo, bool Flag = false) |
406 |
{ |
407 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
408 |
{ |
409 |
Load load = new Load(); |
410 |
|
411 |
_definePages.Back_Image = new ImageBrush(); |
412 |
var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png")); |
413 |
|
414 |
printCanvas.Children.Clear(); |
415 |
|
416 |
ImageBrush background = new ImageBrush(defaultBitmapImage); |
417 |
printCanvas.Background = background; |
418 |
|
419 |
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png")); |
420 |
printCanvas.Width = image.Width; |
421 |
printCanvas.Height = image.Height; |
422 |
|
423 |
foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
424 |
{ |
425 |
load.User_Id = info.UserID; |
426 |
load.document_id = _DocInfo.DOCUMENT_ID; |
427 |
load.Page_No = PageNo; |
428 |
load.DisplayColor = info.DisplayColor; |
429 |
load.Markupinfoid = info.MarkupInfoID; |
430 |
load.Markup_Load(printCanvas); |
431 |
} |
432 |
|
433 |
printCanvas.UpdateLayout(); |
434 |
|
435 |
if(Flag) |
436 |
{ |
437 |
MemoryStream ms = new MemoryStream(); |
438 |
BmpBitmapEncoder bbe = new BmpBitmapEncoder(); |
439 |
bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png"))); |
440 |
bbe.Save(ms); |
441 |
|
442 |
Printimg = System.Drawing.Image.FromStream(ms); |
443 |
Export export = new Export(); |
444 |
p_img = export.Exporting(printCanvas, Printimg); |
445 |
Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
446 |
} |
447 |
})); |
448 |
} |
449 |
|
450 |
//Print 버튼 클릭 이벤트 |
451 |
#region Method - 명령 |
452 |
void PrintMethod(object sender, RoutedEventArgs e) |
453 |
{ |
454 |
|
455 |
if (this.printIndy.IsBusy == true) |
456 |
return; |
457 |
|
458 |
System.Threading.Tasks.Task.Factory.StartNew(() => |
459 |
{ |
460 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
461 |
{ |
462 |
this.printIndy.IsBusy = true; |
463 |
printIndy.BusyContent = "Printing. . ."; |
464 |
})); |
465 |
}); |
466 |
|
467 |
|
468 |
_lstPrintPageNo = PrintPageCreate(); |
469 |
|
470 |
if (_lstPrintPageNo.Count == 0) |
471 |
{ |
472 |
RadWindow.Alert(new DialogParameters |
473 |
{ |
474 |
Theme = new VisualStudio2013Theme(), |
475 |
Header = "안내", |
476 |
Content = "페이지가 지정되지 않았습니다." |
477 |
}); |
478 |
this.printIndy.IsBusy = false; |
479 |
return; |
480 |
} |
481 |
int cnt = 0; |
482 |
List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>(); |
483 |
|
484 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
485 |
|
486 |
foreach (int PageNo in _lstPrintPageNo) |
487 |
{ |
488 |
cnt++; |
489 |
sliderPages.Value = PageNo; |
490 |
PageChanged(PageNo, true); |
491 |
//PageChanged(cnt, true); |
492 |
} |
493 |
PrintName = cbPrint.SelectedItem.ToString(); |
494 |
|
495 |
System.Threading.Tasks.Task.Factory.StartNew(() => |
496 |
{ |
497 |
if (cnt == _lstPrintPageNo.Count) |
498 |
{ |
499 |
Printing(); |
500 |
} |
501 |
}); |
502 |
} |
503 |
|
504 |
//Export 버튼 클릭 이벤트 |
505 |
void ExportMethod(object sender, RoutedEventArgs e) |
506 |
{ |
507 |
if (this.printIndy.IsBusy == true) |
508 |
return; |
509 |
|
510 |
this.printIndy.IsBusy = true; |
511 |
printIndy.BusyContent = "Exporting. . ."; |
512 |
|
513 |
Export export = new Export(); |
514 |
_lstPrintPageNo = PrintPageCreate(); |
515 |
|
516 |
if (_lstPrintPageNo.Count == 0) |
517 |
{ |
518 |
this.printIndy.IsBusy = false; |
519 |
RadWindow.Alert(new DialogParameters |
520 |
{ |
521 |
Theme = new VisualStudio2013Theme(), |
522 |
Header = "안내", |
523 |
Content = "페이지가 지정되지 않았습니다.", |
524 |
}); |
525 |
return; |
526 |
} |
527 |
|
528 |
//FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png"); |
529 |
|
530 |
switch (cbPrint.SelectedIndex) |
531 |
{ |
532 |
case (0): |
533 |
{ |
534 |
SaveDig.Filter = "PDF file format|*.pdf"; |
535 |
break; |
536 |
} |
537 |
case (1): |
538 |
{ |
539 |
SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png"; |
540 |
break; |
541 |
} |
542 |
} |
543 |
|
544 |
SaveDig.Title = "Save an PDF File"; |
545 |
SaveDig.ShowDialog(); |
546 |
Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
547 |
|
548 |
foreach (int PageNo in _lstPrintPageNo) |
549 |
{ |
550 |
sliderPages.Value = PageNo; |
551 |
PageChanged(PageNo, true); |
552 |
} |
553 |
|
554 |
//using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
555 |
|
556 |
if (SaveDig.FileName != "") |
557 |
{ |
558 |
switch (cbPrint.SelectedIndex) |
559 |
{ |
560 |
case (0): |
561 |
{ |
562 |
using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
563 |
{ |
564 |
using (Document doc = new Document()) |
565 |
{ |
566 |
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) |
567 |
{ |
568 |
doc.Open(); |
569 |
foreach (var item in Printimg_List) |
570 |
{ |
571 |
Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png); |
572 |
Export_img.SetAbsolutePosition(0, 0); |
573 |
|
574 |
Export_img.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height); |
575 |
|
576 |
doc.NewPage(); |
577 |
doc.Add(Export_img); |
578 |
} |
579 |
doc.Close(); |
580 |
} |
581 |
} |
582 |
} |
583 |
break; |
584 |
} |
585 |
case (1): |
586 |
{ |
587 |
foreach (var item in Printimg_List) |
588 |
{ |
589 |
switch(SaveDig.FilterIndex) |
590 |
{ |
591 |
case (1): |
592 |
{ |
593 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg); |
594 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); |
595 |
} |
596 |
break; |
597 |
case (2): |
598 |
{ |
599 |
//(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png); |
600 |
(item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png); |
601 |
} |
602 |
break; |
603 |
} |
604 |
} |
605 |
break; |
606 |
} |
607 |
} |
608 |
} |
609 |
else |
610 |
{ |
611 |
this.printIndy.IsBusy = false; |
612 |
return; |
613 |
} |
614 |
|
615 |
|
616 |
|
617 |
//docWriter.EndDocument(); |
618 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
619 |
{ |
620 |
printIndy.IsBusy = false; |
621 |
})); |
622 |
PageChanged(_StartPageNo); |
623 |
|
624 |
(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert"); |
625 |
} |
626 |
#endregion |
627 |
|
628 |
#region Method - 처리 |
629 |
void CheckCommentPages() |
630 |
{ |
631 |
List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
632 |
DoubleCollection _Ticks = new DoubleCollection(); |
633 |
|
634 |
|
635 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
636 |
{ |
637 |
|
638 |
_pages = (from commPage in this._PageMarkupList |
639 |
where commPage.PageNumber == CurrentPageNo |
640 |
orderby commPage.PageNumber |
641 |
select commPage).ToList(); |
642 |
} |
643 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
644 |
{ |
645 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
646 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
647 |
|
648 |
int _stPage = (int)stPageNo.Value; |
649 |
int _edPage = (int)edPageNo.Value; |
650 |
|
651 |
_pages = (from commPage in this._PageMarkupList |
652 |
where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
653 |
orderby commPage.PageNumber |
654 |
select commPage).ToList(); |
655 |
} |
656 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
657 |
{ |
658 |
stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
659 |
edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
660 |
|
661 |
int _stPage = (int)stPageNo.Value; |
662 |
int _edPage = (int)edPageNo.Value; |
663 |
|
664 |
//Using DeepView.Common.RangeParser |
665 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
666 |
_pages = (from commPage in this._PageMarkupList |
667 |
from compareData in lst |
668 |
where commPage.PageNumber == compareData |
669 |
orderby commPage.PageNumber |
670 |
select commPage).ToList(); |
671 |
} |
672 |
else |
673 |
{ |
674 |
_pages = (from commPage in this._PageMarkupList |
675 |
orderby commPage.PageNumber |
676 |
select commPage).ToList(); |
677 |
} |
678 |
CommentPageList.ItemsSource = _pages.ToList(); |
679 |
} |
680 |
|
681 |
void SetLoadMakupList(int PageNo) |
682 |
{ |
683 |
_LoadMakupList.Clear(); |
684 |
var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
685 |
|
686 |
if (_markupList.Count() > 0) |
687 |
_LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
688 |
} |
689 |
|
690 |
#region 프린트 리스트 가져오기 |
691 |
public void GetPrint(bool flag) |
692 |
{ |
693 |
if (flag) |
694 |
{ |
695 |
foreach (string printer in PrinterSettings.InstalledPrinters) |
696 |
{ |
697 |
this.cbPrint.Items.Add(printer); |
698 |
} |
699 |
printDocument = new PrintDocument(); |
700 |
this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
701 |
} |
702 |
else |
703 |
{ |
704 |
this.cbPrint.Items.Add("PDF"); |
705 |
this.cbPrint.Items.Add("IMAGE"); |
706 |
|
707 |
this.cbPrint.SelectedItem = "PDF"; |
708 |
} |
709 |
} |
710 |
#endregion |
711 |
|
712 |
#region 프린트 실행 |
713 |
public void Printing() |
714 |
{ |
715 |
PageChanged(1); |
716 |
if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
717 |
{ |
718 |
printDocument = new PrintDocument(); |
719 |
printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
720 |
printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
721 |
printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
722 |
} |
723 |
else |
724 |
printDocument = null; |
725 |
|
726 |
#region 인쇄 미리보기 테스트 |
727 |
using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
728 |
{ |
729 |
printDocument.PrinterSettings.MinimumPage = 1; |
730 |
printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
731 |
printDocument.PrinterSettings.FromPage = 1; |
732 |
printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
733 |
|
734 |
printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
735 |
printDocument.PrinterSettings.PrinterName = PrintName; |
736 |
|
737 |
dlg.Document = printDocument; |
738 |
dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
739 |
dlg.ShowDialog(); |
740 |
} |
741 |
#endregion |
742 |
|
743 |
#region 인쇄 |
744 |
//printDocument.PrinterSettings.MinimumPage = 1; |
745 |
//printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
746 |
//printDocument.PrinterSettings.FromPage = 1; |
747 |
//printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
748 |
|
749 |
//printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
750 |
//printDocument.PrinterSettings.PrinterName = PrintName; |
751 |
|
752 |
//printDocument.Print(); |
753 |
#endregion |
754 |
} |
755 |
|
756 |
private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
757 |
{ |
758 |
//Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
759 |
// This demo only loads one page at a time, so no need to re-set the print page number |
760 |
PrintDocument document = sender as PrintDocument; |
761 |
currentPage = document.PrinterSettings.FromPage; |
762 |
} |
763 |
|
764 |
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
765 |
{ |
766 |
//e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0); |
767 |
|
768 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
769 |
{ |
770 |
p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
771 |
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg); |
772 |
System.Drawing.Rectangle m = e.MarginBounds; |
773 |
|
774 |
if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider |
775 |
{ |
776 |
m.Height = (int)((double)pic.Height / (double)pic.Width * (double)m.Width); |
777 |
} |
778 |
else |
779 |
{ |
780 |
m.Width = (int)((double)pic.Width / (double)pic.Height * (double)m.Height); |
781 |
} |
782 |
|
783 |
e.Graphics.DrawImage(p_img, m); |
784 |
//e.Graphics.DrawImage(p_img, e.MarginBounds); |
785 |
//e.Graphics.DrawImage(p_img, 0, 0); |
786 |
|
787 |
|
788 |
})); |
789 |
|
790 |
//다음 페이지 |
791 |
currentPage++; |
792 |
|
793 |
////인쇄를 계속 할지 말지 확인 |
794 |
if (currentPage <= printDocument.PrinterSettings.ToPage) |
795 |
e.HasMorePages = true; |
796 |
else |
797 |
e.HasMorePages = false; |
798 |
|
799 |
} |
800 |
|
801 |
private void printDocument_EndPrint(object sender, PrintEventArgs e) |
802 |
{ |
803 |
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
804 |
{ |
805 |
printIndy.IsBusy = false; |
806 |
})); |
807 |
} |
808 |
#endregion |
809 |
|
810 |
#region Selected Pages Check |
811 |
List<int> PrintPageCreate() |
812 |
{ |
813 |
List<int> Result = new List<int>(); |
814 |
|
815 |
if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
816 |
{ |
817 |
Result.Add(CurrentPageNo); |
818 |
} |
819 |
else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
820 |
{ |
821 |
for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
822 |
{ |
823 |
Result.Add(i); |
824 |
} |
825 |
} |
826 |
else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
827 |
{ |
828 |
int _stPage = (int)stPageNo.Value; |
829 |
int _edPage = (int)edPageNo.Value; |
830 |
|
831 |
var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
832 |
Result.AddRange(lst); |
833 |
} |
834 |
else |
835 |
{ |
836 |
for (int i = 1; i <= _definePages.PagesCount; i++) |
837 |
{ |
838 |
Result.Add(i); |
839 |
} |
840 |
} |
841 |
if (currentPagePrint) |
842 |
{ |
843 |
return Result; |
844 |
} |
845 |
|
846 |
if (chkOnlyMarkup.IsChecked.Value) |
847 |
{ |
848 |
var _result = from result in Result |
849 |
where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
850 |
select result; |
851 |
Result = _result.ToList(); |
852 |
} |
853 |
return Result; |
854 |
} |
855 |
#endregion |
856 |
|
857 |
#endregion |
858 |
} |
859 |
} |