프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 5ba8f2d5

이력 | 보기 | 이력해설 | 다운로드 (92.8 KB)

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