markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ faebcce2
이력 | 보기 | 이력해설 | 다운로드 (78.4 KB)
1 |
using IFinalPDF; |
---|---|
2 |
using iTextSharp.text.pdf; |
3 |
using KCOMDataModel.Common; |
4 |
using KCOMDataModel.DataModel; |
5 |
using MarkupToPDF.Controls.Common; |
6 |
using MarkupToPDF.Serialize.Core; |
7 |
using MarkupToPDF.Serialize.S_Control; |
8 |
using Markus.Fonts; |
9 |
using System; |
10 |
using System.Collections.Generic; |
11 |
using System.Configuration; |
12 |
using System.IO; |
13 |
using System.Linq; |
14 |
using System.Net; |
15 |
using System.Runtime.InteropServices; |
16 |
using System.Text; |
17 |
using System.Web; |
18 |
using System.Windows; |
19 |
using System.Windows.Media; |
20 |
|
21 |
namespace MarkupToPDF |
22 |
{ |
23 |
public class MarkupToPDF : IDisposable |
24 |
{ |
25 |
#region 초기 데이터 |
26 |
private static iTextSharp.text.Rectangle mediaBox; |
27 |
private FileInfo PdfFilePath = null; |
28 |
private FileInfo FinalPDFPath = null; |
29 |
private string _FinalPDFStorgeLocal = null; |
30 |
private string _FinalPDFStorgeRemote = null; |
31 |
private string OriginFileName = null; |
32 |
public FINAL_PDF FinalItem; |
33 |
public DOCINFO DocInfoItem = null; |
34 |
public List<DOCPAGE> DocPageItem = null; |
35 |
public MARKUP_INFO MarkupInfoItem = null; |
36 |
public List<MARKUP_DATA> MarkupDataSet = null; |
37 |
//private string _PrintPDFStorgeLocal = null; |
38 |
//private string _PrintPDFStorgeRemote = null; |
39 |
public event EventHandler<MakeFinalErrorArgs> FinalMakeError; |
40 |
public event EventHandler<EndFinalEventArgs> EndFinal; |
41 |
public event EventHandler<StatusChangedEventArgs> StatusChanged; |
42 |
|
43 |
private iTextSharp.text.Rectangle pdfSize { get; set; } |
44 |
private double pageW = 0; |
45 |
private double pageH = 0; |
46 |
|
47 |
//private const double zoomLevel = 3.0; |
48 |
private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음 |
49 |
#endregion |
50 |
|
51 |
#region 메서드 |
52 |
public static bool IsLocalIPAddress(string host) |
53 |
{ |
54 |
try |
55 |
{ |
56 |
IPAddress[] hostIPs = Dns.GetHostAddresses(host); |
57 |
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); |
58 |
|
59 |
foreach (IPAddress hostIP in hostIPs) |
60 |
{ |
61 |
if (IPAddress.IsLoopback(hostIP)) return true; |
62 |
|
63 |
foreach (IPAddress localIP in localIPs) |
64 |
{ |
65 |
if (hostIP.Equals(localIP)) return true; |
66 |
} |
67 |
} |
68 |
} |
69 |
catch { } |
70 |
return false; |
71 |
} |
72 |
|
73 |
private void SetNotice(string finalID, string message) |
74 |
{ |
75 |
if (FinalMakeError != null) |
76 |
{ |
77 |
FinalMakeError(this, new MakeFinalErrorArgs { FinalID = finalID, Message = message }); |
78 |
} |
79 |
} |
80 |
|
81 |
private string GetFileName(string hrefLink) |
82 |
{ |
83 |
try |
84 |
{ |
85 |
if (hrefLink.Contains("vpcs_doclib")) |
86 |
{ |
87 |
return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\")); |
88 |
} |
89 |
else |
90 |
{ |
91 |
Uri fileurl = new Uri(hrefLink); |
92 |
int index = hrefLink.IndexOf("?"); |
93 |
string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName"); |
94 |
return filename; |
95 |
} |
96 |
} |
97 |
catch (Exception ex) |
98 |
{ |
99 |
throw ex; |
100 |
} |
101 |
} |
102 |
|
103 |
public Point GetPdfPointSystem(Point point) |
104 |
{ |
105 |
/// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다. |
106 |
/// Rotation 90 일 경우 pdfsize box 와 media box 가 달라 다른 계산식 적용 |
107 |
if (pdfSize.Rotation == 90) |
108 |
{ |
109 |
return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom); |
110 |
} |
111 |
else |
112 |
{ |
113 |
return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Height - (float)(point.Y / scaleHeight) + pdfSize.Bottom); |
114 |
} |
115 |
} |
116 |
|
117 |
public double GetPdfSize(double size) |
118 |
{ |
119 |
return (size / scaleWidth); |
120 |
} |
121 |
|
122 |
public List<Point> GetPdfPointSystem(List<Point> point) |
123 |
{ |
124 |
List<Point> dummy = new List<Point>(); |
125 |
foreach (var item in point) |
126 |
{ |
127 |
dummy.Add(GetPdfPointSystem(item)); |
128 |
} |
129 |
return dummy; |
130 |
} |
131 |
|
132 |
public double returnAngle(Point start, Point end) |
133 |
{ |
134 |
double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y); |
135 |
//angle *= -1; |
136 |
|
137 |
angle += 90; |
138 |
//if (angle < 0) |
139 |
//{ |
140 |
// angle = angle + 360; |
141 |
//} |
142 |
return angle; |
143 |
} |
144 |
|
145 |
#endregion |
146 |
|
147 |
public bool AddStamp(string stampData) |
148 |
{ |
149 |
bool result = false; |
150 |
|
151 |
try |
152 |
{ |
153 |
using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
154 |
{ |
155 |
var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP"); |
156 |
|
157 |
if(stamp.Count() > 0) |
158 |
{ |
159 |
var xamldata = Serialize.Core.JsonSerializerHelper.CompressStamp(stampData); |
160 |
|
161 |
stamp.First().VALUE = xamldata; |
162 |
_entity.SaveChanges(); |
163 |
result = true; |
164 |
} |
165 |
} |
166 |
} |
167 |
catch (Exception) |
168 |
{ |
169 |
|
170 |
throw; |
171 |
} |
172 |
|
173 |
return result; |
174 |
|
175 |
} |
176 |
|
177 |
/// <summary> |
178 |
/// local에서 final 생성하는 경우 이 함수로 추가 후 실행 |
179 |
/// </summary> |
180 |
/// <param name="finalpdf"></param> |
181 |
/// <returns></returns> |
182 |
public AddFinalPDFResult AddFinalPDF(string ProjectNo,string DocumentID,string UserID) |
183 |
{ |
184 |
//var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS"); |
185 |
//System.Diagnostics.Debug.WriteLine(list); |
186 |
|
187 |
AddFinalPDFResult result = new AddFinalPDFResult { Success = false }; |
188 |
|
189 |
try |
190 |
{ |
191 |
FINAL_PDF addItem = new FINAL_PDF{ |
192 |
ID = CommonLib.Guid.shortGuid(), |
193 |
PROJECT_NO = ProjectNo, |
194 |
DOCUMENT_ID = DocumentID, |
195 |
CREATE_USER_ID = UserID, |
196 |
CREATE_DATETIME = DateTime.Now, |
197 |
STATUS = 4 |
198 |
}; |
199 |
|
200 |
using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString())) |
201 |
{ |
202 |
var docitems = _entity.DOCINFO.Where(x => x.PROJECT_NO == ProjectNo && x.DOCUMENT_ID == DocumentID); |
203 |
|
204 |
if(docitems.Count() > 0) |
205 |
{ |
206 |
addItem.DOCINFO_ID = docitems.First().ID; |
207 |
result.Success = true; |
208 |
} |
209 |
else |
210 |
{ |
211 |
result.Exception = "docInfo Not Found."; |
212 |
result.Success = false; |
213 |
} |
214 |
|
215 |
var markupInfoItems = _entity.MARKUP_INFO.Where(x =>x.DOCINFO_ID == addItem.DOCINFO_ID); |
216 |
|
217 |
if (markupInfoItems.Count() > 0) |
218 |
{ |
219 |
addItem.MARKUPINFO_ID = markupInfoItems.First().ID; |
220 |
result.Success = true; |
221 |
} |
222 |
else |
223 |
{ |
224 |
result.Exception = "Markup Info Not Found."; |
225 |
result.Success = false; |
226 |
} |
227 |
} |
228 |
|
229 |
if (result.Success) |
230 |
{ |
231 |
using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
232 |
{ |
233 |
var finalList = _entity.FINAL_PDF.Where(final => final.ID == addItem.ID); |
234 |
|
235 |
/// Insrt and Update |
236 |
if (finalList.Count() == 0) |
237 |
{ |
238 |
_entity.FINAL_PDF.AddObject(addItem); |
239 |
_entity.SaveChanges(); |
240 |
|
241 |
result.FinalPDF = addItem; |
242 |
result.Success = true; |
243 |
} |
244 |
} |
245 |
} |
246 |
} |
247 |
catch (Exception ex) |
248 |
{ |
249 |
System.Diagnostics.Debug.WriteLine(ex); |
250 |
result.Success = false; |
251 |
} |
252 |
|
253 |
return result; |
254 |
} |
255 |
|
256 |
#region 생성자 & 소멸자 |
257 |
public void MakeFinalPDF(object _FinalPDF) |
258 |
{ |
259 |
DOCUMENT_ITEM documentItem; |
260 |
FINAL_PDF FinalPDF = (FINAL_PDF)_FinalPDF; |
261 |
FinalItem = FinalPDF; |
262 |
|
263 |
|
264 |
string PdfFilePathRoot = null; |
265 |
string TestFile = System.IO.Path.GetTempFileName(); |
266 |
|
267 |
#region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정 |
268 |
try |
269 |
{ |
270 |
using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
271 |
{ |
272 |
var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO); |
273 |
|
274 |
if (_properties.Count() > 0) |
275 |
{ |
276 |
if (_properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).Count() == 0) |
277 |
{ |
278 |
SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found."); |
279 |
return; |
280 |
} |
281 |
else |
282 |
{ |
283 |
PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE; |
284 |
} |
285 |
|
286 |
if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).Count() == 0) |
287 |
{ |
288 |
SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found."); |
289 |
return; |
290 |
} |
291 |
else |
292 |
{ |
293 |
_FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE; |
294 |
} |
295 |
|
296 |
|
297 |
if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).Count() == 0) |
298 |
{ |
299 |
SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found."); |
300 |
return; |
301 |
} |
302 |
else |
303 |
{ |
304 |
_FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE; |
305 |
} |
306 |
} |
307 |
else |
308 |
{ |
309 |
SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found."); |
310 |
return; |
311 |
} |
312 |
|
313 |
var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID); |
314 |
|
315 |
if (finalList.Count() > 0) |
316 |
{ |
317 |
finalList.FirstOrDefault().START_DATETIME = DateTime.Now; |
318 |
finalList.FirstOrDefault().STATUS = (int)FinalStatus.Create; |
319 |
_entity.SaveChanges(); |
320 |
} |
321 |
|
322 |
} |
323 |
} |
324 |
catch (Exception ex) |
325 |
{ |
326 |
SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString()); |
327 |
return; |
328 |
} |
329 |
#endregion |
330 |
|
331 |
#region 문서 복사 |
332 |
try |
333 |
{ |
334 |
using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString())) |
335 |
{ |
336 |
var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID); |
337 |
|
338 |
if (_DOCINFO.Count() > 0) |
339 |
{ |
340 |
DocInfoItem = _DOCINFO.FirstOrDefault(); |
341 |
DocPageItem = DocInfoItem.DOCPAGE.ToList(); |
342 |
|
343 |
PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\" |
344 |
+ (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5)) |
345 |
+ @"\" + FinalPDF.DOCUMENT_ID + @"\"; |
346 |
|
347 |
MarkupInfoItem = DocInfoItem.MARKUP_INFO.Where(data => data.CONSOLIDATE == 1 && data.AVOID_CONSOLIDATE == 0 && data.PART_CONSOLIDATE == 0).FirstOrDefault(); |
348 |
|
349 |
if (MarkupInfoItem == null) |
350 |
{ |
351 |
throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다"); |
352 |
} |
353 |
else |
354 |
{ |
355 |
if (MarkupInfoItem.MARKUP_INFO_VERSION.Count > 0) |
356 |
{ |
357 |
MarkupDataSet = MarkupInfoItem.MARKUP_INFO_VERSION.OrderBy(d => d.CREATE_DATE).LastOrDefault().MARKUP_DATA.ToList().OrderBy(d => d.PAGENUMBER).ToList(); |
358 |
} |
359 |
else |
360 |
{ |
361 |
throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다"); |
362 |
} |
363 |
} |
364 |
|
365 |
documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault(); |
366 |
if (documentItem == null) |
367 |
{ |
368 |
throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요"); |
369 |
} |
370 |
|
371 |
var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 |
372 |
|
373 |
#region 파일 체크 |
374 |
if (_files.Count() == 1) |
375 |
{ |
376 |
/// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정 |
377 |
//if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower())) |
378 |
//{ |
379 |
OriginFileName = _files.First().Name; |
380 |
PdfFilePath = _files.First().CopyTo(TestFile, true); |
381 |
StatusChange($"Copy File file Count = 1 : {PdfFilePath}", 0); |
382 |
//} |
383 |
//else |
384 |
//{ |
385 |
// throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()); |
386 |
//} |
387 |
} |
388 |
else if (_files.Count() > 1) |
389 |
{ |
390 |
var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault(); |
391 |
|
392 |
if (originalFile == null) |
393 |
{ |
394 |
throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다"); |
395 |
} |
396 |
else |
397 |
{ |
398 |
OriginFileName = originalFile.Name; |
399 |
PdfFilePath = originalFile.CopyTo(TestFile, true); |
400 |
StatusChange($"Copy File file Count > 1 : {PdfFilePath}", 0); |
401 |
} |
402 |
} |
403 |
else |
404 |
{ |
405 |
throw new FileNotFoundException("PDF를 찾지 못하였습니다"); |
406 |
} |
407 |
#endregion |
408 |
|
409 |
#region 예외처리 |
410 |
if (PdfFilePath == null) |
411 |
{ |
412 |
throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다"); |
413 |
} |
414 |
if (!PdfFilePath.Exists) |
415 |
{ |
416 |
throw new Exception("PDF원본이 존재하지 않습니다"); |
417 |
} |
418 |
#endregion |
419 |
|
420 |
} |
421 |
else |
422 |
{ |
423 |
throw new Exception("일치하는 DocInfo가 없습니다"); |
424 |
} |
425 |
} |
426 |
} |
427 |
catch (Exception ex) |
428 |
{ |
429 |
if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다") |
430 |
{ |
431 |
SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다"); |
432 |
System.Diagnostics.Process process = new System.Diagnostics.Process(); |
433 |
process.StartInfo.FileName = "cmd"; |
434 |
process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\""; |
435 |
process.Start(); |
436 |
} |
437 |
else |
438 |
{ |
439 |
SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message); |
440 |
} |
441 |
} |
442 |
#endregion |
443 |
|
444 |
try |
445 |
{ |
446 |
|
447 |
using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
448 |
{ |
449 |
var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID); |
450 |
|
451 |
if (finalList.Count() > 0) |
452 |
{ |
453 |
//TestFile = SetFlattingPDF(TestFile); |
454 |
//StatusChange($"SetFlattingPDF : {TestFile}", 0); |
455 |
|
456 |
SetStampInPDF(FinalItem, TestFile, MarkupInfoItem); |
457 |
|
458 |
StatusChange($"SetStampInPDF : {TestFile}", 0); |
459 |
} |
460 |
} |
461 |
if (EndFinal != null) |
462 |
{ |
463 |
EndFinal(this, new EndFinalEventArgs |
464 |
{ |
465 |
OriginPDFName = OriginFileName, |
466 |
FinalPDFPath = FinalPDFPath.FullName, |
467 |
Error = "", |
468 |
Message = "", |
469 |
FinalPDF = FinalPDF, |
470 |
}); |
471 |
} |
472 |
} |
473 |
catch (Exception ex) |
474 |
{ |
475 |
throw new Exception(ex.ToString() + ex.InnerException?.ToString()); |
476 |
} |
477 |
} |
478 |
#endregion |
479 |
|
480 |
#region PDF |
481 |
public static float scaleWidth = 0; |
482 |
public static float scaleHeight = 0; |
483 |
|
484 |
private string SetFlattingPDF(string tempFileInfo) |
485 |
{ |
486 |
if (File.Exists(tempFileInfo)) |
487 |
{ |
488 |
FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName()); |
489 |
|
490 |
PdfReader pdfReader = new PdfReader(tempFileInfo); |
491 |
|
492 |
for (int i = 1; i <= pdfReader.NumberOfPages; i++) |
493 |
{ |
494 |
var mediaBox = pdfReader.GetPageSize(i); |
495 |
var cropbox = pdfReader.GetCropBox(i); |
496 |
|
497 |
//using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString())) |
498 |
//{ |
499 |
// _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE) |
500 |
//} |
501 |
var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault(); |
502 |
|
503 |
//scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width; |
504 |
//scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height; |
505 |
//scaleWidth = 2.0832634F; |
506 |
//scaleHeight = 3.0F; |
507 |
|
508 |
PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i)); |
509 |
//강인구 수정 |
510 |
//if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height)) |
511 |
//if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height)) |
512 |
//{ |
513 |
// var pageDict = pdfReader.GetPageN(i); |
514 |
// pageDict.Put(PdfName.MEDIABOX, rect); |
515 |
//} |
516 |
} |
517 |
|
518 |
var memStream = new MemoryStream(); |
519 |
var stamper = new PdfStamper(pdfReader, memStream) |
520 |
{ |
521 |
FormFlattening = true, |
522 |
//FreeTextFlattening = true, |
523 |
//AnnotationFlattening = true, |
524 |
}; |
525 |
|
526 |
stamper.Close(); |
527 |
pdfReader.Close(); |
528 |
var array = memStream.ToArray(); |
529 |
File.Delete(tempFileInfo); |
530 |
File.WriteAllBytes(TestFile.FullName, array); |
531 |
|
532 |
return TestFile.FullName; |
533 |
} |
534 |
else |
535 |
{ |
536 |
return tempFileInfo; |
537 |
} |
538 |
} |
539 |
|
540 |
public void flattenPdfFile(string src, ref string dest) |
541 |
{ |
542 |
PdfReader reader = new PdfReader(src); |
543 |
var memStream = new MemoryStream(); |
544 |
var stamper = new PdfStamper(reader, memStream) |
545 |
{ |
546 |
FormFlattening = true, |
547 |
FreeTextFlattening = true, |
548 |
AnnotationFlattening = true, |
549 |
}; |
550 |
|
551 |
stamper.Close(); |
552 |
var array = memStream.ToArray(); |
553 |
File.WriteAllBytes(dest, array); |
554 |
} |
555 |
|
556 |
public void StatusChange(string message,int CurrentPage) |
557 |
{ |
558 |
if(StatusChanged != null) |
559 |
{ |
560 |
var sb = new StringBuilder(); |
561 |
sb.AppendLine(message); |
562 |
|
563 |
StatusChanged(null, new StatusChangedEventArgs { CurrentPage = CurrentPage, Message = sb.ToString() }); |
564 |
} |
565 |
} |
566 |
|
567 |
public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo) |
568 |
{ |
569 |
try |
570 |
{ |
571 |
|
572 |
FileInfo tempFileInfo = new FileInfo(testFile); |
573 |
|
574 |
if (!Directory.Exists(_FinalPDFStorgeLocal)) |
575 |
{ |
576 |
Directory.CreateDirectory(_FinalPDFStorgeLocal); |
577 |
} |
578 |
string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name); |
579 |
|
580 |
|
581 |
using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
582 |
{ |
583 |
FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault(); |
584 |
|
585 |
#region 코멘트 적용 + 커버시트 |
586 |
using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) // |
587 |
{ |
588 |
StatusChange("comment Cover",0); |
589 |
|
590 |
PdfReader pdfReader = new PdfReader(pdfStream); |
591 |
//List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>(); |
592 |
Dictionary<string, object> bookmark; |
593 |
List<Dictionary<string, object>> outlines; |
594 |
|
595 |
outlines = new List<Dictionary<string, object>>(); |
596 |
List<Dictionary<string, object>> root = new List<Dictionary<string, object>>(); |
597 |
|
598 |
var dic = new Dictionary<string, object>(); |
599 |
|
600 |
foreach (var data in MarkupDataSet) |
601 |
{ |
602 |
StatusChange("MarkupDataSet", 0); |
603 |
|
604 |
string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID; |
605 |
|
606 |
string username = ""; |
607 |
string userdept = ""; |
608 |
|
609 |
using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString())) |
610 |
{ |
611 |
var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid); |
612 |
|
613 |
if(memberlist.Count() > 0) |
614 |
{ |
615 |
username = memberlist.First().NAME; |
616 |
userdept = memberlist.First().DEPARTMENT; |
617 |
} |
618 |
} |
619 |
|
620 |
bookmark = new Dictionary<string, object>(); |
621 |
bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER)); |
622 |
bookmark.Add("Page", data.PAGENUMBER + " Fit"); |
623 |
bookmark.Add("Action", "GoTo"); |
624 |
bookmark.Add("Kids", outlines); |
625 |
root.Add(bookmark); |
626 |
} |
627 |
|
628 |
|
629 |
using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create))) |
630 |
{ |
631 |
AcroFields pdfFormFields = pdfStamper.AcroFields; |
632 |
pdfFormFields.GenerateAppearances = true; |
633 |
|
634 |
var _SetColor = new SolidColorBrush(Colors.Red); |
635 |
|
636 |
string[] delimiterChars = { "|DZ|" }; |
637 |
string[] delimiterChars2 = { "|" }; |
638 |
|
639 |
//pdfStamper.FormFlattening = true; //이미 선처리 작업함 |
640 |
pdfStamper.SetFullCompression(); |
641 |
_SetColor = new SolidColorBrush(Colors.Red); |
642 |
|
643 |
foreach (var markupItem in MarkupDataSet) |
644 |
{ |
645 |
pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER); |
646 |
var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER).FirstOrDefault(); |
647 |
|
648 |
mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER); |
649 |
var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER); |
650 |
|
651 |
/// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다 |
652 |
if (cropBox != null && |
653 |
(cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom)) |
654 |
{ |
655 |
PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER); |
656 |
|
657 |
PdfArray oNewMediaBox = new PdfArray(); |
658 |
oNewMediaBox.Add(new PdfNumber(cropBox.Left)); |
659 |
oNewMediaBox.Add(new PdfNumber(cropBox.Top)); |
660 |
oNewMediaBox.Add(new PdfNumber(cropBox.Right)); |
661 |
oNewMediaBox.Add(new PdfNumber(cropBox.Bottom)); |
662 |
dict.Put(PdfName.MEDIABOX, oNewMediaBox); |
663 |
|
664 |
pdfSize = cropBox; |
665 |
} |
666 |
scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width; |
667 |
scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height; |
668 |
|
669 |
pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER; |
670 |
_entity.SaveChanges(); |
671 |
|
672 |
string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
673 |
|
674 |
PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER); |
675 |
|
676 |
|
677 |
foreach (var data in markedData) |
678 |
{ |
679 |
var item = JsonSerializerHelper.UnCompressString(data); |
680 |
var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); |
681 |
|
682 |
try |
683 |
{ |
684 |
switch (ControlT.Name) |
685 |
{ |
686 |
#region LINE |
687 |
case "LineControl": |
688 |
{ |
689 |
using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item)) |
690 |
{ |
691 |
string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
692 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
693 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
694 |
DoubleCollection DashSize = control.DashSize; |
695 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
696 |
|
697 |
var Opacity = control.Opac; |
698 |
string UserID = control.UserID; |
699 |
double Interval = control.Interval; |
700 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
701 |
Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, _SetColor, Opacity); |
702 |
switch (control.LineStyleSet) |
703 |
{ |
704 |
case LineStyleSet.ArrowLine: |
705 |
Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
706 |
break; |
707 |
case LineStyleSet.CancelLine: |
708 |
{ |
709 |
var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X))); |
710 |
var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y))); |
711 |
|
712 |
if (x > y) |
713 |
{ |
714 |
StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0)); |
715 |
EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0)); |
716 |
Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, Opacity); |
717 |
} |
718 |
} |
719 |
break; |
720 |
case LineStyleSet.TwinLine: |
721 |
{ |
722 |
Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
723 |
Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
724 |
} |
725 |
break; |
726 |
case LineStyleSet.DimLine: |
727 |
{ |
728 |
Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
729 |
Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
730 |
Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
731 |
} |
732 |
break; |
733 |
default: |
734 |
break; |
735 |
} |
736 |
|
737 |
|
738 |
} |
739 |
} |
740 |
break; |
741 |
#endregion |
742 |
#region ArrowControlMulti |
743 |
case "ArrowControl_Multi": |
744 |
{ |
745 |
using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item)) |
746 |
{ |
747 |
string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
748 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
749 |
Point MidPoint = GetPdfPointSystem(control.MidPoint); |
750 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
751 |
DoubleCollection DashSize = control.DashSize; |
752 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
753 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
754 |
|
755 |
double Opacity = control.Opac; |
756 |
|
757 |
if (EndPoint == MidPoint) |
758 |
{ |
759 |
Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
760 |
} |
761 |
else |
762 |
{ |
763 |
Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
764 |
} |
765 |
|
766 |
Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
767 |
|
768 |
} |
769 |
} |
770 |
break; |
771 |
#endregion |
772 |
#region PolyControl |
773 |
case "PolygonControl": |
774 |
using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item)) |
775 |
{ |
776 |
string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
777 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
778 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
779 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
780 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
781 |
double Opacity = control.Opac; |
782 |
DoubleCollection DashSize = control.DashSize; |
783 |
|
784 |
Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
785 |
} |
786 |
break; |
787 |
#endregion |
788 |
#region ArcControl or ArrowArcControl |
789 |
case "ArcControl": |
790 |
case "ArrowArcControl": |
791 |
{ |
792 |
using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item)) |
793 |
{ |
794 |
string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
795 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
796 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
797 |
Point MidPoint = GetPdfPointSystem(control.MidPoint); |
798 |
DoubleCollection DashSize = control.DashSize; |
799 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
800 |
|
801 |
var Opacity = control.Opac; |
802 |
string UserID = control.UserID; |
803 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
804 |
bool IsTransOn = control.IsTransOn; |
805 |
|
806 |
if (control.IsTransOn) |
807 |
{ |
808 |
Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
809 |
Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
810 |
} |
811 |
else |
812 |
{ |
813 |
Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity); |
814 |
} |
815 |
|
816 |
if (ControlT.Name == "ArrowArcControl") |
817 |
{ |
818 |
Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
819 |
Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
820 |
} |
821 |
} |
822 |
} |
823 |
break; |
824 |
#endregion |
825 |
#region RectangleControl |
826 |
case "RectangleControl": |
827 |
using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item)) |
828 |
{ |
829 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
830 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
831 |
var PaintStyle = control.PaintState; |
832 |
double Angle = control.Angle; |
833 |
DoubleCollection DashSize = control.DashSize; |
834 |
double Opacity = control.Opac; |
835 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
836 |
|
837 |
Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
838 |
} |
839 |
break; |
840 |
#endregion |
841 |
#region TriControl |
842 |
case "TriControl": |
843 |
using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item)) |
844 |
{ |
845 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
846 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
847 |
var PaintStyle = control.Paint; |
848 |
double Angle = control.Angle; |
849 |
//StrokeColor = _SetColor, //색상은 레드 |
850 |
DoubleCollection DashSize = control.DashSize; |
851 |
double Opacity = control.Opac; |
852 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
853 |
|
854 |
Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
855 |
} |
856 |
break; |
857 |
#endregion |
858 |
#region CircleControl |
859 |
case "CircleControl": |
860 |
using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item)) |
861 |
{ |
862 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
863 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
864 |
var StartPoint = GetPdfPointSystem(control.StartPoint); |
865 |
var EndPoint = GetPdfPointSystem(control.EndPoint); |
866 |
var PaintStyle = control.PaintState; |
867 |
double Angle = control.Angle; |
868 |
DoubleCollection DashSize = control.DashSize; |
869 |
double Opacity = control.Opac; |
870 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
871 |
Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet); |
872 |
|
873 |
} |
874 |
break; |
875 |
#endregion |
876 |
#region RectCloudControl |
877 |
case "RectCloudControl": |
878 |
using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item)) |
879 |
{ |
880 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
881 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
882 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
883 |
double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
884 |
|
885 |
double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
886 |
|
887 |
var PaintStyle = control.PaintState; |
888 |
double Opacity = control.Opac; |
889 |
DoubleCollection DashSize = control.DashSize; |
890 |
|
891 |
//드로잉 방식이 표현되지 않음 |
892 |
var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
893 |
|
894 |
double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
895 |
bool reverse = (area < 0); |
896 |
if (PaintStyle == PaintSet.None) |
897 |
{ |
898 |
Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
899 |
} |
900 |
else |
901 |
{ |
902 |
Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
903 |
} |
904 |
} |
905 |
break; |
906 |
#endregion |
907 |
#region CloudControl |
908 |
case "CloudControl": |
909 |
using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item)) |
910 |
{ |
911 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
912 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
913 |
double Toler = control.Toler; |
914 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
915 |
double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
916 |
var PaintStyle = control.PaintState; |
917 |
double Opacity = control.Opac; |
918 |
bool isTransOn = control.IsTrans; |
919 |
bool isChain = control.IsChain; |
920 |
|
921 |
DoubleCollection DashSize = control.DashSize; |
922 |
|
923 |
if (isChain) |
924 |
{ |
925 |
Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
926 |
} |
927 |
else |
928 |
{ |
929 |
if (isTransOn) |
930 |
{ |
931 |
double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
932 |
bool reverse = (area < 0); |
933 |
|
934 |
if (PaintStyle == PaintSet.None) |
935 |
{ |
936 |
Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
937 |
} |
938 |
else |
939 |
{ |
940 |
Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
941 |
} |
942 |
} |
943 |
else |
944 |
{ |
945 |
Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity); |
946 |
} |
947 |
} |
948 |
} |
949 |
break; |
950 |
#endregion |
951 |
#region TEXT |
952 |
case "TextControl": |
953 |
using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item)) |
954 |
{ |
955 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
956 |
string Text = control.Text; |
957 |
|
958 |
bool isUnderline = false; |
959 |
control.BoxW -= scaleWidth; |
960 |
control.BoxH -= scaleHeight; |
961 |
System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH); |
962 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
963 |
Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH)); |
964 |
|
965 |
List<Point> pointSet = new List<Point>(); |
966 |
pointSet.Add(StartPoint); |
967 |
pointSet.Add(EndPoint); |
968 |
|
969 |
PaintSet paint = PaintSet.None; |
970 |
switch (control.paintMethod) |
971 |
{ |
972 |
case 1: |
973 |
{ |
974 |
paint = PaintSet.Fill; |
975 |
} |
976 |
break; |
977 |
case 2: |
978 |
{ |
979 |
paint = PaintSet.Hatch; |
980 |
} |
981 |
break; |
982 |
default: |
983 |
break; |
984 |
} |
985 |
if (control.isHighLight) paint |= PaintSet.Highlight; |
986 |
|
987 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
988 |
double TextSize = Convert.ToDouble(data2[1]); |
989 |
SolidColorBrush FontColor = _SetColor; |
990 |
double Angle = control.Angle; |
991 |
double Opacity = control.Opac; |
992 |
FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]); |
993 |
var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
994 |
|
995 |
FontStyle fontStyle = FontStyles.Normal; |
996 |
if (FontStyles.Italic == TextStyle) |
997 |
{ |
998 |
fontStyle = FontStyles.Italic; |
999 |
} |
1000 |
|
1001 |
FontWeight fontWeight = FontWeights.Black; |
1002 |
|
1003 |
var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
1004 |
//강인구 수정(2018.04.17) |
1005 |
if (FontWeights.Bold == TextWeight) |
1006 |
//if (FontWeights.ExtraBold == TextWeight) |
1007 |
{ |
1008 |
fontWeight = FontWeights.Bold; |
1009 |
} |
1010 |
|
1011 |
TextDecorationCollection decoration = TextDecorations.Baseline; |
1012 |
if (control.fontConfig.Count() == 4) |
1013 |
{ |
1014 |
decoration = TextDecorations.Underline; |
1015 |
} |
1016 |
|
1017 |
Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, _SetColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
1018 |
} |
1019 |
break; |
1020 |
#endregion |
1021 |
#region ArrowTextControl |
1022 |
case "ArrowTextControl": |
1023 |
using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item)) |
1024 |
{ |
1025 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
1026 |
Point tempStartPoint = GetPdfPointSystem(control.StartPoint); |
1027 |
Point tempMidPoint = GetPdfPointSystem(control.MidPoint); |
1028 |
Point tempEndPoint = GetPdfPointSystem(control.EndPoint); |
1029 |
bool isUnderLine = false; |
1030 |
string Text = ""; |
1031 |
double fontsize = 30; |
1032 |
|
1033 |
System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight); |
1034 |
Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight)); |
1035 |
List<Point> tempPoint = new List<Point>(); |
1036 |
|
1037 |
var tempRectMidPoint = MathSet.getRectMiddlePoint(rect); |
1038 |
|
1039 |
tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y)); |
1040 |
tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top)); |
1041 |
tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y)); |
1042 |
tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom)); |
1043 |
double Angle = control.Angle; |
1044 |
var newStartPoint = tempStartPoint; |
1045 |
var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint); |
1046 |
var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint); |
1047 |
|
1048 |
double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
1049 |
SolidColorBrush FontColor = _SetColor; |
1050 |
bool isHighlight = control.isHighLight; |
1051 |
double Opacity = control.Opac; |
1052 |
PaintSet Paint = PaintSet.None; |
1053 |
|
1054 |
switch (control.ArrowStyle) |
1055 |
{ |
1056 |
case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal: |
1057 |
{ |
1058 |
Paint = PaintSet.None; |
1059 |
} |
1060 |
break; |
1061 |
case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud: |
1062 |
{ |
1063 |
Paint = PaintSet.Hatch; |
1064 |
} |
1065 |
break; |
1066 |
case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect: |
1067 |
{ |
1068 |
Paint = PaintSet.Fill; |
1069 |
} |
1070 |
break; |
1071 |
default: |
1072 |
break; |
1073 |
} |
1074 |
if (control.isHighLight) Paint |= PaintSet.Highlight; |
1075 |
|
1076 |
if (Paint == PaintSet.Hatch) |
1077 |
{ |
1078 |
Text = control.ArrowText; |
1079 |
} |
1080 |
else |
1081 |
{ |
1082 |
Text = control.ArrowText; |
1083 |
} |
1084 |
|
1085 |
try |
1086 |
{ |
1087 |
if (control.fontConfig.Count == 4) |
1088 |
{ |
1089 |
fontsize = Convert.ToDouble(control.fontConfig[3]); |
1090 |
} |
1091 |
|
1092 |
//강인구 수정(2018.04.17) |
1093 |
var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
1094 |
|
1095 |
FontStyle fontStyle = FontStyles.Normal; |
1096 |
if (FontStyles.Italic == TextStyle) |
1097 |
{ |
1098 |
fontStyle = FontStyles.Italic; |
1099 |
} |
1100 |
|
1101 |
FontWeight fontWeight = FontWeights.Black; |
1102 |
|
1103 |
var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
1104 |
if (FontWeights.Bold == TextWeight) |
1105 |
{ |
1106 |
fontWeight = FontWeights.Bold; |
1107 |
} |
1108 |
|
1109 |
TextDecorationCollection decoration = TextDecorations.Baseline; |
1110 |
if (control.fontConfig.Count() == 5) |
1111 |
{ |
1112 |
decoration = TextDecorations.Underline; |
1113 |
} |
1114 |
|
1115 |
if (control.isTrans) |
1116 |
{ |
1117 |
//인구 수정 Arrow Text Style적용 되도록 변경 |
1118 |
Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
1119 |
newStartPoint, tempMidPoint, control.isFixed, |
1120 |
LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
1121 |
} |
1122 |
else |
1123 |
{ |
1124 |
if (control.isFixed) |
1125 |
{ |
1126 |
var testP = new Point(0, 0); |
1127 |
if (control.isFixed) |
1128 |
{ |
1129 |
if (tempPoint[1] == newEndPoint) |
1130 |
{ |
1131 |
testP = new Point(newEndPoint.X, newEndPoint.Y - 10); |
1132 |
} |
1133 |
else if (tempPoint[3] == newEndPoint) |
1134 |
{ |
1135 |
testP = new Point(newEndPoint.X, newEndPoint.Y + 10); |
1136 |
} |
1137 |
else if (tempPoint[0] == newEndPoint) |
1138 |
{ |
1139 |
testP = new Point(newEndPoint.X - 10, newEndPoint.Y); |
1140 |
} |
1141 |
else if (tempPoint[2] == newEndPoint) |
1142 |
{ |
1143 |
testP = new Point(newEndPoint.X + 10, newEndPoint.Y); |
1144 |
} |
1145 |
} |
1146 |
//인구 수정 Arrow Text Style적용 되도록 변경 |
1147 |
Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
1148 |
tempStartPoint, testP, control.isFixed , |
1149 |
LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, |
1150 |
FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
1151 |
} |
1152 |
else |
1153 |
{ |
1154 |
//인구 수정 Arrow Text Style적용 되도록 변경 |
1155 |
Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
1156 |
newStartPoint, tempMidPoint, control.isFixed, |
1157 |
LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
1158 |
} |
1159 |
} |
1160 |
} |
1161 |
catch (Exception ex) |
1162 |
{ |
1163 |
throw ex; |
1164 |
} |
1165 |
} |
1166 |
break; |
1167 |
#endregion |
1168 |
#region SignControl |
1169 |
case "SignControl": |
1170 |
using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item)) |
1171 |
{ |
1172 |
|
1173 |
double Angle = control.Angle; |
1174 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1175 |
Point TopRightPoint = GetPdfPointSystem(control.TR); |
1176 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
1177 |
Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
1178 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
1179 |
double Opacity = control.Opac; |
1180 |
string UserNumber = control.UserNumber; |
1181 |
Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO); |
1182 |
} |
1183 |
break; |
1184 |
#endregion |
1185 |
#region MyRegion |
1186 |
case "DateControl": |
1187 |
using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item)) |
1188 |
{ |
1189 |
string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
1190 |
string Text = control.Text; |
1191 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1192 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
1193 |
List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
1194 |
SolidColorBrush FontColor = _SetColor; |
1195 |
double Angle = control.Angle; |
1196 |
double Opacity = control.Opac; |
1197 |
Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity); |
1198 |
} |
1199 |
break; |
1200 |
#endregion |
1201 |
#region SymControlN (APPROVED) |
1202 |
case "SymControlN": |
1203 |
using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
1204 |
{ |
1205 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1206 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
1207 |
List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
1208 |
SolidColorBrush FontColor = _SetColor; |
1209 |
double Angle = control.Angle; |
1210 |
double Opacity = control.Opac; |
1211 |
|
1212 |
var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP"); |
1213 |
|
1214 |
if (stamp.Count() > 0) |
1215 |
{ |
1216 |
var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE); |
1217 |
|
1218 |
Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata); |
1219 |
} |
1220 |
|
1221 |
string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", ""); |
1222 |
|
1223 |
} |
1224 |
break; |
1225 |
case "SymControl": |
1226 |
using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
1227 |
{ |
1228 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1229 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
1230 |
List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
1231 |
SolidColorBrush FontColor = _SetColor; |
1232 |
double Angle = control.Angle; |
1233 |
double Opacity = control.Opac; |
1234 |
|
1235 |
string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", ""); |
1236 |
Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
1237 |
} |
1238 |
break; |
1239 |
#endregion |
1240 |
#region Image |
1241 |
case "ImgControl": |
1242 |
using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item)) |
1243 |
{ |
1244 |
double Angle = control.Angle; |
1245 |
Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1246 |
Point TopRightPoint = GetPdfPointSystem(control.TR); |
1247 |
Point EndPoint = GetPdfPointSystem(control.EndPoint); |
1248 |
Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
1249 |
List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
1250 |
double Opacity = control.Opac; |
1251 |
string FilePath = control.ImagePath; |
1252 |
//Uri uri = new Uri(s.ImagePath); |
1253 |
|
1254 |
Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity); |
1255 |
} |
1256 |
break; |
1257 |
#endregion |
1258 |
default: |
1259 |
StatusChange($"{ControlT.Name} Not Support", 0); |
1260 |
break; |
1261 |
} |
1262 |
} |
1263 |
catch (Exception ex) |
1264 |
{ |
1265 |
StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0); |
1266 |
} |
1267 |
} |
1268 |
} |
1269 |
pdfStamper.Outlines = root; |
1270 |
pdfStamper.Close(); |
1271 |
pdfReader.Close(); |
1272 |
} |
1273 |
} |
1274 |
#endregion |
1275 |
} |
1276 |
if (tempFileInfo.Exists) |
1277 |
{ |
1278 |
tempFileInfo.Delete(); |
1279 |
} |
1280 |
|
1281 |
if (File.Exists(pdfFilePath)) |
1282 |
{ |
1283 |
try |
1284 |
{ |
1285 |
FinalPDFPath = new FileInfo(pdfFilePath); |
1286 |
|
1287 |
string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", ""); |
1288 |
string destfilepath = Path.Combine(pdfmovepath,FinalPDFPath.Name.Replace(".tmp", ".pdf")); |
1289 |
if (File.Exists(destfilepath)) |
1290 |
File.Delete(destfilepath); |
1291 |
File.Move(FinalPDFPath.FullName, destfilepath); |
1292 |
FinalPDFPath = new FileInfo(destfilepath); |
1293 |
File.Delete(pdfFilePath); |
1294 |
} |
1295 |
catch (Exception ex) |
1296 |
{ |
1297 |
SetNotice(finaldata.ID, "File move error: " + ex.ToString()); |
1298 |
} |
1299 |
|
1300 |
return true; |
1301 |
} |
1302 |
} |
1303 |
catch (Exception ex) |
1304 |
{ |
1305 |
throw ex; |
1306 |
} |
1307 |
return false; |
1308 |
} |
1309 |
|
1310 |
|
1311 |
~MarkupToPDF() |
1312 |
{ |
1313 |
this.Dispose(false); |
1314 |
} |
1315 |
|
1316 |
private bool disposed; |
1317 |
|
1318 |
public void Dispose() |
1319 |
{ |
1320 |
this.Dispose(true); |
1321 |
GC.SuppressFinalize(this); |
1322 |
} |
1323 |
|
1324 |
protected virtual void Dispose(bool disposing) |
1325 |
{ |
1326 |
if (this.disposed) return; |
1327 |
if (disposing) |
1328 |
{ |
1329 |
// IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다. |
1330 |
} |
1331 |
// .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다. |
1332 |
this.disposed = true; |
1333 |
} |
1334 |
|
1335 |
#endregion |
1336 |
} |
1337 |
} |