프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 8de55603

이력 | 보기 | 이력해설 | 다운로드 (85.4 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
        public void MakeFinalPDF(object _FinalPDF)
259
        {
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
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found.");
280
                            return;
281
                        }
282
                        else
283
                        { 
284
                            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
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found.");
290
                            return;
291
                        }
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
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found.");
301
                            return;
302
                        }
303
                        else
304
                        {
305
                            _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE;
306
                        }
307 7ca218b3 KangIngu
                    }
308
                    else
309
                    {
310 077fb153 taeseongkim
                        SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found.");
311 7ca218b3 KangIngu
                        return;
312
                    }
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
                SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString());
328
                return;
329
            }
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 8c3a888c djkim
                        DocInfoItem = _DOCINFO.FirstOrDefault();
342
                        DocPageItem = DocInfoItem.DOCPAGE.ToList();
343 7ca218b3 KangIngu
344
                        PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\"
345 a371522c humkyung
                                         + (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5))
346 7ca218b3 KangIngu
                                         + @"\" + FinalPDF.DOCUMENT_ID + @"\";
347
348 8c3a888c djkim
                        MarkupInfoItem = DocInfoItem.MARKUP_INFO.Where(data => data.CONSOLIDATE == 1 && data.AVOID_CONSOLIDATE == 0 && data.PART_CONSOLIDATE == 0).FirstOrDefault();
349 7ca218b3 KangIngu
350
                        if (MarkupInfoItem == null)
351
                        {
352
                            throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다");
353
                        }
354
                        else
355
                        {
356 8c3a888c djkim
                            if (MarkupInfoItem.MARKUP_INFO_VERSION.Count > 0)
357
                            {
358
                                MarkupDataSet = MarkupInfoItem.MARKUP_INFO_VERSION.OrderBy(d => d.CREATE_DATE).LastOrDefault().MARKUP_DATA.ToList().OrderBy(d => d.PAGENUMBER).ToList();
359
                            }
360
                            else
361 7ca218b3 KangIngu
                            {
362
                                throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다");
363 8c3a888c djkim
                            }
364 6c9fec59 djkim
                        }
365 7ca218b3 KangIngu
366 645f6f94 djkim
                        documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault();
367 e0f00e26 djkim
                        if (documentItem == null)
368 6c9fec59 djkim
                        {
369 e0f00e26 djkim
                            throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요");
370
                        }
371 8c3a888c djkim
372 e0f00e26 djkim
                        var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 
373 8c3a888c djkim
374 e0f00e26 djkim
                        #region 파일 체크
375
                        if (_files.Count() == 1)
376
                        {
377 ff01c725 humkyung
                            /// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정
378
                            //if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()))
379
                            //{
380 e0f00e26 djkim
                                OriginFileName = _files.First().Name;
381
                                PdfFilePath = _files.First().CopyTo(TestFile, true);
382 c206d293 taeseongkim
                                StatusChange($"Copy File  file Count = 1 : {PdfFilePath}", 0);
383 ff01c725 humkyung
                            //}
384
                            //else
385
                            //{
386
                            //    throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower());
387
                            //}
388 e0f00e26 djkim
                        }
389
                        else if (_files.Count() > 1)
390
                        {
391
                            var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault();
392 6c9fec59 djkim
393 e0f00e26 djkim
                            if (originalFile == null)
394 8c3a888c djkim
                            {
395 e0f00e26 djkim
                                throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다");
396 8c3a888c djkim
                            }
397 e0f00e26 djkim
                            else
398 8c3a888c djkim
                            {
399 e0f00e26 djkim
                                OriginFileName = originalFile.Name;
400
                                PdfFilePath = originalFile.CopyTo(TestFile, true);
401 c206d293 taeseongkim
                                StatusChange($"Copy File file Count  > 1 : {PdfFilePath}", 0);
402 8c3a888c djkim
                            }
403 6c9fec59 djkim
                        }
404 e0f00e26 djkim
                        else
405
                        {
406 cbea3c14 humkyung
                            throw new FileNotFoundException("PDF를 찾지 못하였습니다");
407 e0f00e26 djkim
                        }
408
                        #endregion
409
410
                        #region 예외처리
411
                        if (PdfFilePath == null)
412
                        {
413
                            throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다");
414
                        }
415
                        if (!PdfFilePath.Exists)
416
                        {
417
                            throw new Exception("PDF원본이 존재하지 않습니다");
418
                        }
419
                        #endregion
420
                        
421 7ca218b3 KangIngu
                    }
422
                    else
423
                    {
424
                        throw new Exception("일치하는 DocInfo가 없습니다");
425
                    }
426
                }
427
            }
428
            catch (Exception ex)
429
            {
430
                if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다")
431
                {
432
                    SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다");
433
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
434
                    process.StartInfo.FileName = "cmd";
435
                    process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\"";
436
                    process.Start();
437
                }
438
                else
439
                {
440
                    SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message);
441
                }
442
            }
443
            #endregion
444
445
            try
446
            {
447
448 8c3a888c djkim
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
449
                {
450
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
451
452
                    if (finalList.Count() > 0)
453 7ca218b3 KangIngu
                    {
454 c206d293 taeseongkim
                        //TestFile = SetFlattingPDF(TestFile);
455
                        //StatusChange($"SetFlattingPDF : {TestFile}", 0);
456
457 8c3a888c djkim
                        SetStampInPDF(FinalItem, TestFile, MarkupInfoItem);
458 c206d293 taeseongkim
459
                        StatusChange($"SetStampInPDF : {TestFile}", 0);
460 7ca218b3 KangIngu
                    }
461 8c3a888c djkim
                }
462
                if (EndFinal != null)
463
                {
464
                    EndFinal(this, new EndFinalEventArgs
465
                    {
466 e77fc685 taeseongkim
                        FinalPDFRemotePath = _FinalPDFStorgeRemote + @"\" + FinalPDFPath.Name,
467 8c3a888c djkim
                        OriginPDFName = OriginFileName,
468
                        FinalPDFPath = FinalPDFPath.FullName,
469
                        Error = "",
470
                        Message = "",
471
                        FinalPDF = FinalPDF,
472
                    });
473
                }
474 7ca218b3 KangIngu
            }
475
            catch (Exception ex)
476
            {
477 782ad7b1 taeseongkim
                SetNotice(FinalPDF.ID, "MarkFinalPDF Error : " + ex.Message);
478 7ca218b3 KangIngu
            }
479
        }
480
        #endregion
481
482
        #region PDF
483 4804a4fb humkyung
        public static float scaleWidth = 0;
484
        public static float scaleHeight = 0;
485 8c3a888c djkim
486 7ca218b3 KangIngu
        private string SetFlattingPDF(string tempFileInfo)
487
        {
488
            if (File.Exists(tempFileInfo))
489
            {
490
                FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName());
491
492
                PdfReader pdfReader = new PdfReader(tempFileInfo);
493 c206d293 taeseongkim
494 dc0bfdad djkim
                for (int i = 1; i <= pdfReader.NumberOfPages; i++)
495 7ca218b3 KangIngu
                {
496
                    var mediaBox = pdfReader.GetPageSize(i);
497
                    var cropbox = pdfReader.GetCropBox(i);
498
499 8c3a888c djkim
                    //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString()))
500
                    //{
501
                    //    _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE)
502
                    //}
503 7ca218b3 KangIngu
                    var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault();
504
505 8c3a888c djkim
                    //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width;
506
                    //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height;
507
                    //scaleWidth = 2.0832634F;
508
                    //scaleHeight = 3.0F;
509
510 7ca218b3 KangIngu
                    PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i));
511 8c3a888c djkim
                    //강인구 수정
512
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height))
513
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height))
514
                    //{
515
                    //    var pageDict = pdfReader.GetPageN(i);
516
                    //    pageDict.Put(PdfName.MEDIABOX, rect);
517
                    //}
518 7ca218b3 KangIngu
                }
519
520
                var memStream = new MemoryStream();
521
                var stamper = new PdfStamper(pdfReader, memStream)
522
                {
523 dc0bfdad djkim
                    FormFlattening = true,                     
524
                    //FreeTextFlattening = true,
525
                    //AnnotationFlattening = true,                     
526 7ca218b3 KangIngu
                };
527 dc0bfdad djkim
                
528 7ca218b3 KangIngu
                stamper.Close();
529
                pdfReader.Close();
530
                var array = memStream.ToArray();
531
                File.Delete(tempFileInfo);
532
                File.WriteAllBytes(TestFile.FullName, array);
533
534
                return TestFile.FullName;
535
            }
536
            else
537
            {
538
                return tempFileInfo;
539
            }
540
        }
541
542
        public void flattenPdfFile(string src, ref string dest)
543
        {
544
            PdfReader reader = new PdfReader(src);
545
            var memStream = new MemoryStream();
546
            var stamper = new PdfStamper(reader, memStream)
547
            {
548
                FormFlattening = true,
549
                FreeTextFlattening = true,
550
                AnnotationFlattening = true,
551
            };
552
553
            stamper.Close();
554
            var array = memStream.ToArray();
555
            File.WriteAllBytes(dest, array);
556
        }
557 8c3a888c djkim
558 ab590000 taeseongkim
        public void StatusChange(string message,int CurrentPage)
559
        {
560
            if(StatusChanged != null)
561
            {
562 c206d293 taeseongkim
                var sb = new StringBuilder();
563
                sb.AppendLine(message);
564
565
                StatusChanged(null, new StatusChangedEventArgs { CurrentPage = CurrentPage, Message = sb.ToString() });
566 ab590000 taeseongkim
            }
567
        }
568
569 8c3a888c djkim
        public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo)
570 7ca218b3 KangIngu
        {
571 e0f00e26 djkim
            try
572 8c3a888c djkim
            {
573 faebcce2 taeseongkim
        
574 e0f00e26 djkim
                FileInfo tempFileInfo = new FileInfo(testFile);
575 abaa85b4 djkim
576 e0f00e26 djkim
                if (!Directory.Exists(_FinalPDFStorgeLocal))
577 8c3a888c djkim
                {
578 e0f00e26 djkim
                    Directory.CreateDirectory(_FinalPDFStorgeLocal);
579
                }
580 cbea3c14 humkyung
                string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name);
581 faebcce2 taeseongkim
          
582
583 e0f00e26 djkim
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
584
                {
585
                    FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault();
586 7ca218b3 KangIngu
587 e0f00e26 djkim
                    #region 코멘트 적용 + 커버시트
588
                    using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) //
589 8c3a888c djkim
                    {
590 ab590000 taeseongkim
                        StatusChange("comment Cover",0);
591 faebcce2 taeseongkim
                        
592 e0f00e26 djkim
                        PdfReader pdfReader = new PdfReader(pdfStream);
593
                        //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
594
                        Dictionary<string, object> bookmark;
595
                        List<Dictionary<string, object>> outlines;
596 faebcce2 taeseongkim
597 e0f00e26 djkim
                        outlines = new List<Dictionary<string, object>>();
598
                        List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
599
600
                        var dic = new Dictionary<string, object>();
601 faebcce2 taeseongkim
602 e0f00e26 djkim
                        foreach (var data in MarkupDataSet)
603
                        {
604 ab590000 taeseongkim
                            StatusChange("MarkupDataSet", 0);
605 abaa85b4 djkim
606 e0f00e26 djkim
                            string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
607
608 faebcce2 taeseongkim
                            string username = "";
609
                            string userdept = "";
610
611
                            using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
612
                            {
613
                                var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
614
615
                                if(memberlist.Count() > 0)
616
                                {
617
                                    username = memberlist.First().NAME;
618
                                    userdept = memberlist.First().DEPARTMENT;
619
                                }
620
                            }
621
622 e0f00e26 djkim
                            bookmark = new Dictionary<string, object>();
623
                            bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
624
                            bookmark.Add("Page", data.PAGENUMBER + " Fit");
625
                            bookmark.Add("Action", "GoTo");
626
                            bookmark.Add("Kids", outlines);
627
                            root.Add(bookmark);
628
                        }
629 abaa85b4 djkim
630
631 e0f00e26 djkim
                        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
632 8c3a888c djkim
                        {
633 c206d293 taeseongkim
                            AcroFields pdfFormFields = pdfStamper.AcroFields;
634 782ad7b1 taeseongkim
635
                            try
636
                            {
637
                                if (pdfFormFields.GenerateAppearances != true)
638
                                {
639
                                    pdfFormFields.GenerateAppearances = true;
640
                                }
641
                            }
642
                            catch (Exception ex)
643
                            {
644
                                SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
645
                            }
646 c206d293 taeseongkim
647 e0f00e26 djkim
                            var _SetColor = new SolidColorBrush(Colors.Red);
648 7ca218b3 KangIngu
649 e0f00e26 djkim
                            string[] delimiterChars = { "|DZ|" };
650
                            string[] delimiterChars2 = { "|" };
651 7ca218b3 KangIngu
652 e0f00e26 djkim
                            //pdfStamper.FormFlattening = true; //이미 선처리 작업함
653
                            pdfStamper.SetFullCompression();
654
                            _SetColor = new SolidColorBrush(Colors.Red);
655 7ca218b3 KangIngu
656 e0f00e26 djkim
                            foreach (var markupItem in MarkupDataSet)
657 8c3a888c djkim
                            {
658 2e1d6c99 djkim
                                pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER);
659 e0f00e26 djkim
                                var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER).FirstOrDefault();
660 7ca218b3 KangIngu
661 e0f00e26 djkim
                                mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER);
662 2e1d6c99 djkim
                                var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER);                                
663 7ca218b3 KangIngu
664 7aa36857 humkyung
                                /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
665
                                if (cropBox != null && 
666
                                    (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
667 2e1d6c99 djkim
                                {
668 7aa36857 humkyung
                                    PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
669
670
                                    PdfArray oNewMediaBox = new PdfArray();
671
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Left));
672
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Top));
673
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Right));
674
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
675
                                    dict.Put(PdfName.MEDIABOX, oNewMediaBox);
676
677 2e1d6c99 djkim
                                    pdfSize = cropBox; 
678
                                }
679 e0f00e26 djkim
                                scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
680
                                scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
681 7ca218b3 KangIngu
682 e0f00e26 djkim
                                pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
683
                                _entity.SaveChanges();
684 8c3a888c djkim
685 e0f00e26 djkim
                                string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
686
687
                                PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
688
689
                                foreach (var data in markedData)
690 7ca218b3 KangIngu
                                {
691 e0f00e26 djkim
                                    var item = JsonSerializerHelper.UnCompressString(data);
692
                                    var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
693 68e3cd94 taeseongkim
                              
694 e0f00e26 djkim
                                    try
695 8c3a888c djkim
                                    {
696 e0f00e26 djkim
                                        switch (ControlT.Name)
697
                                        {
698
                                            #region LINE
699
                                            case "LineControl":
700 7ca218b3 KangIngu
                                                {
701 e0f00e26 djkim
                                                    using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
702 8c3a888c djkim
                                                    {
703 4f017ed3 taeseongkim
                                                        DrawLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
704 e0f00e26 djkim
                                                    }
705 8c3a888c djkim
                                                }
706 e0f00e26 djkim
                                                break;
707
                                            #endregion
708
                                            #region ArrowControlMulti
709
                                            case "ArrowControl_Multi":
710 8c3a888c djkim
                                                {
711 e0f00e26 djkim
                                                    using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
712
                                                    {
713 4f017ed3 taeseongkim
                                                       DrawMultiArrowLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
714 e0f00e26 djkim
                                                    }
715 8c3a888c djkim
                                                }
716 e0f00e26 djkim
                                                break;
717
                                            #endregion
718
                                            #region PolyControl
719
                                            case "PolygonControl":
720
                                                using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
721 7ca218b3 KangIngu
                                                {
722 8c3a888c djkim
                                                    string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
723
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
724
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
725
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
726
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
727 e0f00e26 djkim
                                                    double Opacity = control.Opac;
728
                                                    DoubleCollection DashSize = control.DashSize;
729 8c3a888c djkim
730 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
731 8c3a888c djkim
                                                }
732 e0f00e26 djkim
                                                break;
733
                                            #endregion
734 c206d293 taeseongkim
                                            #region ArcControl or ArrowArcControl
735 e0f00e26 djkim
                                            case "ArcControl":
736 c206d293 taeseongkim
                                            case "ArrowArcControl":
737 8c3a888c djkim
                                                {
738 e0f00e26 djkim
                                                    using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
739 abaa85b4 djkim
                                                    {
740 e0f00e26 djkim
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
741
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
742
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
743
                                                        Point MidPoint = GetPdfPointSystem(control.MidPoint);
744
                                                        DoubleCollection DashSize = control.DashSize;
745
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
746
747
                                                        var Opacity = control.Opac;
748
                                                        string UserID = control.UserID;
749
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
750
                                                        bool IsTransOn = control.IsTransOn;
751
752
                                                        if (control.IsTransOn)
753 8c3a888c djkim
                                                        {
754 16fe076c humkyung
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
755
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
756 8c3a888c djkim
                                                        }
757
                                                        else
758
                                                        {
759 16fe076c humkyung
                                                            Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity);
760 8c3a888c djkim
                                                        }
761 e0f00e26 djkim
762 c206d293 taeseongkim
                                                        if (ControlT.Name == "ArrowArcControl")
763
                                                        {
764
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
765
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
766
                                                        }
767 abaa85b4 djkim
                                                    }
768 8c3a888c djkim
                                                }
769 e0f00e26 djkim
                                                break;
770
                                            #endregion
771
                                            #region RectangleControl
772
                                            case "RectangleControl":
773
                                                using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
774 7ca218b3 KangIngu
                                                {
775 e0f00e26 djkim
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
776
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
777
                                                    var PaintStyle = control.PaintState;
778
                                                    double Angle = control.Angle;
779
                                                    DoubleCollection DashSize = control.DashSize;
780
                                                    double Opacity = control.Opac;
781
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
782
783 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
784 7ca218b3 KangIngu
                                                }
785 e0f00e26 djkim
                                                break;
786
                                            #endregion
787
                                            #region TriControl
788
                                            case "TriControl":
789
                                                using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
790 7ca218b3 KangIngu
                                                {
791 e0f00e26 djkim
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
792
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
793
                                                    var PaintStyle = control.Paint;
794
                                                    double Angle = control.Angle;
795
                                                    //StrokeColor = _SetColor, //색상은 레드
796
                                                    DoubleCollection DashSize = control.DashSize;
797
                                                    double Opacity = control.Opac;
798
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
799 7ca218b3 KangIngu
800 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
801 7ca218b3 KangIngu
                                                }
802 e0f00e26 djkim
                                                break;
803
                                            #endregion
804
                                            #region CircleControl
805
                                            case "CircleControl":
806
                                                using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
807 7ca218b3 KangIngu
                                                {
808 e0f00e26 djkim
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
809
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
810
                                                    var StartPoint = GetPdfPointSystem(control.StartPoint);
811
                                                    var EndPoint = GetPdfPointSystem(control.EndPoint);
812
                                                    var PaintStyle = control.PaintState;
813
                                                    double Angle = control.Angle;
814
                                                    DoubleCollection DashSize = control.DashSize;
815
                                                    double Opacity = control.Opac;
816
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
817 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
818 e0f00e26 djkim
819 7ca218b3 KangIngu
                                                }
820 e0f00e26 djkim
                                                break;
821
                                            #endregion
822
                                            #region RectCloudControl
823
                                            case "RectCloudControl":
824
                                                using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
825
                                                {
826
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
827
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
828
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
829
                                                    double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
830
831
                                                    double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
832
833
                                                    var PaintStyle = control.PaintState;
834
                                                    double Opacity = control.Opac;
835
                                                    DoubleCollection DashSize = control.DashSize;
836 7ca218b3 KangIngu
837 e0f00e26 djkim
                                                    //드로잉 방식이 표현되지 않음
838
                                                    var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
839
840
                                                    double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
841
                                                    bool reverse = (area < 0);
842
                                                    if (PaintStyle == PaintSet.None)
843
                                                    {
844
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
845
                                                    }
846
                                                    else
847
                                                    {
848
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
849
                                                    }
850
                                                }
851
                                                break;
852
                                            #endregion
853
                                            #region CloudControl
854
                                            case "CloudControl":
855
                                                using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
856 7ca218b3 KangIngu
                                                {
857 e0f00e26 djkim
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
858
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
859
                                                    double Toler = control.Toler;
860
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
861
                                                    double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
862
                                                    var PaintStyle = control.PaintState;
863
                                                    double Opacity = control.Opac;
864
                                                    bool isTransOn = control.IsTrans;
865
                                                    bool isChain = control.IsChain;
866
867
                                                    DoubleCollection DashSize = control.DashSize;
868
869
                                                    if (isChain)
870
                                                    {
871 16fe076c humkyung
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
872 e0f00e26 djkim
                                                    }
873
                                                    else
874
                                                    {
875
                                                        if (isTransOn)
876 8c3a888c djkim
                                                        {
877 e0f00e26 djkim
                                                            double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
878
                                                            bool reverse = (area < 0);
879
880
                                                            if (PaintStyle == PaintSet.None)
881
                                                            {
882
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
883
                                                            }
884
                                                            else
885
                                                            {
886
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
887
                                                            }
888 8c3a888c djkim
                                                        }
889 e0f00e26 djkim
                                                        else
890 8c3a888c djkim
                                                        {
891 16fe076c humkyung
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
892 8c3a888c djkim
                                                        }
893 e0f00e26 djkim
                                                    }
894 7ca218b3 KangIngu
                                                }
895 e0f00e26 djkim
                                                break;
896
                                            #endregion
897
                                            #region TEXT
898
                                            case "TextControl":
899
                                                using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
900 7ca218b3 KangIngu
                                                {
901 4f017ed3 taeseongkim
                                                    DrawTextBox(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
902
                                                 }
903
                                                break;
904
                                            #endregion
905
                                            #region ArrowTextControl
906
                                            case "ArrowTextControl":
907
                                                using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
908
                                                {
909
                                                    //using (S_TextControl textcontrol = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
910
                                                    //{
911
                                                    //    textcontrol.Angle = control.Angle;
912
                                                    //    textcontrol.BoxH = control.BoxHeight;
913
                                                    //    textcontrol.BoxW = control.BoxWidth;
914
                                                    //    textcontrol.EndPoint = control.EndPoint;
915
                                                    //    textcontrol.FontColor = "#FFFF0000";
916
                                                    //    textcontrol.Name = "TextControl";
917
                                                    //    textcontrol.Opac = control.Opac;
918
                                                    //    textcontrol.PointSet = new List<Point>();
919
                                                    //    textcontrol.SizeSet = string.Join(delimiterChars2.First(), control.SizeSet.First(), control.fontConfig[3]);
920
                                                    //    textcontrol.StartPoint = control.StartPoint;
921
                                                    //    textcontrol.Text = control.ArrowText;
922
                                                    //    textcontrol.TransformPoint = control.TransformPoint;
923
                                                    //    textcontrol.UserID = null;
924
                                                    //    textcontrol.fontConfig = control.fontConfig;
925
                                                    //    textcontrol.isHighLight = control.isHighLight;
926
                                                    //    textcontrol.paintMethod = 1;
927
928
                                                    //    DrawTextBox(textcontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
929
                                                    //}
930
931
                                                    //using (S_ArrowControl_Multi linecontrol = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
932
                                                    //{
933
                                                    //    linecontrol.Angle = control.Angle;
934
                                                    //    linecontrol.DashSize = new DoubleCollection(new[] {(double)999999 });
935
                                                    //    linecontrol.EndPoint = control.EndPoint;
936
                                                    //    linecontrol.MidPoint = control.MidPoint;
937
                                                    //    linecontrol.Name = "ArrowControl_Multi";
938
                                                    //    linecontrol.Opac = control.Opac;
939
                                                    //    linecontrol.PointSet = control.PointSet;
940
                                                    //    linecontrol.SizeSet = control.SizeSet;
941
                                                    //    linecontrol.StartPoint = control.StartPoint;
942
                                                    //    linecontrol.StrokeColor = control.StrokeColor;
943
                                                    //    linecontrol.TransformPoint = control.TransformPoint;
944
945
                                                    //    DrawMultiArrowLine(linecontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
946
                                                    //}
947
                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
948
                                                Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
949
                                                Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
950
                                                Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
951
                                                bool isUnderLine = false;
952
                                                string Text = "";
953
                                                double fontsize = 30;
954
955
                                                System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
956
                                                Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight));
957
                                                List<Point> tempPoint = new List<Point>();
958
959
                                                double Angle = control.Angle;
960
961
                                                if (Math.Abs(Angle).ToString() == "90")
962
                                                {
963
                                                    Angle = 270;
964
                                                }
965
                                                else if (Math.Abs(Angle).ToString() == "270")
966
                                                {
967
                                                    Angle = 90;
968
                                                }
969 8c3a888c djkim
970 4f017ed3 taeseongkim
                                                var tempRectMidPoint = MathSet.getRectMiddlePoint(rect);
971
                                                tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y));
972
                                                tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top));
973
                                                tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y));
974
                                                tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom));
975
976
                                                var newStartPoint = tempStartPoint;
977
                                                var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint);
978
                                                var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint);
979
980
                                                    //Point testPoint = tempEndPoint;
981
                                                    //if (Angle != 0)
982
                                                    //{
983
                                                    //    testPoint = GetArrowTextControlTestPoint(0, newMidPoint, tempPoint, control.isFixed);
984
                                                    //   //testPoint = Test(rect, newMidPoint);
985
                                                    //}
986
987
                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
988
                                                SolidColorBrush FontColor = _SetColor;
989
                                                bool isHighlight = control.isHighLight;
990
                                                double Opacity = control.Opac;
991
                                                PaintSet Paint = PaintSet.None;
992
993
                                                switch (control.ArrowStyle)
994
                                                {
995
                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
996
                                                        {
997
                                                            Paint = PaintSet.None;
998
                                                        }
999
                                                        break;
1000
                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
1001
                                                        {
1002
                                                            Paint = PaintSet.Hatch;
1003
                                                        }
1004
                                                        break;
1005
                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
1006
                                                        {
1007
                                                            Paint = PaintSet.Fill;
1008
                                                        }
1009
                                                        break;
1010
                                                    default:
1011
                                                        break;
1012
                                                }
1013
                                                if (control.isHighLight) Paint |= PaintSet.Highlight;
1014 e0f00e26 djkim
1015 4f017ed3 taeseongkim
                                                if (Paint == PaintSet.Hatch)
1016
                                                {
1017
                                                    Text = control.ArrowText;
1018
                                                }
1019
                                                else
1020
                                                {
1021
                                                    Text = control.ArrowText;
1022
                                                }
1023 e0f00e26 djkim
1024 4f017ed3 taeseongkim
                                                try
1025
                                                {
1026
                                                    if (control.fontConfig.Count == 4)
1027 7ca218b3 KangIngu
                                                    {
1028 4f017ed3 taeseongkim
                                                        fontsize = Convert.ToDouble(control.fontConfig[3]);
1029 7ca218b3 KangIngu
                                                    }
1030 8c3a888c djkim
1031 4f017ed3 taeseongkim
                                                    //강인구 수정(2018.04.17)
1032 8c3a888c djkim
                                                    var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1033 4f017ed3 taeseongkim
1034 8c3a888c djkim
                                                    FontStyle fontStyle = FontStyles.Normal;
1035
                                                    if (FontStyles.Italic == TextStyle)
1036
                                                    {
1037
                                                        fontStyle = FontStyles.Italic;
1038
                                                    }
1039
1040
                                                    FontWeight fontWeight = FontWeights.Black;
1041
1042
                                                    var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1043
                                                    if (FontWeights.Bold == TextWeight)
1044
                                                    {
1045
                                                        fontWeight = FontWeights.Bold;
1046
                                                    }
1047
1048
                                                    TextDecorationCollection decoration = TextDecorations.Baseline;
1049 4f017ed3 taeseongkim
                                                    if (control.fontConfig.Count() == 5)
1050 8c3a888c djkim
                                                    {
1051
                                                        decoration = TextDecorations.Underline;
1052
                                                    }
1053
1054 4f017ed3 taeseongkim
                                                    if (control.isTrans)
1055 e0f00e26 djkim
                                                    {
1056 4f017ed3 taeseongkim
                                                            //인구 수정 Arrow Text Style적용 되도록 변경
1057
                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1058
                                                            newStartPoint, tempMidPoint, newEndPoint, control.isFixed,
1059
                                                            LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1060 4804a4fb humkyung
                                                    }
1061 8c3a888c djkim
                                                    else
1062
                                                    {
1063 4f017ed3 taeseongkim
                                                        if (control.isFixed)
1064 e0f00e26 djkim
                                                        {
1065 4f017ed3 taeseongkim
                                                            var testP = new Point(0, 0);
1066 e0f00e26 djkim
                                                            if (control.isFixed)
1067
                                                            {
1068 4f017ed3 taeseongkim
                                                                if (tempPoint[1] == newEndPoint)
1069 e0f00e26 djkim
                                                                {
1070 4f017ed3 taeseongkim
                                                                    testP = new Point(newEndPoint.X, newEndPoint.Y - 10);
1071
                                                                }
1072
                                                                else if (tempPoint[3] == newEndPoint)
1073
                                                                {
1074
                                                                    testP = new Point(newEndPoint.X, newEndPoint.Y + 10);
1075
                                                                }
1076
                                                                else if (tempPoint[0] == newEndPoint)
1077
                                                                {
1078
                                                                    testP = new Point(newEndPoint.X - 10, newEndPoint.Y);
1079
                                                                }
1080
                                                                else if (tempPoint[2] == newEndPoint)
1081
                                                                {
1082
                                                                    testP = new Point(newEndPoint.X + 10, newEndPoint.Y);
1083 e0f00e26 djkim
                                                                }
1084
                                                            }
1085 4f017ed3 taeseongkim
                                                            //인구 수정 Arrow Text Style적용 되도록 변경
1086
                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1087
                                                                tempStartPoint, testP, tempEndPoint, control.isFixed,
1088
                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
1089
                                                            FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1090
                                                        }
1091
                                                        else
1092
                                                        {
1093
                                                            //인구 수정 Arrow Text Style적용 되도록 변경
1094
                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1095
                                                                newStartPoint, tempMidPoint, tempEndPoint, control.isFixed,
1096
                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1097 e0f00e26 djkim
                                                        }
1098 8c3a888c djkim
                                                    }
1099 4f017ed3 taeseongkim
                                                }
1100
                                                catch (Exception ex)
1101
                                                {
1102
                                                    throw ex;
1103
                                                }
1104
1105 e0f00e26 djkim
                                                }
1106
                                                break;
1107
                                            #endregion
1108
                                            #region SignControl
1109
                                            case "SignControl":
1110
                                                using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1111
                                                {
1112
1113
                                                    double Angle = control.Angle;
1114
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1115
                                                    Point TopRightPoint = GetPdfPointSystem(control.TR);
1116
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1117
                                                    Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1118
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1119
                                                    double Opacity = control.Opac;
1120
                                                    string UserNumber = control.UserNumber;
1121 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1122 e0f00e26 djkim
                                                }
1123
                                                break;
1124
                                            #endregion
1125
                                            #region MyRegion
1126
                                            case "DateControl":
1127
                                                using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1128
                                                {
1129
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1130
                                                    string Text = control.Text;
1131
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1132
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1133
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1134
                                                    SolidColorBrush FontColor = _SetColor;
1135
                                                    double Angle = control.Angle;
1136
                                                    double Opacity = control.Opac;
1137 c206d293 taeseongkim
                                                    Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1138 f633b10b KangIngu
                                                }
1139 e0f00e26 djkim
                                                break;
1140
                                            #endregion
1141
                                            #region SymControlN (APPROVED)
1142
                                            case "SymControlN":
1143
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1144 8c3a888c djkim
                                                {
1145 e0f00e26 djkim
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1146
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1147
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1148
                                                    SolidColorBrush FontColor = _SetColor;
1149
                                                    double Angle = control.Angle;
1150
                                                    double Opacity = control.Opac;
1151
1152 c206d293 taeseongkim
                                                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1153
1154
                                                    if (stamp.Count() > 0)
1155
                                                    {
1156
                                                        var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1157
1158
                                                        Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1159
                                                    }
1160
1161 e0f00e26 djkim
                                                    string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1162 c206d293 taeseongkim
                                                    
1163 e0f00e26 djkim
                                                }
1164
                                                break;
1165
                                            case "SymControl":
1166
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1167
                                                {
1168
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1169
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1170
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1171
                                                    SolidColorBrush FontColor = _SetColor;
1172
                                                    double Angle = control.Angle;
1173
                                                    double Opacity = control.Opac;
1174 8c3a888c djkim
1175 e0f00e26 djkim
                                                    string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1176 c206d293 taeseongkim
                                                    Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1177 8c3a888c djkim
                                                }
1178 e0f00e26 djkim
                                                break;
1179
                                            #endregion
1180
                                            #region Image
1181
                                            case "ImgControl":
1182
                                                using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1183
                                                {
1184
                                                    double Angle = control.Angle;
1185
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1186
                                                    Point TopRightPoint = GetPdfPointSystem(control.TR);
1187
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1188
                                                    Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1189
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1190
                                                    double Opacity = control.Opac;
1191
                                                    string FilePath = control.ImagePath;
1192
                                                    //Uri uri = new Uri(s.ImagePath);
1193
1194 16fe076c humkyung
                                                    Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1195 e0f00e26 djkim
                                                }
1196
                                                break;
1197
                                            #endregion
1198
                                            default:
1199 c206d293 taeseongkim
                                                StatusChange($"{ControlT.Name} Not Support", 0);
1200 e0f00e26 djkim
                                                break;
1201
                                        }
1202 68e3cd94 taeseongkim
                                        
1203 8c3a888c djkim
                                    }
1204 e0f00e26 djkim
                                    catch (Exception ex)
1205
                                    {
1206 ab590000 taeseongkim
                                        StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1207 e0f00e26 djkim
                                    }
1208 8c3a888c djkim
                                }
1209 abaa85b4 djkim
                            }
1210 e0f00e26 djkim
                            pdfStamper.Outlines = root;
1211
                            pdfStamper.Close();
1212
                            pdfReader.Close();
1213 7ca218b3 KangIngu
                        }
1214 abaa85b4 djkim
                    }
1215 e0f00e26 djkim
                    #endregion
1216 7ca218b3 KangIngu
                }
1217
                if (tempFileInfo.Exists)
1218
                {
1219
                    tempFileInfo.Delete();
1220
                }
1221
1222
                if (File.Exists(pdfFilePath))
1223
                {
1224 e77fc685 taeseongkim
                    string destfilepath = null;
1225 7ca218b3 KangIngu
                    try
1226
                    {
1227 6e5f7eaf djkim
                        FinalPDFPath = new FileInfo(pdfFilePath);
1228
1229 907a99b3 taeseongkim
                        /// 정리 필요함. DB로 변경
1230
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1231
1232
                        if(!string.IsNullOrEmpty(pdfmovepath))
1233
                        {
1234
                            _FinalPDFStorgeLocal = pdfmovepath;
1235
                        }
1236
1237 e77fc685 taeseongkim
                        destfilepath = Path.Combine(_FinalPDFStorgeLocal, FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1238
1239 6e5f7eaf djkim
                        if (File.Exists(destfilepath))
1240
                            File.Delete(destfilepath);
1241 e77fc685 taeseongkim
1242 6e5f7eaf djkim
                        File.Move(FinalPDFPath.FullName, destfilepath);
1243
                        FinalPDFPath = new FileInfo(destfilepath);
1244 7ca218b3 KangIngu
                        File.Delete(pdfFilePath);
1245
                    }
1246
                    catch (Exception ex)
1247
                    {
1248 e77fc685 taeseongkim
                        SetNotice(finaldata.ID, $"File move error - Source File : {FinalPDFPath.FullName} dest File : {destfilepath}" + ex.ToString());
1249 7ca218b3 KangIngu
                    }
1250
1251
                    return true;
1252
                }
1253
            }
1254 7aa36857 humkyung
            catch (Exception ex)
1255 7ca218b3 KangIngu
            {
1256 782ad7b1 taeseongkim
                SetNotice(finaldata.ID, "SetStempinPDF error: " + ex.ToString());
1257 7ca218b3 KangIngu
            }
1258
            return false;
1259
        }
1260 4f017ed3 taeseongkim
1261
        /// <summary>
1262
        /// kcom의 화살표방향과 틀려 추가함
1263
        /// </summary>
1264
        /// <param name="PageAngle"></param>
1265
        /// <param name="endP"></param>
1266
        /// <param name="ps">box Points</param>
1267
        /// <param name="IsFixed"></param>
1268
        /// <returns></returns>
1269
        private Point GetArrowTextControlTestPoint(double PageAngle,Point endP,List<Point> ps,bool IsFixed)
1270
        {
1271
            Point testP = endP;
1272
1273
            try
1274
            {
1275
                switch (Math.Abs(PageAngle).ToString())
1276
                {
1277
                    case "90":
1278
                        testP = new Point(endP.X + 50, endP.Y);
1279
                        break;
1280
                    case "270":
1281
                        testP = new Point(endP.X - 50, endP.Y);
1282
                        break;
1283
                }
1284
1285
                //20180910 LJY 각도에 따라.
1286
                switch (Math.Abs(PageAngle).ToString())
1287
                {
1288
                    case "90":
1289
                        if (IsFixed)
1290
                        {
1291
                            if (ps[0] == endP) //상단
1292
                            {
1293
                                testP = new Point(endP.X, endP.Y + 50);
1294
                                //System.Diagnostics.Debug.WriteLine("상단"+ testP);
1295
                            }
1296
                            else if (ps[1] == endP) //하단
1297
                            {
1298
                                testP = new Point(endP.X, endP.Y - 50);
1299
                                //System.Diagnostics.Debug.WriteLine("하단"+ testP);
1300
                            }
1301
                            else if (ps[2] == endP) //좌단
1302
                            {
1303
                                testP = new Point(endP.X - 50, endP.Y);
1304
                                //System.Diagnostics.Debug.WriteLine("좌단"+ testP);
1305
                            }
1306
                            else if (ps[3] == endP) //우단
1307
                            {
1308
                                testP = new Point(endP.X + 50, endP.Y);
1309
                                //System.Diagnostics.Debug.WriteLine("우단"+ testP);
1310
                            }
1311
                        }
1312
                        break;
1313
                    case "270":
1314
                        if (IsFixed)
1315
                        {
1316
                            if (ps[0] == endP) //상단
1317
                            {
1318
                                testP = new Point(endP.X, endP.Y - 50);
1319
                                //System.Diagnostics.Debug.WriteLine("상단" + testP);
1320
                            }
1321
                            else if (ps[1] == endP) //하단
1322
                            {
1323
                                testP = new Point(endP.X, endP.Y + 50);
1324
                                //System.Diagnostics.Debug.WriteLine("하단" + testP);
1325
                            }
1326
                            else if (ps[2] == endP) //좌단
1327
                            {
1328
                                testP = new Point(endP.X + 50, endP.Y);
1329
                                //System.Diagnostics.Debug.WriteLine("좌단" + testP);
1330
                            }
1331
                            else if (ps[3] == endP) //우단
1332
                            {
1333
                                testP = new Point(endP.X - 50, endP.Y);
1334
                                //System.Diagnostics.Debug.WriteLine("우단" + testP);
1335
                            }
1336
                        }
1337
                        break;
1338
                    default:
1339
                        if (IsFixed)
1340
                        {
1341
1342
                            if (ps[0] == endP) //상단
1343
                            {
1344
                                testP = new Point(endP.X, endP.Y - 50);
1345
                                //System.Diagnostics.Debug.WriteLine("상단");
1346
                            }
1347
                            else if (ps[1] == endP) //하단
1348
                            {
1349
                                testP = new Point(endP.X, endP.Y + 50);
1350
                                //System.Diagnostics.Debug.WriteLine("하단");
1351
                            }
1352
                            else if (ps[2] == endP) //좌단
1353
                            {
1354
                                testP = new Point(endP.X - 50, endP.Y);
1355
                                //System.Diagnostics.Debug.WriteLine("좌단");
1356
                            }
1357
                            else if (ps[3] == endP) //우단
1358
                            {
1359
                                testP = new Point(endP.X + 50, endP.Y);
1360
                                //System.Diagnostics.Debug.WriteLine("우단");
1361
                            }
1362
                        }
1363
                        break;
1364
                }
1365
1366
            }
1367
            catch (Exception)
1368
            {
1369
            }
1370
1371
            return testP;
1372
        }
1373
1374
        private Point Test(Rect rect,Point point)
1375
        {
1376
            Point result = new Point();
1377
1378
            Point newPoint = new Point();
1379
1380
            double oldNear = 0;
1381
            double newNear = 0;
1382
1383
            oldNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.TopRight, out result);
1384
1385
            newNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.BottomLeft, out newPoint);
1386
1387
            if (newNear < oldNear)
1388
            {
1389
                oldNear = newNear;
1390
                result = newPoint;
1391
            }
1392
1393
            newNear = MathSet.GetShortestDistance(point, rect.TopRight, rect.BottomRight, out newPoint);
1394
1395
            if (newNear < oldNear)
1396
            {
1397
                oldNear = newNear;
1398
                result = newPoint;
1399
            }
1400
1401
1402
            newNear = MathSet.GetShortestDistance(point, rect.BottomLeft, rect.BottomRight, out newPoint);
1403
1404
            if (newNear < oldNear)
1405
            {
1406
                oldNear = newNear;
1407
                result = newPoint;
1408
            }
1409
1410
            return result;
1411
        }
1412
1413
        private void DrawMultiArrowLine(S_ArrowControl_Multi control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, SolidColorBrush setColor)
1414
        {
1415
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1416
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1417
            Point MidPoint = GetPdfPointSystem(control.MidPoint);
1418
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1419
            DoubleCollection DashSize = control.DashSize;
1420
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1421
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1422
1423
            double Opacity = control.Opac;
1424
1425
            if (EndPoint == MidPoint)
1426
            {
1427
                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1428
            }
1429
            else
1430
            {
1431
                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, setColor, Opacity);
1432
            }
1433
1434
            Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, setColor, Opacity);
1435
1436
        }
1437
1438
        private void DrawLine(S_LineControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, SolidColorBrush setColor)
1439
        {
1440
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1441
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1442
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1443
            DoubleCollection DashSize = control.DashSize;
1444
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1445
1446
            var Opacity = control.Opac;
1447
            string UserID = control.UserID;
1448
            double Interval = control.Interval;
1449
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1450
            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, setColor, Opacity);
1451
            switch (control.LineStyleSet)
1452
            {
1453
                case LineStyleSet.ArrowLine:
1454
                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1455
                    break;
1456
                case LineStyleSet.CancelLine:
1457
                    {
1458
                        var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X)));
1459
                        var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y)));
1460
1461
                        if (x > y)
1462
                        {
1463
                            StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0));
1464
                            EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0));
1465
                            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, setColor, Opacity);
1466
                        }
1467
                    }
1468
                    break;
1469
                case LineStyleSet.TwinLine:
1470
                    {
1471
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1472
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1473
                    }
1474
                    break;
1475
                case LineStyleSet.DimLine:
1476
                    {
1477
                        Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1478
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1479
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1480
                    }
1481
                    break;
1482
                default:
1483
                    break;
1484
            }
1485
1486
        }
1487
1488
        private void DrawTextBox(S_TextControl control,PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2,SolidColorBrush setColor)
1489
        {
1490
            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1491
            string Text = control.Text;
1492
1493
            bool isUnderline = false;
1494
            control.BoxW -= scaleWidth;
1495
            control.BoxH -= scaleHeight;
1496
            System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
1497
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1498
            Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
1499
1500
            List<Point> pointSet = new List<Point>();
1501
            pointSet.Add(StartPoint);
1502
            pointSet.Add(EndPoint);
1503
1504
            PaintSet paint = PaintSet.None;
1505
            switch (control.paintMethod)
1506
            {
1507
                case 1:
1508
                    {
1509
                        paint = PaintSet.Fill;
1510
                    }
1511
                    break;
1512
                case 2:
1513
                    {
1514
                        paint = PaintSet.Hatch;
1515
                    }
1516
                    break;
1517
                default:
1518
                    break;
1519
            }
1520
            if (control.isHighLight) paint |= PaintSet.Highlight;
1521
1522
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1523
            double TextSize = Convert.ToDouble(data2[1]);
1524
            SolidColorBrush FontColor = setColor;
1525
            double Angle = control.Angle;
1526
            double Opacity = control.Opac;
1527
            FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
1528
            var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1529
1530
            FontStyle fontStyle = FontStyles.Normal;
1531
            if (FontStyles.Italic == TextStyle)
1532
            {
1533
                fontStyle = FontStyles.Italic;
1534
            }
1535
1536
            FontWeight fontWeight = FontWeights.Black;
1537
1538
            var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1539
            //강인구 수정(2018.04.17)
1540
            if (FontWeights.Bold == TextWeight)
1541
            //if (FontWeights.ExtraBold == TextWeight)
1542
            {
1543
                fontWeight = FontWeights.Bold;
1544
            }
1545
1546
            TextDecorationCollection decoration = TextDecorations.Baseline;
1547
            if (control.fontConfig.Count() == 4)
1548
            {
1549
                decoration = TextDecorations.Underline;
1550
            }
1551
1552
            Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, setColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1553
        }
1554 c206d293 taeseongkim
    
1555 7ca218b3 KangIngu
1556 40cf5bf7 humkyung
        ~MarkupToPDF()
1557
        {
1558
            this.Dispose(false);
1559
        }
1560
1561
        private bool disposed;
1562
1563 7ca218b3 KangIngu
        public void Dispose()
1564
        {
1565 40cf5bf7 humkyung
            this.Dispose(true);
1566
            GC.SuppressFinalize(this);
1567
        }
1568
1569
        protected virtual void Dispose(bool disposing)
1570
        {
1571
            if (this.disposed) return;
1572
            if (disposing)
1573
            {
1574
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1575
            }
1576
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1577
            this.disposed = true;
1578 8c3a888c djkim
        }
1579 7f01e35f ljiyeon
1580 7ca218b3 KangIngu
        #endregion
1581
    }
1582
}
클립보드 이미지 추가 (최대 크기: 500 MB)