프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ a7bee7cf

이력 | 보기 | 이력해설 | 다운로드 (90.5 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 e0f00e26 djkim
                        PdfReader pdfReader = new PdfReader(pdfStream);
601
                        //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
602
                        Dictionary<string, object> bookmark;
603
                        List<Dictionary<string, object>> outlines;
604 faebcce2 taeseongkim
605 e0f00e26 djkim
                        outlines = new List<Dictionary<string, object>>();
606
                        List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
607
608
                        var dic = new Dictionary<string, object>();
609 faebcce2 taeseongkim
610 e0f00e26 djkim
                        foreach (var data in MarkupDataSet)
611
                        {
612 b42dd24d taeseongkim
                            //StatusChange("MarkupDataSet", 0);
613 abaa85b4 djkim
614 e0f00e26 djkim
                            string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
615
616 faebcce2 taeseongkim
                            string username = "";
617
                            string userdept = "";
618
619
                            using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
620
                            {
621
                                var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
622
623
                                if(memberlist.Count() > 0)
624
                                {
625
                                    username = memberlist.First().NAME;
626
                                    userdept = memberlist.First().DEPARTMENT;
627
                                }
628
                            }
629
630 e0f00e26 djkim
                            bookmark = new Dictionary<string, object>();
631
                            bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
632
                            bookmark.Add("Page", data.PAGENUMBER + " Fit");
633
                            bookmark.Add("Action", "GoTo");
634
                            bookmark.Add("Kids", outlines);
635
                            root.Add(bookmark);
636
                        }
637 abaa85b4 djkim
638
639 e0f00e26 djkim
                        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
640 8c3a888c djkim
                        {
641 782ad7b1 taeseongkim
                            try
642
                            {
643 77cdac33 taeseongkim
                                if (pdfStamper.AcroFields != null && pdfStamper.AcroFields.GenerateAppearances != true)
644 782ad7b1 taeseongkim
                                {
645 77cdac33 taeseongkim
                                    pdfStamper.AcroFields.GenerateAppearances = true;
646 782ad7b1 taeseongkim
                                }
647
                            }
648
                            catch (Exception ex)
649
                            {
650
                                SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
651
                            }
652 c206d293 taeseongkim
653 e0f00e26 djkim
                            var _SetColor = new SolidColorBrush(Colors.Red);
654 7ca218b3 KangIngu
655 e0f00e26 djkim
                            string[] delimiterChars = { "|DZ|" };
656
                            string[] delimiterChars2 = { "|" };
657 7ca218b3 KangIngu
658 e0f00e26 djkim
                            //pdfStamper.FormFlattening = true; //이미 선처리 작업함
659
                            pdfStamper.SetFullCompression();
660
                            _SetColor = new SolidColorBrush(Colors.Red);
661 7ca218b3 KangIngu
662 b42dd24d taeseongkim
                            StringBuilder strLog = new StringBuilder();
663
                            int lastPageNo = 0;
664
665
                            strLog.Append($"Write {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} markup Count : {MarkupDataSet.Count()} / ");
666
667 e0f00e26 djkim
                            foreach (var markupItem in MarkupDataSet)
668 8c3a888c djkim
                            {
669 ff665e73 taeseongkim
                                /// 2020.11.13 김태성
670
                                /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함.
671
                                var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER);
672 7ca218b3 KangIngu
673 ff665e73 taeseongkim
                                if(pageitems.Count() > 0)
674 2e1d6c99 djkim
                                {
675 ff665e73 taeseongkim
                                    var currentPage = pageitems.First();
676
                                    pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER);
677 b42dd24d taeseongkim
                                    lastPageNo = markupItem.PAGENUMBER;
678 ff665e73 taeseongkim
                                    //try
679
                                    //{
680 b42dd24d taeseongkim
681 ff665e73 taeseongkim
                                    //}
682
                                    //catch (Exception ex)
683
                                    //{
684
                                    //    SetNotice(finaldata.ID, $"GetPageSizeWithRotation Error PageNO : {markupItem.PAGENUMBER} " + ex.ToString());
685
                                    //}
686
                                    //finally
687
                                    //{
688
                                    //    pdfSize = new iTextSharp.text.Rectangle(0, 0, float.Parse(currentPage.PAGE_WIDTH), float.Parse(currentPage.PAGE_HEIGHT));
689
                                    //}
690
691
                                    mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER);
692
                                    var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER);
693
694
                                    /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
695
                                    if (cropBox != null &&
696
                                        (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
697
                                    {
698
                                        PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
699 7aa36857 humkyung
700 ff665e73 taeseongkim
                                        PdfArray oNewMediaBox = new PdfArray();
701
                                        oNewMediaBox.Add(new PdfNumber(cropBox.Left));
702
                                        oNewMediaBox.Add(new PdfNumber(cropBox.Top));
703
                                        oNewMediaBox.Add(new PdfNumber(cropBox.Right));
704
                                        oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
705
                                        dict.Put(PdfName.MEDIABOX, oNewMediaBox);
706 7aa36857 humkyung
707 ff665e73 taeseongkim
                                        pdfSize = cropBox;
708
                                    }
709 7ca218b3 KangIngu
710 ff665e73 taeseongkim
                                    scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
711
                                    scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
712 8c3a888c djkim
713 ff665e73 taeseongkim
                                    pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
714
                                    _entity.SaveChanges();
715 e0f00e26 djkim
716 ff665e73 taeseongkim
                                    string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
717 e0f00e26 djkim
718 ff665e73 taeseongkim
                                    PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
719 b42dd24d taeseongkim
                                    strLog.Append($"{markupItem.PAGENUMBER}/");
720 ff665e73 taeseongkim
721
                                    foreach (var data in markedData)
722 8c3a888c djkim
                                    {
723 ff665e73 taeseongkim
                                        var item = JsonSerializerHelper.UnCompressString(data);
724
                                        var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
725
726
                                        try
727 e0f00e26 djkim
                                        {
728 ff665e73 taeseongkim
                                            switch (ControlT.Name)
729
                                            {
730
                                                #region LINE
731
                                                case "LineControl":
732 8c3a888c djkim
                                                    {
733 ff665e73 taeseongkim
                                                        using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
734
                                                        {
735
                                                            DrawLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
736
                                                        }
737 e0f00e26 djkim
                                                    }
738 ff665e73 taeseongkim
                                                    break;
739
                                                #endregion
740
                                                #region ArrowControlMulti
741
                                                case "ArrowControl_Multi":
742 e0f00e26 djkim
                                                    {
743 ff665e73 taeseongkim
                                                        using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
744
                                                        {
745
                                                            DrawMultiArrowLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
746
                                                        }
747 e0f00e26 djkim
                                                    }
748 ff665e73 taeseongkim
                                                    break;
749
                                                #endregion
750
                                                #region PolyControl
751
                                                case "PolygonControl":
752
                                                    using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
753 abaa85b4 djkim
                                                    {
754 e0f00e26 djkim
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
755
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
756
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
757
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
758
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
759 ff665e73 taeseongkim
                                                        double Opacity = control.Opac;
760
                                                        DoubleCollection DashSize = control.DashSize;
761 e0f00e26 djkim
762 ff665e73 taeseongkim
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
763
                                                    }
764
                                                    break;
765
                                                #endregion
766
                                                #region ArcControl or ArrowArcControl
767
                                                case "ArcControl":
768
                                                case "ArrowArcControl":
769
                                                    {
770
                                                        using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
771 8c3a888c djkim
                                                        {
772 ff665e73 taeseongkim
                                                            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
773
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
774
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
775
                                                            Point MidPoint = GetPdfPointSystem(control.MidPoint);
776
                                                            DoubleCollection DashSize = control.DashSize;
777
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
778
779
                                                            var Opacity = control.Opac;
780
                                                            string UserID = control.UserID;
781
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
782
                                                            bool IsTransOn = control.IsTransOn;
783
784
                                                            if (control.IsTransOn)
785
                                                            {
786
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
787
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
788
                                                            }
789
                                                            else
790
                                                            {
791 a7bee7cf taeseongkim
                                                                Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
792 ff665e73 taeseongkim
                                                            }
793 e0f00e26 djkim
794 ff665e73 taeseongkim
                                                            if (ControlT.Name == "ArrowArcControl")
795
                                                            {
796
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
797
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
798
                                                            }
799 c206d293 taeseongkim
                                                        }
800 abaa85b4 djkim
                                                    }
801 ff665e73 taeseongkim
                                                    break;
802
                                                #endregion
803
                                                #region RectangleControl
804
                                                case "RectangleControl":
805
                                                    using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
806 e0f00e26 djkim
                                                    {
807 ff665e73 taeseongkim
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
808
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
809
                                                        var PaintStyle = control.PaintState;
810
                                                        double Angle = control.Angle;
811
                                                        DoubleCollection DashSize = control.DashSize;
812
                                                        double Opacity = control.Opac;
813
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
814
815
                                                        Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
816 e0f00e26 djkim
                                                    }
817 ff665e73 taeseongkim
                                                    break;
818
                                                #endregion
819
                                                #region TriControl
820
                                                case "TriControl":
821
                                                    using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
822 e0f00e26 djkim
                                                    {
823 ff665e73 taeseongkim
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
824
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
825
                                                        var PaintStyle = control.Paint;
826
                                                        double Angle = control.Angle;
827
                                                        //StrokeColor = _SetColor, //색상은 레드
828
                                                        DoubleCollection DashSize = control.DashSize;
829
                                                        double Opacity = control.Opac;
830
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
831
832
                                                        Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
833 e0f00e26 djkim
                                                    }
834 ff665e73 taeseongkim
                                                    break;
835
                                                #endregion
836
                                                #region CircleControl
837
                                                case "CircleControl":
838
                                                    using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
839 e0f00e26 djkim
                                                    {
840 ff665e73 taeseongkim
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
841
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
842
                                                        var StartPoint = GetPdfPointSystem(control.StartPoint);
843
                                                        var EndPoint = GetPdfPointSystem(control.EndPoint);
844
                                                        var PaintStyle = control.PaintState;
845
                                                        double Angle = control.Angle;
846
                                                        DoubleCollection DashSize = control.DashSize;
847
                                                        double Opacity = control.Opac;
848
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
849
                                                        Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
850
851 e0f00e26 djkim
                                                    }
852 ff665e73 taeseongkim
                                                    break;
853
                                                #endregion
854
                                                #region RectCloudControl
855
                                                case "RectCloudControl":
856
                                                    using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
857 e0f00e26 djkim
                                                    {
858 ff665e73 taeseongkim
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
859
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
860
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
861
                                                        double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
862
863
                                                        double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
864
865
                                                        var PaintStyle = control.PaintState;
866
                                                        double Opacity = control.Opac;
867
                                                        DoubleCollection DashSize = control.DashSize;
868
869
                                                        //드로잉 방식이 표현되지 않음
870
                                                        var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
871
872
                                                        double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
873
                                                        bool reverse = (area < 0);
874
                                                        if (PaintStyle == PaintSet.None)
875 8c3a888c djkim
                                                        {
876 ff665e73 taeseongkim
                                                            Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
877
                                                        }
878
                                                        else
879
                                                        {
880
                                                            Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
881
                                                        }
882
                                                    }
883
                                                    break;
884
                                                #endregion
885
                                                #region CloudControl
886
                                                case "CloudControl":
887
                                                    using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
888
                                                    {
889
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
890
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
891
                                                        double Toler = control.Toler;
892
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
893
                                                        double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
894
                                                        var PaintStyle = control.PaintState;
895
                                                        double Opacity = control.Opac;
896
                                                        bool isTransOn = control.IsTrans;
897
                                                        bool isChain = control.IsChain;
898
899
                                                        DoubleCollection DashSize = control.DashSize;
900 e0f00e26 djkim
901 ff665e73 taeseongkim
                                                        if (isChain)
902
                                                        {
903
                                                            Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
904
                                                        }
905
                                                        else
906
                                                        {
907
                                                            if (isTransOn)
908 e0f00e26 djkim
                                                            {
909 ff665e73 taeseongkim
                                                                double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
910
                                                                bool reverse = (area < 0);
911
912
                                                                if (PaintStyle == PaintSet.None)
913
                                                                {
914
                                                                    Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
915
                                                                }
916
                                                                else
917
                                                                {
918
                                                                    Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
919
                                                                }
920 e0f00e26 djkim
                                                            }
921
                                                            else
922
                                                            {
923 ff665e73 taeseongkim
                                                                Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
924 e0f00e26 djkim
                                                            }
925 8c3a888c djkim
                                                        }
926 ff665e73 taeseongkim
                                                    }
927
                                                    break;
928
                                                #endregion
929
                                                #region TEXT
930
                                                case "TextControl":
931
                                                    using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
932
                                                    {
933
                                                        DrawTextBox(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
934
                                                    }
935
                                                    break;
936
                                                #endregion
937
                                                #region ArrowTextControl
938
                                                case "ArrowTextControl":
939
                                                    using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
940
                                                    {
941
                                                        //using (S_TextControl textcontrol = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
942
                                                        //{
943
                                                        //    textcontrol.Angle = control.Angle;
944
                                                        //    textcontrol.BoxH = control.BoxHeight;
945
                                                        //    textcontrol.BoxW = control.BoxWidth;
946
                                                        //    textcontrol.EndPoint = control.EndPoint;
947
                                                        //    textcontrol.FontColor = "#FFFF0000";
948
                                                        //    textcontrol.Name = "TextControl";
949
                                                        //    textcontrol.Opac = control.Opac;
950
                                                        //    textcontrol.PointSet = new List<Point>();
951
                                                        //    textcontrol.SizeSet = string.Join(delimiterChars2.First(), control.SizeSet.First(), control.fontConfig[3]);
952
                                                        //    textcontrol.StartPoint = control.StartPoint;
953
                                                        //    textcontrol.Text = control.ArrowText;
954
                                                        //    textcontrol.TransformPoint = control.TransformPoint;
955
                                                        //    textcontrol.UserID = null;
956
                                                        //    textcontrol.fontConfig = control.fontConfig;
957
                                                        //    textcontrol.isHighLight = control.isHighLight;
958
                                                        //    textcontrol.paintMethod = 1;
959
960
                                                        //    DrawTextBox(textcontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
961
                                                        //}
962
963
                                                        //using (S_ArrowControl_Multi linecontrol = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
964
                                                        //{
965
                                                        //    linecontrol.Angle = control.Angle;
966
                                                        //    linecontrol.DashSize = new DoubleCollection(new[] {(double)999999 });
967
                                                        //    linecontrol.EndPoint = control.EndPoint;
968
                                                        //    linecontrol.MidPoint = control.MidPoint;
969
                                                        //    linecontrol.Name = "ArrowControl_Multi";
970
                                                        //    linecontrol.Opac = control.Opac;
971
                                                        //    linecontrol.PointSet = control.PointSet;
972
                                                        //    linecontrol.SizeSet = control.SizeSet;
973
                                                        //    linecontrol.StartPoint = control.StartPoint;
974
                                                        //    linecontrol.StrokeColor = control.StrokeColor;
975
                                                        //    linecontrol.TransformPoint = control.TransformPoint;
976
977
                                                        //    DrawMultiArrowLine(linecontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
978
                                                        //}
979
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
980
                                                        Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
981
                                                        Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
982
                                                        Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
983
                                                        bool isUnderLine = false;
984
                                                        string Text = "";
985
                                                        double fontsize = 30;
986
987
                                                        System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
988
                                                        Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight));
989
                                                        List<Point> tempPoint = new List<Point>();
990
991
                                                        double Angle = control.Angle;
992
993
                                                        if (Math.Abs(Angle).ToString() == "90")
994 8c3a888c djkim
                                                        {
995 ff665e73 taeseongkim
                                                            Angle = 270;
996 8c3a888c djkim
                                                        }
997 ff665e73 taeseongkim
                                                        else if (Math.Abs(Angle).ToString() == "270")
998 4f017ed3 taeseongkim
                                                        {
999 ff665e73 taeseongkim
                                                            Angle = 90;
1000
                                                        }
1001
1002
                                                        var tempRectMidPoint = MathSet.getRectMiddlePoint(rect);
1003
                                                        tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y));
1004
                                                        tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top));
1005
                                                        tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y));
1006
                                                        tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom));
1007
1008
                                                        var newStartPoint = tempStartPoint;
1009
                                                        var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint);
1010
                                                        var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint);
1011
1012
                                                        //Point testPoint = tempEndPoint;
1013
                                                        //if (Angle != 0)
1014
                                                        //{
1015
                                                        //    testPoint = GetArrowTextControlTestPoint(0, newMidPoint, tempPoint, control.isFixed);
1016
                                                        //   //testPoint = Test(rect, newMidPoint);
1017
                                                        //}
1018
1019
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1020
                                                        SolidColorBrush FontColor = _SetColor;
1021
                                                        bool isHighlight = control.isHighLight;
1022
                                                        double Opacity = control.Opac;
1023
                                                        PaintSet Paint = PaintSet.None;
1024
1025
                                                        switch (control.ArrowStyle)
1026
                                                        {
1027
                                                            case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
1028
                                                                {
1029
                                                                    Paint = PaintSet.None;
1030
                                                                }
1031
                                                                break;
1032
                                                            case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
1033
                                                                {
1034
                                                                    Paint = PaintSet.Hatch;
1035
                                                                }
1036
                                                                break;
1037
                                                            case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
1038
                                                                {
1039
                                                                    Paint = PaintSet.Fill;
1040
                                                                }
1041
                                                                break;
1042
                                                            default:
1043
                                                                break;
1044 4f017ed3 taeseongkim
                                                        }
1045 ff665e73 taeseongkim
                                                        if (control.isHighLight) Paint |= PaintSet.Highlight;
1046
1047
                                                        if (Paint == PaintSet.Hatch)
1048 4f017ed3 taeseongkim
                                                        {
1049 ff665e73 taeseongkim
                                                            Text = control.ArrowText;
1050 4f017ed3 taeseongkim
                                                        }
1051 ff665e73 taeseongkim
                                                        else
1052 4f017ed3 taeseongkim
                                                        {
1053 ff665e73 taeseongkim
                                                            Text = control.ArrowText;
1054 4f017ed3 taeseongkim
                                                        }
1055 8c3a888c djkim
1056 ff665e73 taeseongkim
                                                        try
1057
                                                        {
1058
                                                            if (control.fontConfig.Count == 4)
1059
                                                            {
1060
                                                                fontsize = Convert.ToDouble(control.fontConfig[3]);
1061
                                                            }
1062 4f017ed3 taeseongkim
1063 ff665e73 taeseongkim
                                                            //강인구 수정(2018.04.17)
1064
                                                            var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1065 8c3a888c djkim
1066 ff665e73 taeseongkim
                                                            FontStyle fontStyle = FontStyles.Normal;
1067
                                                            if (FontStyles.Italic == TextStyle)
1068
                                                            {
1069
                                                                fontStyle = FontStyles.Italic;
1070
                                                            }
1071 8c3a888c djkim
1072 ff665e73 taeseongkim
                                                            FontWeight fontWeight = FontWeights.Black;
1073 8c3a888c djkim
1074 ff665e73 taeseongkim
                                                            var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1075
                                                            if (FontWeights.Bold == TextWeight)
1076
                                                            {
1077
                                                                fontWeight = FontWeights.Bold;
1078
                                                            }
1079 8c3a888c djkim
1080 ff665e73 taeseongkim
                                                            TextDecorationCollection decoration = TextDecorations.Baseline;
1081
                                                            if (control.fontConfig.Count() == 5)
1082 e0f00e26 djkim
                                                            {
1083 ff665e73 taeseongkim
                                                                decoration = TextDecorations.Underline;
1084
                                                            }
1085
1086
                                                            if (control.isTrans)
1087
                                                            {
1088
                                                                //인구 수정 Arrow Text Style적용 되도록 변경
1089
                                                                Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1090
                                                                newStartPoint, tempMidPoint, newEndPoint, control.isFixed,
1091
                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1092
                                                            }
1093
                                                            else
1094
                                                            {
1095
                                                                if (control.isFixed)
1096 4f017ed3 taeseongkim
                                                                {
1097 ff665e73 taeseongkim
                                                                    var testP = new Point(0, 0);
1098
                                                                    if (control.isFixed)
1099
                                                                    {
1100
                                                                        if (tempPoint[1] == newEndPoint)
1101
                                                                        {
1102
                                                                            testP = new Point(newEndPoint.X, newEndPoint.Y - 10);
1103
                                                                        }
1104
                                                                        else if (tempPoint[3] == newEndPoint)
1105
                                                                        {
1106
                                                                            testP = new Point(newEndPoint.X, newEndPoint.Y + 10);
1107
                                                                        }
1108
                                                                        else if (tempPoint[0] == newEndPoint)
1109
                                                                        {
1110
                                                                            testP = new Point(newEndPoint.X - 10, newEndPoint.Y);
1111
                                                                        }
1112
                                                                        else if (tempPoint[2] == newEndPoint)
1113
                                                                        {
1114
                                                                            testP = new Point(newEndPoint.X + 10, newEndPoint.Y);
1115
                                                                        }
1116
                                                                    }
1117
                                                                    //인구 수정 Arrow Text Style적용 되도록 변경
1118
                                                                    Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1119
                                                                        tempStartPoint, testP, tempEndPoint, control.isFixed,
1120
                                                                        LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
1121
                                                                    FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1122 4f017ed3 taeseongkim
                                                                }
1123 ff665e73 taeseongkim
                                                                else
1124 4f017ed3 taeseongkim
                                                                {
1125 ff665e73 taeseongkim
                                                                    //인구 수정 Arrow Text Style적용 되도록 변경
1126
                                                                    Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1127
                                                                        newStartPoint, tempMidPoint, tempEndPoint, control.isFixed,
1128
                                                                        LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1129 e0f00e26 djkim
                                                                }
1130
                                                            }
1131 4f017ed3 taeseongkim
                                                        }
1132 ff665e73 taeseongkim
                                                        catch (Exception ex)
1133 4f017ed3 taeseongkim
                                                        {
1134 ff665e73 taeseongkim
                                                            throw ex;
1135 e0f00e26 djkim
                                                        }
1136 ff665e73 taeseongkim
1137 8c3a888c djkim
                                                    }
1138 ff665e73 taeseongkim
                                                    break;
1139
                                                #endregion
1140
                                                #region SignControl
1141
                                                case "SignControl":
1142
                                                    using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1143 c206d293 taeseongkim
                                                    {
1144
1145 ff665e73 taeseongkim
                                                        double Angle = control.Angle;
1146
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
1147
                                                        Point TopRightPoint = GetPdfPointSystem(control.TR);
1148
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
1149
                                                        Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1150
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1151
                                                        double Opacity = control.Opac;
1152
                                                        string UserNumber = control.UserNumber;
1153
                                                        Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1154
                                                    }
1155
                                                    break;
1156
                                                #endregion
1157
                                                #region MyRegion
1158
                                                case "DateControl":
1159
                                                    using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1160
                                                    {
1161
                                                        string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1162
                                                        string Text = control.Text;
1163
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
1164
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
1165
                                                        List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1166
                                                        SolidColorBrush FontColor = _SetColor;
1167
                                                        double Angle = control.Angle;
1168
                                                        double Opacity = control.Opac;
1169
                                                        Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1170 c206d293 taeseongkim
                                                    }
1171 ff665e73 taeseongkim
                                                    break;
1172
                                                #endregion
1173
                                                #region SymControlN (APPROVED)
1174
                                                case "SymControlN":
1175
                                                    using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1176
                                                    {
1177
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
1178
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
1179
                                                        List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1180
                                                        SolidColorBrush FontColor = _SetColor;
1181
                                                        double Angle = control.Angle;
1182
                                                        double Opacity = control.Opac;
1183
1184
                                                        var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1185
1186
                                                        if (stamp.Count() > 0)
1187
                                                        {
1188
                                                            var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1189
1190
                                                            Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1191
                                                        }
1192
1193
                                                        string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1194
1195
                                                    }
1196
                                                    break;
1197
                                                case "SymControl":
1198
                                                    using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1199
                                                    {
1200
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
1201
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
1202
                                                        List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1203
                                                        SolidColorBrush FontColor = _SetColor;
1204
                                                        double Angle = control.Angle;
1205
                                                        double Opacity = control.Opac;
1206
1207
                                                        string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1208
                                                        Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1209
                                                    }
1210
                                                    break;
1211
                                                #endregion
1212
                                                #region Image
1213
                                                case "ImgControl":
1214
                                                    using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1215
                                                    {
1216
                                                        double Angle = control.Angle;
1217
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
1218
                                                        Point TopRightPoint = GetPdfPointSystem(control.TR);
1219
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
1220
                                                        Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1221
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1222
                                                        double Opacity = control.Opac;
1223
                                                        string FilePath = control.ImagePath;
1224
                                                        //Uri uri = new Uri(s.ImagePath);
1225
1226
                                                        Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1227
                                                    }
1228
                                                    break;
1229
                                                #endregion
1230
                                                default:
1231
                                                    StatusChange($"{ControlT.Name} Not Support", 0);
1232
                                                    break;
1233
                                            }
1234 c206d293 taeseongkim
1235 e0f00e26 djkim
                                        }
1236 ff665e73 taeseongkim
                                        catch (Exception ex)
1237
                                        {
1238
                                            StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1239
                                        }
1240 b42dd24d taeseongkim
                                        finally
1241
                                        {
1242
                                            if(ControlT?.Name != null)
1243
                                            {
1244
                                                strLog.Append($"{ControlT.Name},");
1245
                                            }
1246
                                        }
1247 e0f00e26 djkim
                                    }
1248 b42dd24d taeseongkim
1249 ed705a3d taeseongkim
                                }
1250 abaa85b4 djkim
                            }
1251 b42dd24d taeseongkim
1252
                            if (StatusChanged != null)
1253
                            {
1254
                                StatusChanged(this, new StatusChangedEventArgs { CurrentPage = lastPageNo, Message = strLog.ToString() });
1255
                            }
1256 ed705a3d 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);
1257
                            //pdfStamper.AddFileAttachment("F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", pfs);
1258
1259 e0f00e26 djkim
                            pdfStamper.Outlines = root;
1260
                            pdfStamper.Close();
1261
                            pdfReader.Close();
1262 7ca218b3 KangIngu
                        }
1263 abaa85b4 djkim
                    }
1264 e0f00e26 djkim
                    #endregion
1265 7ca218b3 KangIngu
                }
1266 a1e2ba68 taeseongkim
1267 7ca218b3 KangIngu
                if (tempFileInfo.Exists)
1268
                {
1269 a1e2ba68 taeseongkim
#if !DEBUG
1270 7ca218b3 KangIngu
                    tempFileInfo.Delete();
1271 a1e2ba68 taeseongkim
#endif
1272 7ca218b3 KangIngu
                }
1273
1274
                if (File.Exists(pdfFilePath))
1275
                {
1276 e77fc685 taeseongkim
                    string destfilepath = null;
1277 7ca218b3 KangIngu
                    try
1278
                    {
1279 6e5f7eaf djkim
                        FinalPDFPath = new FileInfo(pdfFilePath);
1280
1281 907a99b3 taeseongkim
                        /// 정리 필요함. DB로 변경
1282
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1283
1284
                        if(!string.IsNullOrEmpty(pdfmovepath))
1285
                        {
1286
                            _FinalPDFStorgeLocal = pdfmovepath;
1287
                        }
1288
1289 e77fc685 taeseongkim
                        destfilepath = Path.Combine(_FinalPDFStorgeLocal, FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1290
1291 6e5f7eaf djkim
                        if (File.Exists(destfilepath))
1292
                            File.Delete(destfilepath);
1293 e77fc685 taeseongkim
1294 6e5f7eaf djkim
                        File.Move(FinalPDFPath.FullName, destfilepath);
1295
                        FinalPDFPath = new FileInfo(destfilepath);
1296 7ca218b3 KangIngu
                        File.Delete(pdfFilePath);
1297
                    }
1298
                    catch (Exception ex)
1299
                    {
1300 e77fc685 taeseongkim
                        SetNotice(finaldata.ID, $"File move error - Source File : {FinalPDFPath.FullName} dest File : {destfilepath}" + ex.ToString());
1301 7ca218b3 KangIngu
                    }
1302
1303
                    return true;
1304
                }
1305
            }
1306 7aa36857 humkyung
            catch (Exception ex)
1307 7ca218b3 KangIngu
            {
1308 782ad7b1 taeseongkim
                SetNotice(finaldata.ID, "SetStempinPDF error: " + ex.ToString());
1309 7ca218b3 KangIngu
            }
1310
            return false;
1311
        }
1312 4f017ed3 taeseongkim
1313
        /// <summary>
1314
        /// kcom의 화살표방향과 틀려 추가함
1315
        /// </summary>
1316
        /// <param name="PageAngle"></param>
1317
        /// <param name="endP"></param>
1318
        /// <param name="ps">box Points</param>
1319
        /// <param name="IsFixed"></param>
1320
        /// <returns></returns>
1321
        private Point GetArrowTextControlTestPoint(double PageAngle,Point endP,List<Point> ps,bool IsFixed)
1322
        {
1323
            Point testP = endP;
1324
1325
            try
1326
            {
1327
                switch (Math.Abs(PageAngle).ToString())
1328
                {
1329
                    case "90":
1330
                        testP = new Point(endP.X + 50, endP.Y);
1331
                        break;
1332
                    case "270":
1333
                        testP = new Point(endP.X - 50, endP.Y);
1334
                        break;
1335
                }
1336
1337
                //20180910 LJY 각도에 따라.
1338
                switch (Math.Abs(PageAngle).ToString())
1339
                {
1340
                    case "90":
1341
                        if (IsFixed)
1342
                        {
1343
                            if (ps[0] == endP) //상단
1344
                            {
1345
                                testP = new Point(endP.X, endP.Y + 50);
1346
                                //System.Diagnostics.Debug.WriteLine("상단"+ testP);
1347
                            }
1348
                            else if (ps[1] == endP) //하단
1349
                            {
1350
                                testP = new Point(endP.X, endP.Y - 50);
1351
                                //System.Diagnostics.Debug.WriteLine("하단"+ testP);
1352
                            }
1353
                            else if (ps[2] == endP) //좌단
1354
                            {
1355
                                testP = new Point(endP.X - 50, endP.Y);
1356
                                //System.Diagnostics.Debug.WriteLine("좌단"+ testP);
1357
                            }
1358
                            else if (ps[3] == endP) //우단
1359
                            {
1360
                                testP = new Point(endP.X + 50, endP.Y);
1361
                                //System.Diagnostics.Debug.WriteLine("우단"+ testP);
1362
                            }
1363
                        }
1364
                        break;
1365
                    case "270":
1366
                        if (IsFixed)
1367
                        {
1368
                            if (ps[0] == endP) //상단
1369
                            {
1370
                                testP = new Point(endP.X, endP.Y - 50);
1371
                                //System.Diagnostics.Debug.WriteLine("상단" + testP);
1372
                            }
1373
                            else if (ps[1] == endP) //하단
1374
                            {
1375
                                testP = new Point(endP.X, endP.Y + 50);
1376
                                //System.Diagnostics.Debug.WriteLine("하단" + testP);
1377
                            }
1378
                            else if (ps[2] == endP) //좌단
1379
                            {
1380
                                testP = new Point(endP.X + 50, endP.Y);
1381
                                //System.Diagnostics.Debug.WriteLine("좌단" + testP);
1382
                            }
1383
                            else if (ps[3] == endP) //우단
1384
                            {
1385
                                testP = new Point(endP.X - 50, endP.Y);
1386
                                //System.Diagnostics.Debug.WriteLine("우단" + testP);
1387
                            }
1388
                        }
1389
                        break;
1390
                    default:
1391
                        if (IsFixed)
1392
                        {
1393
1394
                            if (ps[0] == endP) //상단
1395
                            {
1396
                                testP = new Point(endP.X, endP.Y - 50);
1397
                                //System.Diagnostics.Debug.WriteLine("상단");
1398
                            }
1399
                            else if (ps[1] == endP) //하단
1400
                            {
1401
                                testP = new Point(endP.X, endP.Y + 50);
1402
                                //System.Diagnostics.Debug.WriteLine("하단");
1403
                            }
1404
                            else if (ps[2] == endP) //좌단
1405
                            {
1406
                                testP = new Point(endP.X - 50, endP.Y);
1407
                                //System.Diagnostics.Debug.WriteLine("좌단");
1408
                            }
1409
                            else if (ps[3] == endP) //우단
1410
                            {
1411
                                testP = new Point(endP.X + 50, endP.Y);
1412
                                //System.Diagnostics.Debug.WriteLine("우단");
1413
                            }
1414
                        }
1415
                        break;
1416
                }
1417
1418
            }
1419
            catch (Exception)
1420
            {
1421
            }
1422
1423
            return testP;
1424
        }
1425
1426
        private Point Test(Rect rect,Point point)
1427
        {
1428
            Point result = new Point();
1429
1430
            Point newPoint = new Point();
1431
1432
            double oldNear = 0;
1433
            double newNear = 0;
1434
1435
            oldNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.TopRight, out result);
1436
1437
            newNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.BottomLeft, out newPoint);
1438
1439
            if (newNear < oldNear)
1440
            {
1441
                oldNear = newNear;
1442
                result = newPoint;
1443
            }
1444
1445
            newNear = MathSet.GetShortestDistance(point, rect.TopRight, rect.BottomRight, out newPoint);
1446
1447
            if (newNear < oldNear)
1448
            {
1449
                oldNear = newNear;
1450
                result = newPoint;
1451
            }
1452
1453
1454
            newNear = MathSet.GetShortestDistance(point, rect.BottomLeft, rect.BottomRight, out newPoint);
1455
1456
            if (newNear < oldNear)
1457
            {
1458
                oldNear = newNear;
1459
                result = newPoint;
1460
            }
1461
1462
            return result;
1463
        }
1464
1465
        private void DrawMultiArrowLine(S_ArrowControl_Multi control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, SolidColorBrush setColor)
1466
        {
1467
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1468
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1469
            Point MidPoint = GetPdfPointSystem(control.MidPoint);
1470
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1471
            DoubleCollection DashSize = control.DashSize;
1472
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1473
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1474
1475
            double Opacity = control.Opac;
1476
1477
            if (EndPoint == MidPoint)
1478
            {
1479
                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1480
            }
1481
            else
1482
            {
1483
                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, setColor, Opacity);
1484
            }
1485
1486
            Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, setColor, Opacity);
1487
1488
        }
1489
1490
        private void DrawLine(S_LineControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, SolidColorBrush setColor)
1491
        {
1492
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1493
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1494
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1495
            DoubleCollection DashSize = control.DashSize;
1496
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1497
1498
            var Opacity = control.Opac;
1499
            string UserID = control.UserID;
1500
            double Interval = control.Interval;
1501
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1502
            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, setColor, Opacity);
1503
            switch (control.LineStyleSet)
1504
            {
1505
                case LineStyleSet.ArrowLine:
1506
                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1507
                    break;
1508
                case LineStyleSet.CancelLine:
1509
                    {
1510
                        var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X)));
1511
                        var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y)));
1512
1513
                        if (x > y)
1514
                        {
1515
                            StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0));
1516
                            EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0));
1517
                            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, setColor, Opacity);
1518
                        }
1519
                    }
1520
                    break;
1521
                case LineStyleSet.TwinLine:
1522
                    {
1523
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1524
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1525
                    }
1526
                    break;
1527
                case LineStyleSet.DimLine:
1528
                    {
1529
                        Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1530
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1531
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1532
                    }
1533
                    break;
1534
                default:
1535
                    break;
1536
            }
1537
1538
        }
1539
1540
        private void DrawTextBox(S_TextControl control,PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2,SolidColorBrush setColor)
1541
        {
1542
            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1543
            string Text = control.Text;
1544
1545
            bool isUnderline = false;
1546
            control.BoxW -= scaleWidth;
1547
            control.BoxH -= scaleHeight;
1548
            System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
1549
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1550
            Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
1551
1552
            List<Point> pointSet = new List<Point>();
1553
            pointSet.Add(StartPoint);
1554
            pointSet.Add(EndPoint);
1555
1556
            PaintSet paint = PaintSet.None;
1557
            switch (control.paintMethod)
1558
            {
1559
                case 1:
1560
                    {
1561
                        paint = PaintSet.Fill;
1562
                    }
1563
                    break;
1564
                case 2:
1565
                    {
1566
                        paint = PaintSet.Hatch;
1567
                    }
1568
                    break;
1569
                default:
1570
                    break;
1571
            }
1572
            if (control.isHighLight) paint |= PaintSet.Highlight;
1573
1574
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1575
            double TextSize = Convert.ToDouble(data2[1]);
1576
            SolidColorBrush FontColor = setColor;
1577
            double Angle = control.Angle;
1578
            double Opacity = control.Opac;
1579
            FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
1580
            var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1581
1582
            FontStyle fontStyle = FontStyles.Normal;
1583
            if (FontStyles.Italic == TextStyle)
1584
            {
1585
                fontStyle = FontStyles.Italic;
1586
            }
1587
1588
            FontWeight fontWeight = FontWeights.Black;
1589
1590
            var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1591
            //강인구 수정(2018.04.17)
1592
            if (FontWeights.Bold == TextWeight)
1593
            //if (FontWeights.ExtraBold == TextWeight)
1594
            {
1595
                fontWeight = FontWeights.Bold;
1596
            }
1597
1598
            TextDecorationCollection decoration = TextDecorations.Baseline;
1599
            if (control.fontConfig.Count() == 4)
1600
            {
1601
                decoration = TextDecorations.Underline;
1602
            }
1603
1604
            Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, setColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1605
        }
1606 c206d293 taeseongkim
    
1607 7ca218b3 KangIngu
1608 40cf5bf7 humkyung
        ~MarkupToPDF()
1609
        {
1610
            this.Dispose(false);
1611
        }
1612
1613
        private bool disposed;
1614
1615 7ca218b3 KangIngu
        public void Dispose()
1616
        {
1617 40cf5bf7 humkyung
            this.Dispose(true);
1618
            GC.SuppressFinalize(this);
1619
        }
1620
1621
        protected virtual void Dispose(bool disposing)
1622
        {
1623
            if (this.disposed) return;
1624
            if (disposing)
1625
            {
1626
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1627
            }
1628
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1629
            this.disposed = true;
1630 8c3a888c djkim
        }
1631 7f01e35f ljiyeon
1632 a1e2ba68 taeseongkim
#endregion
1633 7ca218b3 KangIngu
    }
1634
}
클립보드 이미지 추가 (최대 크기: 500 MB)