markus / FinalServiceV3 / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 6a19b48d
이력 | 보기 | 이력해설 | 다운로드 (93.6 KB)
1 | 6a19b48d | taeseongkim | using iTextSharp.text.pdf; |
---|---|---|---|
2 | using log4net; |
||
3 | faf998c6 | taeseongkim | using MarkupToPDF.Controls.Common; |
4 | using MarkupToPDF.Serialize.Core; |
||
5 | using MarkupToPDF.Serialize.S_Control; |
||
6 | using Markus.EntityModel; |
||
7 | using Markus.Fonts; |
||
8 | 6a19b48d | taeseongkim | using Markus.Service.Helper; |
9 | using Markus.Service.Interface; |
||
10 | faf998c6 | taeseongkim | using System; |
11 | using System.Collections.Generic; |
||
12 | using System.Configuration; |
||
13 | using System.IO; |
||
14 | using System.Linq; |
||
15 | using System.Net; |
||
16 | using System.Runtime.InteropServices; |
||
17 | 6a19b48d | taeseongkim | using System.ServiceModel; |
18 | using System.ServiceModel.Security.Tokens; |
||
19 | faf998c6 | taeseongkim | using System.Text; |
20 | using System.Web; |
||
21 | using System.Windows; |
||
22 | using System.Windows.Media; |
||
23 | |||
24 | namespace MarkupToPDF |
||
25 | { |
||
26 | public class MarkupToPDF : IDisposable |
||
27 | { |
||
28 | 6a19b48d | taeseongkim | protected static ILog logger; |
29 | faf998c6 | taeseongkim | |
30 | #region 초기 데이터 |
||
31 | private static iTextSharp.text.Rectangle mediaBox; |
||
32 | private FileInfo PdfFilePath = null; |
||
33 | private FileInfo FinalPDFPath = null; |
||
34 | private string _FinalPDFStorgeLocal = null; |
||
35 | private string _FinalPDFStorgeRemote = null; |
||
36 | private string OriginFileName = null; |
||
37 | 6a19b48d | taeseongkim | |
38 | faf998c6 | taeseongkim | public DOCINFO DocInfoItem = null; |
39 | public List<DOCPAGE> DocPageItem = null; |
||
40 | public MARKUP_INFO MarkupInfoItem = null; |
||
41 | public List<MARKUP_DATA> MarkupDataSet = null; |
||
42 | //private string _PrintPDFStorgeLocal = null; |
||
43 | //private string _PrintPDFStorgeRemote = null; |
||
44 | 6a19b48d | taeseongkim | //public event EventHandler<StatusChangedEventArgs> StatusChanged; |
45 | faf998c6 | taeseongkim | |
46 | private iTextSharp.text.Rectangle pdfSize { get; set; } |
||
47 | private double pageW = 0; |
||
48 | private double pageH = 0; |
||
49 | |||
50 | //private const double zoomLevel = 3.0; |
||
51 | private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음 |
||
52 | #endregion |
||
53 | |||
54 | #region 추가 함수 |
||
55 | 6a19b48d | taeseongkim | private DOCPAGE CurrentPage; |
56 | private int TotalPage; |
||
57 | faf998c6 | taeseongkim | private string MarkusConnectionString; |
58 | private string CIConnectionString; |
||
59 | 6a19b48d | taeseongkim | private string FinalID; |
60 | private string ProjectNo; |
||
61 | private Markus.Service.WcfClient.FinalService.FinalServiceClient FinalServiceClient; |
||
62 | faf998c6 | taeseongkim | |
63 | /// <summary> |
||
64 | /// |
||
65 | /// </summary> |
||
66 | 6a19b48d | taeseongkim | public MarkupToPDF(ProcessContext processContext) |
67 | faf998c6 | taeseongkim | { |
68 | 6a19b48d | taeseongkim | logger = LogManager.GetLogger(typeof(MarkupToPDF)); |
69 | |||
70 | MarkusConnectionString = processContext.MarkusConnectionString; |
||
71 | CIConnectionString = processContext.CI_ConnectionString; |
||
72 | FinalID = processContext.FinalID; |
||
73 | |||
74 | BasicHttpBinding myBinding = new BasicHttpBinding { TransferMode = TransferMode.Buffered }; |
||
75 | |||
76 | myBinding.CloseTimeout = new TimeSpan(0, 10, 0); |
||
77 | myBinding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
78 | myBinding.SendTimeout = new TimeSpan(0, 10, 0); |
||
79 | myBinding.OpenTimeout = new TimeSpan(0, 10, 0); |
||
80 | |||
81 | EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(processContext.ServiceUri)); |
||
82 | |||
83 | FinalServiceClient = new Markus.Service.WcfClient.FinalService.FinalServiceClient(myBinding, myEndpoint); |
||
84 | |||
85 | faf998c6 | taeseongkim | } |
86 | |||
87 | #endregion |
||
88 | |||
89 | #region 메서드 |
||
90 | public static bool IsLocalIPAddress(string host) |
||
91 | { |
||
92 | try |
||
93 | { |
||
94 | IPAddress[] hostIPs = Dns.GetHostAddresses(host); |
||
95 | IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); |
||
96 | |||
97 | foreach (IPAddress hostIP in hostIPs) |
||
98 | { |
||
99 | if (IPAddress.IsLoopback(hostIP)) return true; |
||
100 | |||
101 | foreach (IPAddress localIP in localIPs) |
||
102 | { |
||
103 | if (hostIP.Equals(localIP)) return true; |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | catch { } |
||
108 | return false; |
||
109 | } |
||
110 | |||
111 | 6a19b48d | taeseongkim | private void FinalStatusChange(StatusCodeType status, string message) |
112 | faf998c6 | taeseongkim | { |
113 | 6a19b48d | taeseongkim | int currentPage = 0; |
114 | int totalPage = 0; |
||
115 | |||
116 | if (CurrentPage != null) |
||
117 | faf998c6 | taeseongkim | { |
118 | 6a19b48d | taeseongkim | currentPage = CurrentPage.PAGE_NUMBER; |
119 | totalPage = CurrentPage.PAGE_NUMBER; |
||
120 | faf998c6 | taeseongkim | } |
121 | 6a19b48d | taeseongkim | |
122 | logger.Info($"ID:{FinalID} Status:{status.ToString()} message:{message}"); |
||
123 | |||
124 | #if ProcessDebug |
||
125 | Console.WriteLine($"FinalID :{FinalID} status :{status.ToString()}, current Page :{currentPage} totalPage : {totalPage}"); |
||
126 | |||
127 | if (status != StatusCodeType.Complated) |
||
128 | { |
||
129 | Console.WriteLine(message); |
||
130 | } |
||
131 | #else |
||
132 | if (status == StatusCodeType.Complated) |
||
133 | { |
||
134 | FinalServiceClient.FinalFinish(FinalID, (int)status, currentPage, totalPage, ""); |
||
135 | } |
||
136 | else |
||
137 | { |
||
138 | FinalServiceClient.FinalFinish(FinalID, (int)status, currentPage, totalPage, message); |
||
139 | } |
||
140 | #endif |
||
141 | |||
142 | |||
143 | } |
||
144 | |||
145 | private void FinalMakeError(string message, StatusCodeType status) |
||
146 | { |
||
147 | int currentPage = 0; |
||
148 | int totalPage = 0; |
||
149 | |||
150 | if(CurrentPage != null) |
||
151 | { |
||
152 | currentPage = CurrentPage.PAGE_NUMBER; |
||
153 | totalPage = CurrentPage.PAGE_NUMBER; |
||
154 | } |
||
155 | |||
156 | logger.Error($"ID:{FinalID} Status:{status.ToString()} CurrentPage:{currentPage} totolPage:{totalPage} Message:{message}"); |
||
157 | |||
158 | #if ProcessDebug |
||
159 | Console.WriteLine($"FinalID :{FinalID} status :{status.ToString()}, current Page :{currentPage} totalPage : {totalPage}"); |
||
160 | #else |
||
161 | FinalServiceClient.FinalFinish(FinalID,(int)status, currentPage, totalPage, message); |
||
162 | #endif |
||
163 | |||
164 | faf998c6 | taeseongkim | } |
165 | |||
166 | private string GetFileName(string hrefLink) |
||
167 | { |
||
168 | try |
||
169 | { |
||
170 | if (hrefLink.Contains("vpcs_doclib")) |
||
171 | { |
||
172 | return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\")); |
||
173 | } |
||
174 | else |
||
175 | { |
||
176 | Uri fileurl = new Uri(hrefLink); |
||
177 | int index = hrefLink.IndexOf("?"); |
||
178 | string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName"); |
||
179 | return filename; |
||
180 | } |
||
181 | } |
||
182 | catch (Exception ex) |
||
183 | { |
||
184 | throw ex; |
||
185 | } |
||
186 | } |
||
187 | |||
188 | public Point GetPdfPointSystem(Point point) |
||
189 | { |
||
190 | /// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다. |
||
191 | /// Rotation 90 일 경우 pdfsize box 와 media box 가 달라 다른 계산식 적용 |
||
192 | if (pdfSize.Rotation == 90) |
||
193 | { |
||
194 | return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom); |
||
195 | } |
||
196 | else |
||
197 | { |
||
198 | return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Height - (float)(point.Y / scaleHeight) + pdfSize.Bottom); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | public double GetPdfSize(double size) |
||
203 | { |
||
204 | return (size / scaleWidth); |
||
205 | } |
||
206 | |||
207 | public List<Point> GetPdfPointSystem(List<Point> point) |
||
208 | { |
||
209 | List<Point> dummy = new List<Point>(); |
||
210 | foreach (var item in point) |
||
211 | { |
||
212 | dummy.Add(GetPdfPointSystem(item)); |
||
213 | } |
||
214 | return dummy; |
||
215 | } |
||
216 | |||
217 | public double returnAngle(Point start, Point end) |
||
218 | { |
||
219 | double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y); |
||
220 | //angle *= -1; |
||
221 | |||
222 | angle += 90; |
||
223 | //if (angle < 0) |
||
224 | //{ |
||
225 | // angle = angle + 360; |
||
226 | //} |
||
227 | return angle; |
||
228 | } |
||
229 | |||
230 | 6a19b48d | taeseongkim | #endregion |
231 | faf998c6 | taeseongkim | |
232 | public bool AddStamp(string stampData) |
||
233 | { |
||
234 | bool result = false; |
||
235 | |||
236 | try |
||
237 | { |
||
238 | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(MarkusConnectionString)) |
||
239 | { |
||
240 | var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP"); |
||
241 | |||
242 | if(stamp.Count() > 0) |
||
243 | { |
||
244 | var xamldata = Serialize.Core.JsonSerializerHelper.CompressStamp(stampData); |
||
245 | |||
246 | stamp.First().VALUE = xamldata; |
||
247 | _entity.SaveChanges(); |
||
248 | result = true; |
||
249 | } |
||
250 | } |
||
251 | } |
||
252 | catch (Exception) |
||
253 | { |
||
254 | |||
255 | throw; |
||
256 | } |
||
257 | |||
258 | return result; |
||
259 | |||
260 | } |
||
261 | |||
262 | /// <summary> |
||
263 | /// local에서 final 생성하는 경우 이 함수로 추가 후 실행 |
||
264 | /// </summary> |
||
265 | /// <param name="finalpdf"></param> |
||
266 | /// <returns></returns> |
||
267 | public AddFinalPDFResult AddFinalPDF(string ProjectNo,string DocumentID,string UserID) |
||
268 | { |
||
269 | //var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS"); |
||
270 | //System.Diagnostics.Debug.WriteLine(list); |
||
271 | |||
272 | AddFinalPDFResult result = new AddFinalPDFResult { Success = false }; |
||
273 | |||
274 | try |
||
275 | { |
||
276 | FINAL_PDF addItem = new FINAL_PDF{ |
||
277 | ID = CommonLib.Guid.shortGuid(), |
||
278 | PROJECT_NO = ProjectNo, |
||
279 | DOCUMENT_ID = DocumentID, |
||
280 | CREATE_USER_ID = UserID, |
||
281 | CREATE_DATETIME = DateTime.Now, |
||
282 | STATUS = 4 |
||
283 | }; |
||
284 | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(CIConnectionString)) |
||
285 | { |
||
286 | var docitems = _entity.DOCINFO.Where(x => x.PROJECT_NO == ProjectNo && x.DOCUMENT_ID == DocumentID); |
||
287 | |||
288 | if(docitems.Count() > 0) |
||
289 | { |
||
290 | addItem.DOCINFO_ID = docitems.First().ID; |
||
291 | result.Success = true; |
||
292 | } |
||
293 | else |
||
294 | { |
||
295 | result.Exception = "docInfo Not Found."; |
||
296 | result.Success = false; |
||
297 | } |
||
298 | |||
299 | var markupInfoItems = _entity.MARKUP_INFO.Where(x =>x.DOCINFO_ID == addItem.DOCINFO_ID); |
||
300 | |||
301 | if (markupInfoItems.Count() > 0) |
||
302 | { |
||
303 | addItem.MARKUPINFO_ID = markupInfoItems.First().ID; |
||
304 | result.Success = true; |
||
305 | } |
||
306 | else |
||
307 | { |
||
308 | result.Exception = "Markup Info Not Found."; |
||
309 | result.Success = false; |
||
310 | } |
||
311 | } |
||
312 | |||
313 | if (result.Success) |
||
314 | { |
||
315 | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(MarkusConnectionString)) |
||
316 | { |
||
317 | var finalList = _entity.FINAL_PDF.Where(final => final.ID == addItem.ID); |
||
318 | |||
319 | /// Insrt and Update |
||
320 | if (finalList.Count() == 0) |
||
321 | { |
||
322 | _entity.FINAL_PDF.Add(addItem); |
||
323 | _entity.SaveChanges(); |
||
324 | |||
325 | result.FinalPDF = addItem; |
||
326 | result.Success = true; |
||
327 | } |
||
328 | } |
||
329 | } |
||
330 | } |
||
331 | catch (Exception ex) |
||
332 | { |
||
333 | System.Diagnostics.Debug.WriteLine(ex); |
||
334 | result.Success = false; |
||
335 | } |
||
336 | |||
337 | return result; |
||
338 | } |
||
339 | |||
340 | 6a19b48d | taeseongkim | #region 생성자 & 소멸자 |
341 | public void MakeFinalPDF() |
||
342 | faf998c6 | taeseongkim | { |
343 | DOCUMENT_ITEM documentItem; |
||
344 | 6a19b48d | taeseongkim | FINAL_PDF FinalPDF = null; |
345 | faf998c6 | taeseongkim | |
346 | |||
347 | string PdfFilePathRoot = null; |
||
348 | string TestFile = System.IO.Path.GetTempFileName(); |
||
349 | |||
350 | 6a19b48d | taeseongkim | #region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정 |
351 | faf998c6 | taeseongkim | try |
352 | { |
||
353 | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(MarkusConnectionString)) |
||
354 | { |
||
355 | 6a19b48d | taeseongkim | var items = _entity.FINAL_PDF.Where(x => x.ID == FinalID); |
356 | |||
357 | if (items.Count() > 0) |
||
358 | { |
||
359 | FinalPDF = items.First(); |
||
360 | } |
||
361 | else |
||
362 | { |
||
363 | FinalMakeError( "FinalPDF not Found",StatusCodeType.Error); |
||
364 | return; |
||
365 | } |
||
366 | |||
367 | faf998c6 | taeseongkim | var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO); |
368 | |||
369 | if (_properties.Count() > 0) |
||
370 | { |
||
371 | if (_properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).Count() == 0) |
||
372 | { |
||
373 | 6a19b48d | taeseongkim | FinalMakeError($"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found.", StatusCodeType.Error); |
374 | faf998c6 | taeseongkim | return; |
375 | } |
||
376 | else |
||
377 | { |
||
378 | PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE; |
||
379 | } |
||
380 | |||
381 | if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).Count() == 0) |
||
382 | { |
||
383 | 6a19b48d | taeseongkim | FinalMakeError( $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found.", StatusCodeType.Error); |
384 | faf998c6 | taeseongkim | return; |
385 | } |
||
386 | else |
||
387 | { |
||
388 | _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE; |
||
389 | } |
||
390 | |||
391 | |||
392 | if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).Count() == 0) |
||
393 | { |
||
394 | 6a19b48d | taeseongkim | FinalMakeError($"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found.", StatusCodeType.Error); |
395 | faf998c6 | taeseongkim | return; |
396 | } |
||
397 | else |
||
398 | { |
||
399 | _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE; |
||
400 | } |
||
401 | } |
||
402 | else |
||
403 | { |
||
404 | 6a19b48d | taeseongkim | FinalMakeError($"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found.", StatusCodeType.Error); |
405 | faf998c6 | taeseongkim | return; |
406 | } |
||
407 | } |
||
408 | } |
||
409 | catch (Exception ex) |
||
410 | { |
||
411 | 6a19b48d | taeseongkim | FinalMakeError( "프로퍼티 에러: " + ex.ToString(), StatusCodeType.Error); |
412 | faf998c6 | taeseongkim | return; |
413 | } |
||
414 | 6a19b48d | taeseongkim | #endregion |
415 | faf998c6 | taeseongkim | |
416 | 6a19b48d | taeseongkim | #region 문서 복사 |
417 | faf998c6 | taeseongkim | try |
418 | { |
||
419 | 6a19b48d | taeseongkim | FinalStatusChange(StatusCodeType.Create,null); |
420 | |||
421 | faf998c6 | taeseongkim | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(CIConnectionString)) |
422 | { |
||
423 | var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID); |
||
424 | |||
425 | if (_DOCINFO.Count() > 0) |
||
426 | { |
||
427 | DocInfoItem = _DOCINFO.First(); |
||
428 | |||
429 | DocPageItem = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == DocInfoItem.ID).ToList(); |
||
430 | |||
431 | PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\" |
||
432 | + (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5)) |
||
433 | + @"\" + FinalPDF.DOCUMENT_ID + @"\"; |
||
434 | |||
435 | var infoItems = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == DocInfoItem.ID && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0); |
||
436 | |||
437 | if (infoItems.Count() == 0) |
||
438 | { |
||
439 | throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다"); |
||
440 | } |
||
441 | else |
||
442 | { |
||
443 | MarkupInfoItem = infoItems.First(); |
||
444 | |||
445 | var markupInfoVerItems = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == MarkupInfoItem.ID).ToList(); |
||
446 | |||
447 | if (markupInfoVerItems.Count() > 0) |
||
448 | { |
||
449 | var markupInfoVerItem = markupInfoVerItems.OrderByDescending(x => x.CREATE_DATE).First(); |
||
450 | |||
451 | MarkupDataSet = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupInfoVerItem.ID).OrderBy(d => d.PAGENUMBER).ToList(); |
||
452 | } |
||
453 | else |
||
454 | { |
||
455 | throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다"); |
||
456 | } |
||
457 | } |
||
458 | |||
459 | documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault(); |
||
460 | if (documentItem == null) |
||
461 | { |
||
462 | throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요"); |
||
463 | } |
||
464 | |||
465 | var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 |
||
466 | |||
467 | 6a19b48d | taeseongkim | #region 파일 체크 |
468 | faf998c6 | taeseongkim | if (_files.Count() == 1) |
469 | { |
||
470 | /// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정 |
||
471 | //if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower())) |
||
472 | //{ |
||
473 | OriginFileName = _files.First().Name; |
||
474 | PdfFilePath = _files.First().CopyTo(TestFile, true); |
||
475 | 6a19b48d | taeseongkim | //StatusChange($"Copy File file Count = 1 : {PdfFilePath}", 0); |
476 | faf998c6 | taeseongkim | //} |
477 | //else |
||
478 | //{ |
||
479 | // throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()); |
||
480 | //} |
||
481 | } |
||
482 | else if (_files.Count() > 1) |
||
483 | { |
||
484 | var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault(); |
||
485 | |||
486 | if (originalFile == null) |
||
487 | { |
||
488 | throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다"); |
||
489 | } |
||
490 | else |
||
491 | { |
||
492 | OriginFileName = originalFile.Name; |
||
493 | PdfFilePath = originalFile.CopyTo(TestFile, true); |
||
494 | 6a19b48d | taeseongkim | //StatusChange($"Copy File file Count > 1 : {PdfFilePath}", 0); |
495 | faf998c6 | taeseongkim | } |
496 | } |
||
497 | else |
||
498 | { |
||
499 | throw new FileNotFoundException("PDF를 찾지 못하였습니다"); |
||
500 | } |
||
501 | 6a19b48d | taeseongkim | #endregion |
502 | faf998c6 | taeseongkim | |
503 | 6a19b48d | taeseongkim | #region 예외처리 |
504 | faf998c6 | taeseongkim | if (PdfFilePath == null) |
505 | { |
||
506 | throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다"); |
||
507 | } |
||
508 | if (!PdfFilePath.Exists) |
||
509 | { |
||
510 | throw new Exception("PDF원본이 존재하지 않습니다"); |
||
511 | } |
||
512 | 6a19b48d | taeseongkim | #endregion |
513 | faf998c6 | taeseongkim | |
514 | } |
||
515 | else |
||
516 | { |
||
517 | throw new Exception("일치하는 DocInfo가 없습니다"); |
||
518 | } |
||
519 | } |
||
520 | } |
||
521 | catch (Exception ex) |
||
522 | { |
||
523 | if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다") |
||
524 | { |
||
525 | 6a19b48d | taeseongkim | FinalMakeError("Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다", StatusCodeType.Error); |
526 | faf998c6 | taeseongkim | //System.Diagnostics.Process process = new System.Diagnostics.Process(); |
527 | //process.StartInfo.FileName = "cmd"; |
||
528 | //process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\""; |
||
529 | //process.Start(); |
||
530 | } |
||
531 | else |
||
532 | { |
||
533 | 6a19b48d | taeseongkim | FinalMakeError("PDF를 Stamp 중 에러 : " + ex.Message, StatusCodeType.Error); |
534 | faf998c6 | taeseongkim | } |
535 | } |
||
536 | 6a19b48d | taeseongkim | #endregion |
537 | faf998c6 | taeseongkim | |
538 | try |
||
539 | { |
||
540 | 6a19b48d | taeseongkim | FinalStatusChange(StatusCodeType.Stamp, null); |
541 | |||
542 | faf998c6 | taeseongkim | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(MarkusConnectionString)) |
543 | { |
||
544 | var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID); |
||
545 | |||
546 | if (finalList.Count() > 0) |
||
547 | { |
||
548 | //TestFile = SetFlattingPDF(TestFile); |
||
549 | //StatusChange($"SetFlattingPDF : {TestFile}", 0); |
||
550 | |||
551 | 6a19b48d | taeseongkim | SetStampInPDF(FinalPDF, TestFile, MarkupInfoItem); |
552 | FinalStatusChange(StatusCodeType.Complated, ""); |
||
553 | faf998c6 | taeseongkim | } |
554 | 6a19b48d | taeseongkim | else |
555 | faf998c6 | taeseongkim | { |
556 | 6a19b48d | taeseongkim | FinalMakeError("FinalPDF DB Not Found",StatusCodeType.Error); |
557 | } |
||
558 | faf998c6 | taeseongkim | } |
559 | 6a19b48d | taeseongkim | |
560 | faf998c6 | taeseongkim | } |
561 | catch (Exception ex) |
||
562 | { |
||
563 | 6a19b48d | taeseongkim | FinalMakeError("MarkFinalPDF Error : " + ex.Message, StatusCodeType.Error); |
564 | faf998c6 | taeseongkim | } |
565 | } |
||
566 | 6a19b48d | taeseongkim | #endregion |
567 | faf998c6 | taeseongkim | |
568 | 6a19b48d | taeseongkim | #region PDF |
569 | faf998c6 | taeseongkim | public static float scaleWidth = 0; |
570 | public static float scaleHeight = 0; |
||
571 | |||
572 | private string SetFlattingPDF(string tempFileInfo) |
||
573 | { |
||
574 | if (File.Exists(tempFileInfo)) |
||
575 | { |
||
576 | FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName()); |
||
577 | |||
578 | PdfReader pdfReader = new PdfReader(tempFileInfo); |
||
579 | |||
580 | for (int i = 1; i <= pdfReader.NumberOfPages; i++) |
||
581 | { |
||
582 | var mediaBox = pdfReader.GetPageSize(i); |
||
583 | var cropbox = pdfReader.GetCropBox(i); |
||
584 | |||
585 | //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString())) |
||
586 | //{ |
||
587 | // _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE) |
||
588 | //} |
||
589 | var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault(); |
||
590 | |||
591 | //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width; |
||
592 | //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height; |
||
593 | //scaleWidth = 2.0832634F; |
||
594 | //scaleHeight = 3.0F; |
||
595 | |||
596 | PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i)); |
||
597 | //강인구 수정 |
||
598 | //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height)) |
||
599 | //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height)) |
||
600 | //{ |
||
601 | // var pageDict = pdfReader.GetPageN(i); |
||
602 | // pageDict.Put(PdfName.MEDIABOX, rect); |
||
603 | //} |
||
604 | } |
||
605 | |||
606 | var memStream = new MemoryStream(); |
||
607 | var stamper = new PdfStamper(pdfReader, memStream) |
||
608 | { |
||
609 | FormFlattening = true, |
||
610 | //FreeTextFlattening = true, |
||
611 | //AnnotationFlattening = true, |
||
612 | }; |
||
613 | |||
614 | stamper.Close(); |
||
615 | pdfReader.Close(); |
||
616 | var array = memStream.ToArray(); |
||
617 | File.Delete(tempFileInfo); |
||
618 | File.WriteAllBytes(TestFile.FullName, array); |
||
619 | |||
620 | return TestFile.FullName; |
||
621 | } |
||
622 | else |
||
623 | { |
||
624 | return tempFileInfo; |
||
625 | } |
||
626 | } |
||
627 | |||
628 | public void flattenPdfFile(string src, ref string dest) |
||
629 | { |
||
630 | PdfReader reader = new PdfReader(src); |
||
631 | var memStream = new MemoryStream(); |
||
632 | var stamper = new PdfStamper(reader, memStream) |
||
633 | { |
||
634 | FormFlattening = true, |
||
635 | FreeTextFlattening = true, |
||
636 | AnnotationFlattening = true, |
||
637 | }; |
||
638 | |||
639 | stamper.Close(); |
||
640 | var array = memStream.ToArray(); |
||
641 | File.WriteAllBytes(dest, array); |
||
642 | } |
||
643 | |||
644 | 6a19b48d | taeseongkim | public bool SetStampInPDF(FINAL_PDF finalPDF, string testFile, MARKUP_INFO markupInfo) |
645 | faf998c6 | taeseongkim | { |
646 | try |
||
647 | { |
||
648 | |||
649 | FileInfo tempFileInfo = new FileInfo(testFile); |
||
650 | |||
651 | if (!Directory.Exists(_FinalPDFStorgeLocal)) |
||
652 | { |
||
653 | Directory.CreateDirectory(_FinalPDFStorgeLocal); |
||
654 | } |
||
655 | |||
656 | string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name); |
||
657 | |||
658 | 6a19b48d | taeseongkim | #region 코멘트 적용 + 커버시트 |
659 | faf998c6 | taeseongkim | using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) // |
660 | { |
||
661 | 6a19b48d | taeseongkim | FinalStatusChange(StatusCodeType.Stamp, "comment Cover"); |
662 | faf998c6 | taeseongkim | |
663 | 6a19b48d | taeseongkim | using (PdfReader pdfReader = new PdfReader(pdfStream)) |
664 | { |
||
665 | //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>(); |
||
666 | Dictionary<string, object> bookmark; |
||
667 | List<Dictionary<string, object>> outlines; |
||
668 | faf998c6 | taeseongkim | |
669 | 6a19b48d | taeseongkim | outlines = new List<Dictionary<string, object>>(); |
670 | List<Dictionary<string, object>> root = new List<Dictionary<string, object>>(); |
||
671 | faf998c6 | taeseongkim | |
672 | 6a19b48d | taeseongkim | var dic = new Dictionary<string, object>(); |
673 | faf998c6 | taeseongkim | |
674 | 6a19b48d | taeseongkim | foreach (var data in MarkupDataSet) |
675 | { |
||
676 | //StatusChange("MarkupDataSet", 0); |
||
677 | faf998c6 | taeseongkim | |
678 | 6a19b48d | taeseongkim | string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID; |
679 | faf998c6 | taeseongkim | |
680 | 6a19b48d | taeseongkim | string username = ""; |
681 | string userdept = ""; |
||
682 | faf998c6 | taeseongkim | |
683 | 6a19b48d | taeseongkim | using (Markus.EntityModel.MarkusModel _ciEntity = new Markus.EntityModel.MarkusModel(CIConnectionString)) |
684 | { |
||
685 | var memberlist = _ciEntity.MEMBER.Where(x=>x.ID == userid); |
||
686 | faf998c6 | taeseongkim | |
687 | 6a19b48d | taeseongkim | if(memberlist.Count() > 0) |
688 | { |
||
689 | username = memberlist.First().NAME; |
||
690 | userdept = memberlist.First().DEPARTMENT; |
||
691 | faf998c6 | taeseongkim | } |
692 | } |
||
693 | |||
694 | 6a19b48d | taeseongkim | bookmark = new Dictionary<string, object>(); |
695 | bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER)); |
||
696 | bookmark.Add("Page", data.PAGENUMBER + " Fit"); |
||
697 | bookmark.Add("Action", "GoTo"); |
||
698 | bookmark.Add("Kids", outlines); |
||
699 | root.Add(bookmark); |
||
700 | } |
||
701 | |||
702 | iTextSharp.text.Version.GetInstance(); |
||
703 | using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create))) |
||
704 | { |
||
705 | try |
||
706 | faf998c6 | taeseongkim | { |
707 | 6a19b48d | taeseongkim | if (pdfStamper.AcroFields != null && pdfStamper.AcroFields.GenerateAppearances != true) |
708 | faf998c6 | taeseongkim | { |
709 | 6a19b48d | taeseongkim | pdfStamper.AcroFields.GenerateAppearances = true; |
710 | faf998c6 | taeseongkim | } |
711 | 6a19b48d | taeseongkim | } |
712 | catch (Exception ex) |
||
713 | { |
||
714 | FinalMakeError("this pdf is not AcroForm.", StatusCodeType.FileError); |
||
715 | } |
||
716 | |||
717 | System.Drawing.Color _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red); |
||
718 | faf998c6 | taeseongkim | |
719 | |||
720 | 6a19b48d | taeseongkim | string[] delimiterChars = { "|DZ|" }; |
721 | string[] delimiterChars2 = { "|" }; |
||
722 | faf998c6 | taeseongkim | |
723 | 6a19b48d | taeseongkim | //pdfStamper.FormFlattening = true; //이미 선처리 작업함 |
724 | pdfStamper.SetFullCompression(); |
||
725 | _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red); |
||
726 | faf998c6 | taeseongkim | |
727 | 6a19b48d | taeseongkim | StringBuilder strLog = new StringBuilder(); |
728 | |||
729 | strLog.Append($"Write {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} markup Count : {MarkupDataSet.Count()} / "); |
||
730 | faf998c6 | taeseongkim | |
731 | 6a19b48d | taeseongkim | foreach (var markupItem in MarkupDataSet) |
732 | { |
||
733 | /// 2020.11.13 김태성 |
||
734 | /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함. |
||
735 | var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER); |
||
736 | faf998c6 | taeseongkim | |
737 | 6a19b48d | taeseongkim | if (pageitems.Count() > 0) |
738 | faf998c6 | taeseongkim | { |
739 | 6a19b48d | taeseongkim | CurrentPage = pageitems.First(); |
740 | pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER); |
||
741 | //try |
||
742 | //{ |
||
743 | |||
744 | //} |
||
745 | //catch (Exception ex) |
||
746 | //{ |
||
747 | // SetNotice(finaldata.ID, $"GetPageSizeWithRotation Error PageNO : {markupItem.PAGENUMBER} " + ex.ToString()); |
||
748 | //} |
||
749 | //finally |
||
750 | //{ |
||
751 | // pdfSize = new iTextSharp.text.Rectangle(0, 0, float.Parse(currentPage.PAGE_WIDTH), float.Parse(currentPage.PAGE_HEIGHT)); |
||
752 | //} |
||
753 | |||
754 | mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER); |
||
755 | var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER); |
||
756 | |||
757 | /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다 |
||
758 | if (cropBox != null && |
||
759 | (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom)) |
||
760 | faf998c6 | taeseongkim | { |
761 | 6a19b48d | taeseongkim | PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER); |
762 | faf998c6 | taeseongkim | |
763 | 6a19b48d | taeseongkim | PdfArray oNewMediaBox = new PdfArray(); |
764 | oNewMediaBox.Add(new PdfNumber(cropBox.Left)); |
||
765 | oNewMediaBox.Add(new PdfNumber(cropBox.Top)); |
||
766 | oNewMediaBox.Add(new PdfNumber(cropBox.Right)); |
||
767 | oNewMediaBox.Add(new PdfNumber(cropBox.Bottom)); |
||
768 | dict.Put(PdfName.MEDIABOX, oNewMediaBox); |
||
769 | faf998c6 | taeseongkim | |
770 | 6a19b48d | taeseongkim | pdfSize = cropBox; |
771 | } |
||
772 | faf998c6 | taeseongkim | |
773 | 6a19b48d | taeseongkim | scaleWidth = float.Parse(CurrentPage.PAGE_WIDTH) / pdfSize.Width; |
774 | scaleHeight = float.Parse(CurrentPage.PAGE_HEIGHT) / pdfSize.Height; |
||
775 | faf998c6 | taeseongkim | |
776 | 6a19b48d | taeseongkim | string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
777 | faf998c6 | taeseongkim | |
778 | 6a19b48d | taeseongkim | PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER); |
779 | strLog.Append($"p.{markupItem.PAGENUMBER}:{markupItem.DATA_TYPE}/"); |
||
780 | faf998c6 | taeseongkim | |
781 | 6a19b48d | taeseongkim | foreach (var data in markedData) |
782 | { |
||
783 | var item = JsonSerializerHelper.UnCompressString(data); |
||
784 | var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); |
||
785 | faf998c6 | taeseongkim | |
786 | 6a19b48d | taeseongkim | try |
787 | faf998c6 | taeseongkim | { |
788 | 6a19b48d | taeseongkim | switch (ControlT.Name) |
789 | faf998c6 | taeseongkim | { |
790 | 6a19b48d | taeseongkim | #region LINE |
791 | case "LineControl": |
||
792 | { |
||
793 | using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item)) |
||
794 | faf998c6 | taeseongkim | { |
795 | 6a19b48d | taeseongkim | DrawLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor); |
796 | faf998c6 | taeseongkim | } |
797 | 6a19b48d | taeseongkim | } |
798 | break; |
||
799 | #endregion |
||
800 | #region ArrowControlMulti |
||
801 | case "ArrowControl_Multi": |
||
802 | { |
||
803 | using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item)) |
||
804 | faf998c6 | taeseongkim | { |
805 | 6a19b48d | taeseongkim | DrawMultiArrowLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor); |
806 | faf998c6 | taeseongkim | } |
807 | 6a19b48d | taeseongkim | } |
808 | break; |
||
809 | #endregion |
||
810 | #region PolyControl |
||
811 | case "PolygonControl": |
||
812 | using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item)) |
||
813 | { |
||
814 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
815 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
816 | var PaintStyle = control.PaintState; |
||
817 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
818 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
819 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
820 | double Opacity = control.Opac; |
||
821 | DoubleCollection DashSize = control.DashSize; |
||
822 | |||
823 | Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor,PaintStyle| PaintSet.Outline, Opacity); |
||
824 | //Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
||
825 | } |
||
826 | break; |
||
827 | #endregion |
||
828 | #region ArcControl or ArrowArcControl |
||
829 | case "ArcControl": |
||
830 | case "ArrowArcControl": |
||
831 | { |
||
832 | using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item)) |
||
833 | faf998c6 | taeseongkim | { |
834 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
835 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
836 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
837 | 6a19b48d | taeseongkim | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
838 | DoubleCollection DashSize = control.DashSize; |
||
839 | faf998c6 | taeseongkim | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
840 | 6a19b48d | taeseongkim | |
841 | var Opacity = control.Opac; |
||
842 | string UserID = control.UserID; |
||
843 | faf998c6 | taeseongkim | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
844 | 6a19b48d | taeseongkim | bool IsTransOn = control.IsTransOn; |
845 | faf998c6 | taeseongkim | |
846 | 6a19b48d | taeseongkim | if (control.IsTransOn) |
847 | { |
||
848 | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
||
849 | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
||
850 | } |
||
851 | else |
||
852 | { |
||
853 | Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
||
854 | } |
||
855 | |||
856 | if (ControlT.Name == "ArrowArcControl") |
||
857 | { |
||
858 | Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
||
859 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
||
860 | } |
||
861 | faf998c6 | taeseongkim | } |
862 | 6a19b48d | taeseongkim | } |
863 | break; |
||
864 | #endregion |
||
865 | #region RectangleControl |
||
866 | case "RectangleControl": |
||
867 | using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item)) |
||
868 | { |
||
869 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
870 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
871 | var PaintStyle = control.PaintState; |
||
872 | double Angle = control.Angle; |
||
873 | DoubleCollection DashSize = control.DashSize; |
||
874 | double Opacity = control.Opac; |
||
875 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
876 | |||
877 | Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
||
878 | } |
||
879 | break; |
||
880 | #endregion |
||
881 | #region TriControl |
||
882 | case "TriControl": |
||
883 | using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item)) |
||
884 | { |
||
885 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
886 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
887 | var PaintStyle = control.Paint; |
||
888 | double Angle = control.Angle; |
||
889 | //StrokeColor = _SetColor, //색상은 레드 |
||
890 | DoubleCollection DashSize = control.DashSize; |
||
891 | double Opacity = control.Opac; |
||
892 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
893 | |||
894 | Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle | PaintSet.Outline, Opacity); |
||
895 | } |
||
896 | break; |
||
897 | #endregion |
||
898 | #region CircleControl |
||
899 | case "CircleControl": |
||
900 | using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item)) |
||
901 | { |
||
902 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
903 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
904 | var StartPoint = GetPdfPointSystem(control.StartPoint); |
||
905 | var EndPoint = GetPdfPointSystem(control.EndPoint); |
||
906 | var PaintStyle = control.PaintState; |
||
907 | double Angle = control.Angle; |
||
908 | DoubleCollection DashSize = control.DashSize; |
||
909 | double Opacity = control.Opac; |
||
910 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
911 | Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet); |
||
912 | |||
913 | } |
||
914 | break; |
||
915 | #endregion |
||
916 | #region RectCloudControl |
||
917 | case "RectCloudControl": |
||
918 | using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item)) |
||
919 | { |
||
920 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
921 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
922 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
923 | double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
924 | |||
925 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
926 | |||
927 | var PaintStyle = control.PaintState; |
||
928 | double Opacity = control.Opac; |
||
929 | DoubleCollection DashSize = control.DashSize; |
||
930 | |||
931 | //드로잉 방식이 표현되지 않음 |
||
932 | var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
933 | |||
934 | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
||
935 | bool reverse = (area < 0); |
||
936 | |||
937 | Controls_PDF.DrawSet_Cloud.DrawCloudRect(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
938 | } |
||
939 | break; |
||
940 | #endregion |
||
941 | #region CloudControl |
||
942 | case "CloudControl": |
||
943 | using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item)) |
||
944 | { |
||
945 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
946 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
947 | double Toler = control.Toler; |
||
948 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
949 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
950 | var PaintStyle = control.PaintState; |
||
951 | double Opacity = control.Opac; |
||
952 | bool isTransOn = control.IsTrans; |
||
953 | bool isChain = control.IsChain; |
||
954 | |||
955 | DoubleCollection DashSize = control.DashSize; |
||
956 | |||
957 | if (isChain) |
||
958 | { |
||
959 | Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
||
960 | } |
||
961 | else |
||
962 | faf998c6 | taeseongkim | { |
963 | 6a19b48d | taeseongkim | if (isTransOn) |
964 | faf998c6 | taeseongkim | { |
965 | 6a19b48d | taeseongkim | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
966 | bool reverse = (area < 0); |
||
967 | faf998c6 | taeseongkim | |
968 | 6a19b48d | taeseongkim | if (PaintStyle == PaintSet.None) |
969 | faf998c6 | taeseongkim | { |
970 | 6a19b48d | taeseongkim | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
971 | faf998c6 | taeseongkim | } |
972 | else |
||
973 | { |
||
974 | 6a19b48d | taeseongkim | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
975 | faf998c6 | taeseongkim | } |
976 | } |
||
977 | 6a19b48d | taeseongkim | else |
978 | { |
||
979 | Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity); |
||
980 | } |
||
981 | faf998c6 | taeseongkim | } |
982 | 6a19b48d | taeseongkim | } |
983 | break; |
||
984 | #endregion |
||
985 | #region TEXT |
||
986 | case "TextControl": |
||
987 | using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item)) |
||
988 | { |
||
989 | DrawTextBox(control, contentByte, delimiterChars, delimiterChars2, _SetColor); |
||
990 | } |
||
991 | break; |
||
992 | #endregion |
||
993 | #region ArrowTextControl |
||
994 | case "ArrowTextControl": |
||
995 | using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item)) |
||
996 | { |
||
997 | //using (S_TextControl textcontrol = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item)) |
||
998 | //{ |
||
999 | // textcontrol.Angle = control.Angle; |
||
1000 | // textcontrol.BoxH = control.BoxHeight; |
||
1001 | // textcontrol.BoxW = control.BoxWidth; |
||
1002 | // textcontrol.EndPoint = control.EndPoint; |
||
1003 | // textcontrol.FontColor = "#FFFF0000"; |
||
1004 | // textcontrol.Name = "TextControl"; |
||
1005 | // textcontrol.Opac = control.Opac; |
||
1006 | // textcontrol.PointSet = new List<Point>(); |
||
1007 | // textcontrol.SizeSet = string.Join(delimiterChars2.First(), control.SizeSet.First(), control.fontConfig[3]); |
||
1008 | // textcontrol.StartPoint = control.StartPoint; |
||
1009 | // textcontrol.Text = control.ArrowText; |
||
1010 | // textcontrol.TransformPoint = control.TransformPoint; |
||
1011 | // textcontrol.UserID = null; |
||
1012 | // textcontrol.fontConfig = control.fontConfig; |
||
1013 | // textcontrol.isHighLight = control.isHighLight; |
||
1014 | // textcontrol.paintMethod = 1; |
||
1015 | |||
1016 | // DrawTextBox(textcontrol, contentByte, delimiterChars, delimiterChars2, _SetColor); |
||
1017 | //} |
||
1018 | |||
1019 | //using (S_ArrowControl_Multi linecontrol = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item)) |
||
1020 | //{ |
||
1021 | // linecontrol.Angle = control.Angle; |
||
1022 | // linecontrol.DashSize = new DoubleCollection(new[] {(double)999999 }); |
||
1023 | // linecontrol.EndPoint = control.EndPoint; |
||
1024 | // linecontrol.MidPoint = control.MidPoint; |
||
1025 | // linecontrol.Name = "ArrowControl_Multi"; |
||
1026 | // linecontrol.Opac = control.Opac; |
||
1027 | // linecontrol.PointSet = control.PointSet; |
||
1028 | // linecontrol.SizeSet = control.SizeSet; |
||
1029 | // linecontrol.StartPoint = control.StartPoint; |
||
1030 | // linecontrol.StrokeColor = control.StrokeColor; |
||
1031 | // linecontrol.TransformPoint = control.TransformPoint; |
||
1032 | |||
1033 | // DrawMultiArrowLine(linecontrol, contentByte, delimiterChars, delimiterChars2, _SetColor); |
||
1034 | //} |
||
1035 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1036 | Point tempStartPoint = GetPdfPointSystem(control.StartPoint); |
||
1037 | Point tempMidPoint = GetPdfPointSystem(control.MidPoint); |
||
1038 | Point tempEndPoint = GetPdfPointSystem(control.EndPoint); |
||
1039 | bool isUnderLine = false; |
||
1040 | string Text = ""; |
||
1041 | double fontsize = 30; |
||
1042 | |||
1043 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight); |
||
1044 | Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight)); |
||
1045 | List<Point> tempPoint = new List<Point>(); |
||
1046 | |||
1047 | double Angle = control.Angle; |
||
1048 | |||
1049 | if (Math.Abs(Angle).ToString() == "90") |
||
1050 | faf998c6 | taeseongkim | { |
1051 | 6a19b48d | taeseongkim | Angle = 270; |
1052 | faf998c6 | taeseongkim | } |
1053 | 6a19b48d | taeseongkim | else if (Math.Abs(Angle).ToString() == "270") |
1054 | faf998c6 | taeseongkim | { |
1055 | 6a19b48d | taeseongkim | Angle = 90; |
1056 | faf998c6 | taeseongkim | } |
1057 | |||
1058 | 6a19b48d | taeseongkim | var tempRectMidPoint = MathSet.getRectMiddlePoint(rect); |
1059 | tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y)); |
||
1060 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top)); |
||
1061 | tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y)); |
||
1062 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom)); |
||
1063 | |||
1064 | var newStartPoint = tempStartPoint; |
||
1065 | var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint); |
||
1066 | var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint); |
||
1067 | |||
1068 | //Point testPoint = tempEndPoint; |
||
1069 | //if (Angle != 0) |
||
1070 | //{ |
||
1071 | // testPoint = GetArrowTextControlTestPoint(0, newMidPoint, tempPoint, control.isFixed); |
||
1072 | // //testPoint = Test(rect, newMidPoint); |
||
1073 | //} |
||
1074 | |||
1075 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
1076 | System.Drawing.Color FontColor = _SetColor; |
||
1077 | bool isHighlight = control.isHighLight; |
||
1078 | double Opacity = control.Opac; |
||
1079 | PaintSet Paint = PaintSet.None; |
||
1080 | |||
1081 | switch (control.ArrowStyle) |
||
1082 | faf998c6 | taeseongkim | { |
1083 | 6a19b48d | taeseongkim | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal: |
1084 | faf998c6 | taeseongkim | { |
1085 | 6a19b48d | taeseongkim | Paint = PaintSet.None; |
1086 | faf998c6 | taeseongkim | } |
1087 | 6a19b48d | taeseongkim | break; |
1088 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud: |
||
1089 | faf998c6 | taeseongkim | { |
1090 | 6a19b48d | taeseongkim | Paint = PaintSet.Hatch; |
1091 | faf998c6 | taeseongkim | } |
1092 | 6a19b48d | taeseongkim | break; |
1093 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect: |
||
1094 | { |
||
1095 | Paint = PaintSet.Fill; |
||
1096 | } |
||
1097 | break; |
||
1098 | default: |
||
1099 | break; |
||
1100 | faf998c6 | taeseongkim | } |
1101 | 6a19b48d | taeseongkim | if (control.isHighLight) Paint |= PaintSet.Highlight; |
1102 | |||
1103 | if (Paint == PaintSet.Hatch) |
||
1104 | { |
||
1105 | Text = control.ArrowText; |
||
1106 | } |
||
1107 | else |
||
1108 | faf998c6 | taeseongkim | { |
1109 | 6a19b48d | taeseongkim | Text = control.ArrowText; |
1110 | faf998c6 | taeseongkim | } |
1111 | 6a19b48d | taeseongkim | |
1112 | try |
||
1113 | faf998c6 | taeseongkim | { |
1114 | 6a19b48d | taeseongkim | if (control.fontConfig.Count == 4) |
1115 | faf998c6 | taeseongkim | { |
1116 | 6a19b48d | taeseongkim | fontsize = Convert.ToDouble(control.fontConfig[3]); |
1117 | faf998c6 | taeseongkim | } |
1118 | 6a19b48d | taeseongkim | |
1119 | //강인구 수정(2018.04.17) |
||
1120 | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
||
1121 | |||
1122 | FontStyle fontStyle = FontStyles.Normal; |
||
1123 | if (FontStyles.Italic == TextStyle) |
||
1124 | faf998c6 | taeseongkim | { |
1125 | 6a19b48d | taeseongkim | fontStyle = FontStyles.Italic; |
1126 | faf998c6 | taeseongkim | } |
1127 | |||
1128 | 6a19b48d | taeseongkim | FontWeight fontWeight = FontWeights.Black; |
1129 | |||
1130 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
1131 | if (FontWeights.Bold == TextWeight) |
||
1132 | faf998c6 | taeseongkim | { |
1133 | 6a19b48d | taeseongkim | fontWeight = FontWeights.Bold; |
1134 | faf998c6 | taeseongkim | } |
1135 | |||
1136 | 6a19b48d | taeseongkim | TextDecorationCollection decoration = TextDecorations.Baseline; |
1137 | if (control.fontConfig.Count() == 5) |
||
1138 | faf998c6 | taeseongkim | { |
1139 | 6a19b48d | taeseongkim | decoration = TextDecorations.Underline; |
1140 | faf998c6 | taeseongkim | } |
1141 | 6a19b48d | taeseongkim | |
1142 | if (control.isTrans) |
||
1143 | faf998c6 | taeseongkim | { |
1144 | 6a19b48d | taeseongkim | //인구 수정 Arrow Text Style적용 되도록 변경 |
1145 | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
1146 | newStartPoint, tempMidPoint, newEndPoint, control.isFixed, |
||
1147 | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
1148 | faf998c6 | taeseongkim | } |
1149 | 6a19b48d | taeseongkim | else |
1150 | faf998c6 | taeseongkim | { |
1151 | 6a19b48d | taeseongkim | if (control.isFixed) |
1152 | faf998c6 | taeseongkim | { |
1153 | 6a19b48d | taeseongkim | var testP = new Point(0, 0); |
1154 | faf998c6 | taeseongkim | if (control.isFixed) |
1155 | { |
||
1156 | 6a19b48d | taeseongkim | if (tempPoint[1] == newEndPoint) |
1157 | faf998c6 | taeseongkim | { |
1158 | 6a19b48d | taeseongkim | testP = new Point(newEndPoint.X, newEndPoint.Y - 10); |
1159 | } |
||
1160 | else if (tempPoint[3] == newEndPoint) |
||
1161 | { |
||
1162 | testP = new Point(newEndPoint.X, newEndPoint.Y + 10); |
||
1163 | } |
||
1164 | else if (tempPoint[0] == newEndPoint) |
||
1165 | { |
||
1166 | testP = new Point(newEndPoint.X - 10, newEndPoint.Y); |
||
1167 | } |
||
1168 | else if (tempPoint[2] == newEndPoint) |
||
1169 | { |
||
1170 | testP = new Point(newEndPoint.X + 10, newEndPoint.Y); |
||
1171 | faf998c6 | taeseongkim | } |
1172 | } |
||
1173 | 6a19b48d | taeseongkim | //인구 수정 Arrow Text Style적용 되도록 변경 |
1174 | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
1175 | tempStartPoint, testP, tempEndPoint, control.isFixed, |
||
1176 | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, |
||
1177 | FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
1178 | faf998c6 | taeseongkim | } |
1179 | else |
||
1180 | { |
||
1181 | 6a19b48d | taeseongkim | //인구 수정 Arrow Text Style적용 되도록 변경 |
1182 | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
1183 | newStartPoint, tempMidPoint, tempEndPoint, control.isFixed, |
||
1184 | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
1185 | faf998c6 | taeseongkim | } |
1186 | } |
||
1187 | } |
||
1188 | 6a19b48d | taeseongkim | catch (Exception ex) |
1189 | faf998c6 | taeseongkim | { |
1190 | 6a19b48d | taeseongkim | throw ex; |
1191 | faf998c6 | taeseongkim | } |
1192 | 6a19b48d | taeseongkim | |
1193 | } |
||
1194 | break; |
||
1195 | #endregion |
||
1196 | #region SignControl |
||
1197 | case "SignControl": |
||
1198 | string signStr = null; |
||
1199 | |||
1200 | using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item)) |
||
1201 | { |
||
1202 | using (Markus.EntityModel.MarkusModel cIEntity = new Markus.EntityModel.MarkusModel(CIConnectionString)) |
||
1203 | faf998c6 | taeseongkim | { |
1204 | 6a19b48d | taeseongkim | var sIGNINFO = from sin in cIEntity.SIGN_INFO |
1205 | where sin.MEMBER_USER_ID == control.UserNumber |
||
1206 | select sin; |
||
1207 | |||
1208 | if (sIGNINFO.Count() > 0) |
||
1209 | { |
||
1210 | signStr = sIGNINFO.First().SIGN_STR; |
||
1211 | faf998c6 | taeseongkim | |
1212 | 6a19b48d | taeseongkim | double Angle = control.Angle; |
1213 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1214 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
1215 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1216 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
1217 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1218 | double Opacity = control.Opac; |
||
1219 | Controls_PDF.DrawSet_Image.DrawSign(signStr, StartPoint, EndPoint, PointSet, contentByte, Angle, Opacity); |
||
1220 | } |
||
1221 | else |
||
1222 | { |
||
1223 | FinalMakeError($"Sign Not Found. UserID : {control.UserNumber}.", StatusCodeType.SignError); |
||
1224 | } |
||
1225 | } |
||
1226 | } |
||
1227 | break; |
||
1228 | #endregion |
||
1229 | #region MyRegion |
||
1230 | case "DateControl": |
||
1231 | using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item)) |
||
1232 | { |
||
1233 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1234 | string Text = control.Text; |
||
1235 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1236 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1237 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1238 | System.Drawing.Color FontColor = _SetColor; |
||
1239 | double Angle = control.Angle; |
||
1240 | double Opacity = control.Opac; |
||
1241 | Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity); |
||
1242 | } |
||
1243 | break; |
||
1244 | #endregion |
||
1245 | #region SymControlN (APPROVED) |
||
1246 | case "SymControlN": |
||
1247 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1248 | { |
||
1249 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1250 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1251 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1252 | System.Drawing.Color FontColor = _SetColor; |
||
1253 | double Angle = control.Angle; |
||
1254 | double Opacity = control.Opac; |
||
1255 | |||
1256 | using (Markus.EntityModel.MarkusModel _entity = new Markus.EntityModel.MarkusModel(MarkusConnectionString)) |
||
1257 | { |
||
1258 | faf998c6 | taeseongkim | var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP"); |
1259 | |||
1260 | if (stamp.Count() > 0) |
||
1261 | { |
||
1262 | var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE); |
||
1263 | |||
1264 | var Contents = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP_CONTENTS"); |
||
1265 | 6a19b48d | taeseongkim | |
1266 | faf998c6 | taeseongkim | if (Contents?.Count() > 0) |
1267 | { |
||
1268 | foreach (var content in Contents) |
||
1269 | { |
||
1270 | xamldata = xamldata.Replace(content.PROPERTY, System.Security.SecurityElement.Escape(content.VALUE)); |
||
1271 | } |
||
1272 | } |
||
1273 | |||
1274 | Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata); |
||
1275 | } |
||
1276 | } |
||
1277 | |||
1278 | 6a19b48d | taeseongkim | //string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", ""); |
1279 | |||
1280 | } |
||
1281 | break; |
||
1282 | case "SymControl": |
||
1283 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1284 | { |
||
1285 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1286 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1287 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1288 | System.Drawing.Color FontColor = _SetColor; |
||
1289 | double Angle = control.Angle; |
||
1290 | double Opacity = control.Opac; |
||
1291 | |||
1292 | string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", ""); |
||
1293 | Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
||
1294 | } |
||
1295 | break; |
||
1296 | #endregion |
||
1297 | #region Image |
||
1298 | case "ImgControl": |
||
1299 | using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item)) |
||
1300 | { |
||
1301 | double Angle = control.Angle; |
||
1302 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1303 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
1304 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1305 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
1306 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1307 | double Opacity = control.Opac; |
||
1308 | string FilePath = control.ImagePath; |
||
1309 | //Uri uri = new Uri(s.ImagePath); |
||
1310 | |||
1311 | Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity); |
||
1312 | } |
||
1313 | break; |
||
1314 | #endregion |
||
1315 | default: |
||
1316 | FinalMakeError($"{ControlT.Name} Not Support", StatusCodeType.FileError); |
||
1317 | break; |
||
1318 | faf998c6 | taeseongkim | } |
1319 | |||
1320 | 6a19b48d | taeseongkim | } |
1321 | catch (Exception ex) |
||
1322 | { |
||
1323 | FinalMakeError($"markupItem : {markupItem.ID}" + ex.ToString(), StatusCodeType.Error); |
||
1324 | } |
||
1325 | finally |
||
1326 | { |
||
1327 | //if (ControlT?.Name != null) |
||
1328 | //{ |
||
1329 | // strLog.Append($"{ControlT.Name},"); |
||
1330 | //} |
||
1331 | } |
||
1332 | faf998c6 | taeseongkim | } |
1333 | |||
1334 | } |
||
1335 | } |
||
1336 | 6a19b48d | taeseongkim | |
1337 | #if ProcessDebug |
||
1338 | Console.WriteLine($"FinalID :{FinalID} status :{StatusCodeType.Stamp.ToString()}, current Page :{CurrentPage.PAGE_NUMBER} totalPage : {CurrentPage.PAGE_NUMBER}"); |
||
1339 | #else |
||
1340 | FinalServiceClient.FinalProcessState(FinalID, (int)StatusCodeType.Stamp, CurrentPage.PAGE_NUMBER, CurrentPage.PAGE_NUMBER, ""); |
||
1341 | #endif |
||
1342 | |||
1343 | MarkupToPDF.logger.Info(strLog.ToString()); |
||
1344 | |||
1345 | //PdfFileSpecification pfs = PdfFileSpecification.FileEmbedded(pdfStamper.Writer, @"C:\Users\kts\Documents\업무\CARS\엑셀양식\F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", "F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", null); |
||
1346 | //pdfStamper.AddFileAttachment("F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", pfs); |
||
1347 | |||
1348 | pdfStamper.Outlines = root; |
||
1349 | pdfStamper.Close(); |
||
1350 | pdfReader.Close(); |
||
1351 | faf998c6 | taeseongkim | } |
1352 | } |
||
1353 | 6a19b48d | taeseongkim | #endregion |
1354 | faf998c6 | taeseongkim | } |
1355 | |||
1356 | if (tempFileInfo.Exists) |
||
1357 | { |
||
1358 | #if !DEBUG |
||
1359 | tempFileInfo.Delete(); |
||
1360 | #endif |
||
1361 | } |
||
1362 | |||
1363 | if (File.Exists(pdfFilePath)) |
||
1364 | { |
||
1365 | string destfilepath = null; |
||
1366 | try |
||
1367 | { |
||
1368 | FinalPDFPath = new FileInfo(pdfFilePath); |
||
1369 | |||
1370 | /// 정리 필요함. DB로 변경 |
||
1371 | string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", ""); |
||
1372 | |||
1373 | if(!string.IsNullOrEmpty(pdfmovepath)) |
||
1374 | { |
||
1375 | _FinalPDFStorgeLocal = pdfmovepath; |
||
1376 | } |
||
1377 | |||
1378 | destfilepath = Path.Combine(_FinalPDFStorgeLocal, FinalPDFPath.Name.Replace(".tmp", ".pdf")); |
||
1379 | |||
1380 | if (File.Exists(destfilepath)) |
||
1381 | File.Delete(destfilepath); |
||
1382 | |||
1383 | File.Move(FinalPDFPath.FullName, destfilepath); |
||
1384 | FinalPDFPath = new FileInfo(destfilepath); |
||
1385 | File.Delete(pdfFilePath); |
||
1386 | } |
||
1387 | catch (Exception ex) |
||
1388 | { |
||
1389 | 6a19b48d | taeseongkim | FinalMakeError($"File move error - Source File : {FinalPDFPath.FullName} dest File : {destfilepath}" + ex.ToString(), StatusCodeType.StampError); |
1390 | faf998c6 | taeseongkim | } |
1391 | |||
1392 | return true; |
||
1393 | } |
||
1394 | } |
||
1395 | catch (Exception ex) |
||
1396 | { |
||
1397 | 6a19b48d | taeseongkim | FinalMakeError("SetStempinPDF error: " + ex.ToString(), StatusCodeType.StampError); |
1398 | faf998c6 | taeseongkim | } |
1399 | return false; |
||
1400 | } |
||
1401 | |||
1402 | /// <summary> |
||
1403 | /// kcom의 화살표방향과 틀려 추가함 |
||
1404 | /// </summary> |
||
1405 | /// <param name="PageAngle"></param> |
||
1406 | /// <param name="endP"></param> |
||
1407 | /// <param name="ps">box Points</param> |
||
1408 | /// <param name="IsFixed"></param> |
||
1409 | /// <returns></returns> |
||
1410 | private Point GetArrowTextControlTestPoint(double PageAngle,Point endP,List<Point> ps,bool IsFixed) |
||
1411 | { |
||
1412 | Point testP = endP; |
||
1413 | |||
1414 | try |
||
1415 | { |
||
1416 | switch (Math.Abs(PageAngle).ToString()) |
||
1417 | { |
||
1418 | case "90": |
||
1419 | testP = new Point(endP.X + 50, endP.Y); |
||
1420 | break; |
||
1421 | case "270": |
||
1422 | testP = new Point(endP.X - 50, endP.Y); |
||
1423 | break; |
||
1424 | } |
||
1425 | |||
1426 | //20180910 LJY 각도에 따라. |
||
1427 | switch (Math.Abs(PageAngle).ToString()) |
||
1428 | { |
||
1429 | case "90": |
||
1430 | if (IsFixed) |
||
1431 | { |
||
1432 | if (ps[0] == endP) //상단 |
||
1433 | { |
||
1434 | testP = new Point(endP.X, endP.Y + 50); |
||
1435 | //System.Diagnostics.Debug.WriteLine("상단"+ testP); |
||
1436 | } |
||
1437 | else if (ps[1] == endP) //하단 |
||
1438 | { |
||
1439 | testP = new Point(endP.X, endP.Y - 50); |
||
1440 | //System.Diagnostics.Debug.WriteLine("하단"+ testP); |
||
1441 | } |
||
1442 | else if (ps[2] == endP) //좌단 |
||
1443 | { |
||
1444 | testP = new Point(endP.X - 50, endP.Y); |
||
1445 | //System.Diagnostics.Debug.WriteLine("좌단"+ testP); |
||
1446 | } |
||
1447 | else if (ps[3] == endP) //우단 |
||
1448 | { |
||
1449 | testP = new Point(endP.X + 50, endP.Y); |
||
1450 | //System.Diagnostics.Debug.WriteLine("우단"+ testP); |
||
1451 | } |
||
1452 | } |
||
1453 | break; |
||
1454 | case "270": |
||
1455 | if (IsFixed) |
||
1456 | { |
||
1457 | if (ps[0] == endP) //상단 |
||
1458 | { |
||
1459 | testP = new Point(endP.X, endP.Y - 50); |
||
1460 | //System.Diagnostics.Debug.WriteLine("상단" + testP); |
||
1461 | } |
||
1462 | else if (ps[1] == endP) //하단 |
||
1463 | { |
||
1464 | testP = new Point(endP.X, endP.Y + 50); |
||
1465 | //System.Diagnostics.Debug.WriteLine("하단" + testP); |
||
1466 | } |
||
1467 | else if (ps[2] == endP) //좌단 |
||
1468 | { |
||
1469 | testP = new Point(endP.X + 50, endP.Y); |
||
1470 | //System.Diagnostics.Debug.WriteLine("좌단" + testP); |
||
1471 | } |
||
1472 | else if (ps[3] == endP) //우단 |
||
1473 | { |
||
1474 | testP = new Point(endP.X - 50, endP.Y); |
||
1475 | //System.Diagnostics.Debug.WriteLine("우단" + testP); |
||
1476 | } |
||
1477 | } |
||
1478 | break; |
||
1479 | default: |
||
1480 | if (IsFixed) |
||
1481 | { |
||
1482 | |||
1483 | if (ps[0] == endP) //상단 |
||
1484 | { |
||
1485 | testP = new Point(endP.X, endP.Y - 50); |
||
1486 | //System.Diagnostics.Debug.WriteLine("상단"); |
||
1487 | } |
||
1488 | else if (ps[1] == endP) //하단 |
||
1489 | { |
||
1490 | testP = new Point(endP.X, endP.Y + 50); |
||
1491 | //System.Diagnostics.Debug.WriteLine("하단"); |
||
1492 | } |
||
1493 | else if (ps[2] == endP) //좌단 |
||
1494 | { |
||
1495 | testP = new Point(endP.X - 50, endP.Y); |
||
1496 | //System.Diagnostics.Debug.WriteLine("좌단"); |
||
1497 | } |
||
1498 | else if (ps[3] == endP) //우단 |
||
1499 | { |
||
1500 | testP = new Point(endP.X + 50, endP.Y); |
||
1501 | //System.Diagnostics.Debug.WriteLine("우단"); |
||
1502 | } |
||
1503 | } |
||
1504 | break; |
||
1505 | } |
||
1506 | |||
1507 | } |
||
1508 | catch (Exception) |
||
1509 | { |
||
1510 | } |
||
1511 | |||
1512 | return testP; |
||
1513 | } |
||
1514 | |||
1515 | private Point Test(Rect rect,Point point) |
||
1516 | { |
||
1517 | Point result = new Point(); |
||
1518 | |||
1519 | Point newPoint = new Point(); |
||
1520 | |||
1521 | double oldNear = 0; |
||
1522 | double newNear = 0; |
||
1523 | |||
1524 | oldNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.TopRight, out result); |
||
1525 | |||
1526 | newNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.BottomLeft, out newPoint); |
||
1527 | |||
1528 | if (newNear < oldNear) |
||
1529 | { |
||
1530 | oldNear = newNear; |
||
1531 | result = newPoint; |
||
1532 | } |
||
1533 | |||
1534 | newNear = MathSet.GetShortestDistance(point, rect.TopRight, rect.BottomRight, out newPoint); |
||
1535 | |||
1536 | if (newNear < oldNear) |
||
1537 | { |
||
1538 | oldNear = newNear; |
||
1539 | result = newPoint; |
||
1540 | } |
||
1541 | |||
1542 | |||
1543 | newNear = MathSet.GetShortestDistance(point, rect.BottomLeft, rect.BottomRight, out newPoint); |
||
1544 | |||
1545 | if (newNear < oldNear) |
||
1546 | { |
||
1547 | oldNear = newNear; |
||
1548 | result = newPoint; |
||
1549 | } |
||
1550 | |||
1551 | return result; |
||
1552 | } |
||
1553 | |||
1554 | private void DrawMultiArrowLine(S_ArrowControl_Multi control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor) |
||
1555 | { |
||
1556 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1557 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1558 | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
||
1559 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1560 | DoubleCollection DashSize = control.DashSize; |
||
1561 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1562 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
1563 | |||
1564 | double Opacity = control.Opac; |
||
1565 | |||
1566 | if (EndPoint == MidPoint) |
||
1567 | { |
||
1568 | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, setColor, Opacity); |
||
1569 | } |
||
1570 | else |
||
1571 | { |
||
1572 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, setColor, Opacity); |
||
1573 | } |
||
1574 | |||
1575 | Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, setColor, Opacity); |
||
1576 | |||
1577 | } |
||
1578 | |||
1579 | private void DrawLine(S_LineControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor) |
||
1580 | { |
||
1581 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1582 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1583 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1584 | DoubleCollection DashSize = control.DashSize; |
||
1585 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1586 | |||
1587 | var Opacity = control.Opac; |
||
1588 | string UserID = control.UserID; |
||
1589 | double Interval = control.Interval; |
||
1590 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
1591 | Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, setColor, Opacity); |
||
1592 | switch (control.LineStyleSet) |
||
1593 | { |
||
1594 | case LineStyleSet.ArrowLine: |
||
1595 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity); |
||
1596 | break; |
||
1597 | case LineStyleSet.CancelLine: |
||
1598 | { |
||
1599 | var x = Math.Abs((Math.Abs(control.StartPoint.X) - Math.Abs(control.EndPoint.X))); |
||
1600 | var y = Math.Abs((Math.Abs(control.StartPoint.Y) - Math.Abs(control.EndPoint.Y))); |
||
1601 | |||
1602 | Point newStartPoint = new Point(); |
||
1603 | Point newEndPoint = new Point(); |
||
1604 | |||
1605 | if (x > y) |
||
1606 | { |
||
1607 | newStartPoint = new Point(control.StartPoint.X, control.StartPoint.Y + control.Interval); |
||
1608 | newEndPoint = new Point(control.EndPoint.X, control.EndPoint.Y + control.Interval); |
||
1609 | } |
||
1610 | else |
||
1611 | { |
||
1612 | newStartPoint = new Point(control.StartPoint.X + control.Interval, control.StartPoint.Y); |
||
1613 | newEndPoint = new Point(control.EndPoint.X + control.Interval, control.EndPoint.Y); |
||
1614 | } |
||
1615 | |||
1616 | newStartPoint = GetPdfPointSystem(newStartPoint); |
||
1617 | newEndPoint = GetPdfPointSystem(newEndPoint); |
||
1618 | |||
1619 | Controls_PDF.DrawSet_Line.DrawLine(newStartPoint, newEndPoint, LineSize, contentByte, DashSize, setColor, Opacity); |
||
1620 | } |
||
1621 | break; |
||
1622 | case LineStyleSet.TwinLine: |
||
1623 | { |
||
1624 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity); |
||
1625 | Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity); |
||
1626 | } |
||
1627 | break; |
||
1628 | case LineStyleSet.DimLine: |
||
1629 | { |
||
1630 | Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity); |
||
1631 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity); |
||
1632 | Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity); |
||
1633 | } |
||
1634 | break; |
||
1635 | default: |
||
1636 | break; |
||
1637 | } |
||
1638 | |||
1639 | } |
||
1640 | |||
1641 | private void DrawTextBox(S_TextControl control,PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2,System.Drawing.Color setColor) |
||
1642 | { |
||
1643 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1644 | string Text = control.Text; |
||
1645 | |||
1646 | bool isUnderline = false; |
||
1647 | control.BoxW -= scaleWidth; |
||
1648 | control.BoxH -= scaleHeight; |
||
1649 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH); |
||
1650 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1651 | Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH)); |
||
1652 | |||
1653 | List<Point> pointSet = new List<Point>(); |
||
1654 | pointSet.Add(StartPoint); |
||
1655 | pointSet.Add(EndPoint); |
||
1656 | |||
1657 | PaintSet paint = PaintSet.None; |
||
1658 | switch (control.paintMethod) |
||
1659 | { |
||
1660 | case 1: |
||
1661 | { |
||
1662 | paint = PaintSet.Fill; |
||
1663 | } |
||
1664 | break; |
||
1665 | case 2: |
||
1666 | { |
||
1667 | paint = PaintSet.Hatch; |
||
1668 | } |
||
1669 | break; |
||
1670 | default: |
||
1671 | break; |
||
1672 | } |
||
1673 | if (control.isHighLight) paint |= PaintSet.Highlight; |
||
1674 | |||
1675 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
1676 | double TextSize = Convert.ToDouble(data2[1]); |
||
1677 | System.Drawing.Color FontColor = setColor; |
||
1678 | double Angle = control.Angle; |
||
1679 | double Opacity = control.Opac; |
||
1680 | FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]); |
||
1681 | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
||
1682 | |||
1683 | FontStyle fontStyle = FontStyles.Normal; |
||
1684 | if (FontStyles.Italic == TextStyle) |
||
1685 | { |
||
1686 | fontStyle = FontStyles.Italic; |
||
1687 | } |
||
1688 | |||
1689 | FontWeight fontWeight = FontWeights.Black; |
||
1690 | |||
1691 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
1692 | //강인구 수정(2018.04.17) |
||
1693 | if (FontWeights.Bold == TextWeight) |
||
1694 | //if (FontWeights.ExtraBold == TextWeight) |
||
1695 | { |
||
1696 | fontWeight = FontWeights.Bold; |
||
1697 | } |
||
1698 | |||
1699 | TextDecorationCollection decoration = TextDecorations.Baseline; |
||
1700 | if (control.fontConfig.Count() == 4) |
||
1701 | { |
||
1702 | decoration = TextDecorations.Underline; |
||
1703 | } |
||
1704 | |||
1705 | Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, setColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
1706 | } |
||
1707 | |||
1708 | |||
1709 | ~MarkupToPDF() |
||
1710 | { |
||
1711 | this.Dispose(false); |
||
1712 | } |
||
1713 | |||
1714 | private bool disposed; |
||
1715 | |||
1716 | public void Dispose() |
||
1717 | { |
||
1718 | this.Dispose(true); |
||
1719 | GC.SuppressFinalize(this); |
||
1720 | } |
||
1721 | |||
1722 | protected virtual void Dispose(bool disposing) |
||
1723 | { |
||
1724 | if (this.disposed) return; |
||
1725 | if (disposing) |
||
1726 | { |
||
1727 | // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다. |
||
1728 | } |
||
1729 | // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다. |
||
1730 | this.disposed = true; |
||
1731 | } |
||
1732 | |||
1733 | #endregion |
||
1734 | } |
||
1735 | } |