프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 782ad7b1

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

1
using IFinalPDF;
2
using iTextSharp.text.pdf;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using MarkupToPDF.Controls.Common;
6
using MarkupToPDF.Serialize.Core;
7
using MarkupToPDF.Serialize.S_Control;
8
using Markus.Fonts;
9
using System;
10
using System.Collections.Generic;
11
using System.Configuration;
12
using System.IO;
13
using System.Linq;
14
using System.Net;
15
using System.Runtime.InteropServices;
16
using System.Text;
17
using System.Web;
18
using System.Windows;
19
using System.Windows.Media;
20

    
21
namespace MarkupToPDF
22
{
23
    public class MarkupToPDF : IDisposable
24
    {
25
        #region 초기 데이터
26
        private static iTextSharp.text.Rectangle mediaBox;
27
        private FileInfo PdfFilePath = null;
28
        private FileInfo FinalPDFPath = null;
29
        private string _FinalPDFStorgeLocal = null;
30
        private string _FinalPDFStorgeRemote = null;
31
        private string OriginFileName = null;
32
        public FINAL_PDF FinalItem;
33
        public DOCINFO DocInfoItem = null;
34
        public List<DOCPAGE> DocPageItem = null;
35
        public MARKUP_INFO MarkupInfoItem = null;
36
        public List<MARKUP_DATA> MarkupDataSet = null;
37
        //private string _PrintPDFStorgeLocal = null;
38
        //private string _PrintPDFStorgeRemote = null;
39
        public event EventHandler<MakeFinalErrorArgs> FinalMakeError;
40
        public event EventHandler<EndFinalEventArgs> EndFinal;
41
        public event EventHandler<StatusChangedEventArgs> StatusChanged;
42

    
43
        private iTextSharp.text.Rectangle pdfSize { get; set; }
44
        private double pageW = 0;
45
        private double pageH = 0;
46

    
47
        //private const double zoomLevel = 3.0;
48
        private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음
49
        #endregion
50

    
51
        #region 메서드        
52
        public static bool IsLocalIPAddress(string host)
53
        {
54
            try
55
            {
56
                IPAddress[] hostIPs = Dns.GetHostAddresses(host);
57
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
58

    
59
                foreach (IPAddress hostIP in hostIPs)
60
                {
61
                    if (IPAddress.IsLoopback(hostIP)) return true;
62

    
63
                    foreach (IPAddress localIP in localIPs)
64
                    {
65
                        if (hostIP.Equals(localIP)) return true;
66
                    }
67
                }
68
            }
69
            catch { }
70
            return false;
71
        }
72

    
73
        private void SetNotice(string finalID, string message)
74
        {
75
            if (FinalMakeError != null)
76
            {
77
                FinalMakeError(this, new MakeFinalErrorArgs { FinalID = finalID, Message = message });
78
            }
79
        }
80

    
81
        private string GetFileName(string hrefLink)
82
        {
83
            try
84
            {
85
                if (hrefLink.Contains("vpcs_doclib"))
86
                {
87
                    return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\"));
88
                }
89
                else
90
                {
91
                    Uri fileurl = new Uri(hrefLink);
92
                    int index = hrefLink.IndexOf("?");
93
                    string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName");
94
                    return filename;
95
                }
96
            }
97
            catch (Exception ex)
98
            {
99
                throw ex;
100
            }
101
        }
102

    
103
        public Point GetPdfPointSystem(Point point)
104
        {
105
            /// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다.
106
            /// Rotation 90 일 경우 pdfsize box 와 media box 가 달라 다른 계산식 적용
107
            if (pdfSize.Rotation == 90)
108
            {
109
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom);
110
            }
111
            else
112
            {
113
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Height - (float)(point.Y / scaleHeight) + pdfSize.Bottom);
114
            }  
115
        }
116

    
117
        public double GetPdfSize(double size)
118
        {
119
            return (size / scaleWidth);
120
        }
121

    
122
        public List<Point> GetPdfPointSystem(List<Point> point)
123
        {
124
            List<Point> dummy = new List<Point>();
125
            foreach (var item in point)
126
            {
127
                dummy.Add(GetPdfPointSystem(item));
128
            }
129
            return dummy;
130
        }
131

    
132
        public double returnAngle(Point start, Point end)
133
        {
134
            double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y);
135
            //angle *= -1;
136

    
137
            angle += 90;
138
            //if (angle < 0)
139
            //{
140
            //    angle = angle + 360;
141
            //}
142
            return angle;
143
        }
144

    
145
        #endregion
146

    
147
        public bool AddStamp(string stampData)
148
        {
149
            bool result = false;
150

    
151
            try
152
            {
153
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
154
                {
155
                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
156

    
157
                    if(stamp.Count() > 0)
158
                    {
159
                        var xamldata = Serialize.Core.JsonSerializerHelper.CompressStamp(stampData);
160

    
161
                        stamp.First().VALUE = xamldata;
162
                        _entity.SaveChanges();
163
                        result = true;
164
                    }
165
                }
166
            }
167
            catch (Exception)
168
            {
169

    
170
                throw;
171
            }
172

    
173
            return result;
174

    
175
        }
176

    
177
        /// <summary>
178
        /// local에서 final 생성하는 경우 이 함수로 추가 후 실행
179
        /// </summary>
180
        /// <param name="finalpdf"></param>
181
        /// <returns></returns>
182
        public AddFinalPDFResult AddFinalPDF(string ProjectNo,string DocumentID,string UserID)
183
        {
184
            //var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS");
185
            //System.Diagnostics.Debug.WriteLine(list);
186

    
187
            AddFinalPDFResult result = new AddFinalPDFResult { Success = false };
188

    
189
            try
190
            {
191
                FINAL_PDF addItem = new FINAL_PDF{
192
                    ID = CommonLib.Guid.shortGuid(),
193
                    PROJECT_NO = ProjectNo,
194
                    DOCUMENT_ID = DocumentID,
195
                    CREATE_USER_ID = UserID,
196
                    CREATE_DATETIME = DateTime.Now,
197
                    STATUS = 4
198
                };
199

    
200
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
201
                {
202
                    var docitems = _entity.DOCINFO.Where(x => x.PROJECT_NO == ProjectNo && x.DOCUMENT_ID == DocumentID);
203

    
204
                    if(docitems.Count() > 0)
205
                    {
206
                        addItem.DOCINFO_ID = docitems.First().ID;
207
                        result.Success = true;
208
                    }
209
                    else
210
                    {
211
                        result.Exception = "docInfo Not Found.";
212
                        result.Success = false;
213
                    }
214

    
215
                    var markupInfoItems = _entity.MARKUP_INFO.Where(x =>x.DOCINFO_ID == addItem.DOCINFO_ID);
216

    
217
                    if (markupInfoItems.Count() > 0)
218
                    {
219
                        addItem.MARKUPINFO_ID = markupInfoItems.First().ID;
220
                        result.Success = true;
221
                    }
222
                    else
223
                    {
224
                        result.Exception = "Markup Info Not Found.";
225
                        result.Success = false;
226
                    }
227
                }
228

    
229
                if (result.Success)
230
                {
231
                    using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
232
                    {
233
                        var finalList = _entity.FINAL_PDF.Where(final => final.ID == addItem.ID);
234

    
235
                        /// Insrt and Update
236
                        if (finalList.Count() == 0)
237
                        {
238
                            _entity.FINAL_PDF.AddObject(addItem);
239
                            _entity.SaveChanges();
240

    
241
                            result.FinalPDF = addItem;
242
                            result.Success = true;
243
                        }
244
                    }
245
                }
246
            }
247
            catch (Exception ex)
248
            {
249
                System.Diagnostics.Debug.WriteLine(ex);
250
                result.Success = false;
251
            }
252

    
253
            return result;
254
        }
255

    
256
        #region 생성자 & 소멸자
257
        public void MakeFinalPDF(object _FinalPDF)
258
        {
259
            DOCUMENT_ITEM documentItem;
260
            FINAL_PDF FinalPDF = (FINAL_PDF)_FinalPDF;
261
            FinalItem = FinalPDF;
262

    
263

    
264
            string PdfFilePathRoot = null;
265
            string TestFile = System.IO.Path.GetTempFileName();
266

    
267
            #region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정
268
            try
269
            {
270
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
271
                {
272
                    var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO);
273

    
274
                    if (_properties.Count() > 0)
275
                    {
276
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).Count() == 0)
277
                        {
278
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found.");
279
                            return;
280
                        }
281
                        else
282
                        { 
283
                            PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE;
284
                        }
285

    
286
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).Count() == 0)
287
                        {
288
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found.");
289
                            return;
290
                        }
291
                        else
292
                        {
293
                            _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE;
294
                        }
295

    
296

    
297
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).Count() == 0)
298
                        {
299
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found.");
300
                            return;
301
                        }
302
                        else
303
                        {
304
                            _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE;
305
                        }
306
                    }
307
                    else
308
                    {
309
                        SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found.");
310
                        return;
311
                    }
312

    
313
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
314

    
315
                    if (finalList.Count() > 0)
316
                    {
317
                        finalList.FirstOrDefault().START_DATETIME = DateTime.Now;
318
                        finalList.FirstOrDefault().STATUS = (int)FinalStatus.Create;
319
                        _entity.SaveChanges();
320
                    }
321

    
322
                }
323
            }
324
            catch (Exception ex)
325
            {
326
                SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString());
327
                return;
328
            }
329
            #endregion
330

    
331
            #region 문서 복사
332
            try
333
            {
334
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString()))
335
                {
336
                    var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
337

    
338
                    if (_DOCINFO.Count() > 0)
339
                    {
340
                        DocInfoItem = _DOCINFO.FirstOrDefault();
341
                        DocPageItem = DocInfoItem.DOCPAGE.ToList();
342

    
343
                        PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\"
344
                                         + (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5))
345
                                         + @"\" + FinalPDF.DOCUMENT_ID + @"\";
346

    
347
                        MarkupInfoItem = DocInfoItem.MARKUP_INFO.Where(data => data.CONSOLIDATE == 1 && data.AVOID_CONSOLIDATE == 0 && data.PART_CONSOLIDATE == 0).FirstOrDefault();
348

    
349
                        if (MarkupInfoItem == null)
350
                        {
351
                            throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다");
352
                        }
353
                        else
354
                        {
355
                            if (MarkupInfoItem.MARKUP_INFO_VERSION.Count > 0)
356
                            {
357
                                MarkupDataSet = MarkupInfoItem.MARKUP_INFO_VERSION.OrderBy(d => d.CREATE_DATE).LastOrDefault().MARKUP_DATA.ToList().OrderBy(d => d.PAGENUMBER).ToList();
358
                            }
359
                            else
360
                            {
361
                                throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다");
362
                            }
363
                        }
364

    
365
                        documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault();
366
                        if (documentItem == null)
367
                        {
368
                            throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요");
369
                        }
370

    
371
                        var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 
372

    
373
                        #region 파일 체크
374
                        if (_files.Count() == 1)
375
                        {
376
                            /// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정
377
                            //if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()))
378
                            //{
379
                                OriginFileName = _files.First().Name;
380
                                PdfFilePath = _files.First().CopyTo(TestFile, true);
381
                                StatusChange($"Copy File  file Count = 1 : {PdfFilePath}", 0);
382
                            //}
383
                            //else
384
                            //{
385
                            //    throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower());
386
                            //}
387
                        }
388
                        else if (_files.Count() > 1)
389
                        {
390
                            var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault();
391

    
392
                            if (originalFile == null)
393
                            {
394
                                throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다");
395
                            }
396
                            else
397
                            {
398
                                OriginFileName = originalFile.Name;
399
                                PdfFilePath = originalFile.CopyTo(TestFile, true);
400
                                StatusChange($"Copy File file Count  > 1 : {PdfFilePath}", 0);
401
                            }
402
                        }
403
                        else
404
                        {
405
                            throw new FileNotFoundException("PDF를 찾지 못하였습니다");
406
                        }
407
                        #endregion
408

    
409
                        #region 예외처리
410
                        if (PdfFilePath == null)
411
                        {
412
                            throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다");
413
                        }
414
                        if (!PdfFilePath.Exists)
415
                        {
416
                            throw new Exception("PDF원본이 존재하지 않습니다");
417
                        }
418
                        #endregion
419
                        
420
                    }
421
                    else
422
                    {
423
                        throw new Exception("일치하는 DocInfo가 없습니다");
424
                    }
425
                }
426
            }
427
            catch (Exception ex)
428
            {
429
                if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다")
430
                {
431
                    SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다");
432
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
433
                    process.StartInfo.FileName = "cmd";
434
                    process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\"";
435
                    process.Start();
436
                }
437
                else
438
                {
439
                    SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message);
440
                }
441
            }
442
            #endregion
443

    
444
            try
445
            {
446

    
447
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
448
                {
449
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
450

    
451
                    if (finalList.Count() > 0)
452
                    {
453
                        //TestFile = SetFlattingPDF(TestFile);
454
                        //StatusChange($"SetFlattingPDF : {TestFile}", 0);
455

    
456
                        SetStampInPDF(FinalItem, TestFile, MarkupInfoItem);
457

    
458
                        StatusChange($"SetStampInPDF : {TestFile}", 0);
459
                    }
460
                }
461
                if (EndFinal != null)
462
                {
463
                    EndFinal(this, new EndFinalEventArgs
464
                    {
465
                        OriginPDFName = OriginFileName,
466
                        FinalPDFPath = FinalPDFPath.FullName,
467
                        Error = "",
468
                        Message = "",
469
                        FinalPDF = FinalPDF,
470
                    });
471
                }
472
            }
473
            catch (Exception ex)
474
            {
475
                SetNotice(FinalPDF.ID, "MarkFinalPDF Error : " + ex.Message);
476
            }
477
        }
478
        #endregion
479

    
480
        #region PDF
481
        public static float scaleWidth = 0;
482
        public static float scaleHeight = 0;
483

    
484
        private string SetFlattingPDF(string tempFileInfo)
485
        {
486
            if (File.Exists(tempFileInfo))
487
            {
488
                FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName());
489

    
490
                PdfReader pdfReader = new PdfReader(tempFileInfo);
491

    
492
                for (int i = 1; i <= pdfReader.NumberOfPages; i++)
493
                {
494
                    var mediaBox = pdfReader.GetPageSize(i);
495
                    var cropbox = pdfReader.GetCropBox(i);
496

    
497
                    //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString()))
498
                    //{
499
                    //    _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE)
500
                    //}
501
                    var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault();
502

    
503
                    //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width;
504
                    //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height;
505
                    //scaleWidth = 2.0832634F;
506
                    //scaleHeight = 3.0F;
507

    
508
                    PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i));
509
                    //강인구 수정
510
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height))
511
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height))
512
                    //{
513
                    //    var pageDict = pdfReader.GetPageN(i);
514
                    //    pageDict.Put(PdfName.MEDIABOX, rect);
515
                    //}
516
                }
517

    
518
                var memStream = new MemoryStream();
519
                var stamper = new PdfStamper(pdfReader, memStream)
520
                {
521
                    FormFlattening = true,                     
522
                    //FreeTextFlattening = true,
523
                    //AnnotationFlattening = true,                     
524
                };
525
                
526
                stamper.Close();
527
                pdfReader.Close();
528
                var array = memStream.ToArray();
529
                File.Delete(tempFileInfo);
530
                File.WriteAllBytes(TestFile.FullName, array);
531

    
532
                return TestFile.FullName;
533
            }
534
            else
535
            {
536
                return tempFileInfo;
537
            }
538
        }
539

    
540
        public void flattenPdfFile(string src, ref string dest)
541
        {
542
            PdfReader reader = new PdfReader(src);
543
            var memStream = new MemoryStream();
544
            var stamper = new PdfStamper(reader, memStream)
545
            {
546
                FormFlattening = true,
547
                FreeTextFlattening = true,
548
                AnnotationFlattening = true,
549
            };
550

    
551
            stamper.Close();
552
            var array = memStream.ToArray();
553
            File.WriteAllBytes(dest, array);
554
        }
555

    
556
        public void StatusChange(string message,int CurrentPage)
557
        {
558
            if(StatusChanged != null)
559
            {
560
                var sb = new StringBuilder();
561
                sb.AppendLine(message);
562

    
563
                StatusChanged(null, new StatusChangedEventArgs { CurrentPage = CurrentPage, Message = sb.ToString() });
564
            }
565
        }
566

    
567
        public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo)
568
        {
569
            try
570
            {
571
        
572
                FileInfo tempFileInfo = new FileInfo(testFile);
573

    
574
                if (!Directory.Exists(_FinalPDFStorgeLocal))
575
                {
576
                    Directory.CreateDirectory(_FinalPDFStorgeLocal);
577
                }
578
                string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name);
579
          
580

    
581
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
582
                {
583
                    FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault();
584

    
585
                    #region 코멘트 적용 + 커버시트
586
                    using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) //
587
                    {
588
                        StatusChange("comment Cover",0);
589
                        
590
                        PdfReader pdfReader = new PdfReader(pdfStream);
591
                        //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
592
                        Dictionary<string, object> bookmark;
593
                        List<Dictionary<string, object>> outlines;
594

    
595
                        outlines = new List<Dictionary<string, object>>();
596
                        List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
597

    
598
                        var dic = new Dictionary<string, object>();
599

    
600
                        foreach (var data in MarkupDataSet)
601
                        {
602
                            StatusChange("MarkupDataSet", 0);
603

    
604
                            string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
605

    
606
                            string username = "";
607
                            string userdept = "";
608

    
609
                            using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
610
                            {
611
                                var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
612

    
613
                                if(memberlist.Count() > 0)
614
                                {
615
                                    username = memberlist.First().NAME;
616
                                    userdept = memberlist.First().DEPARTMENT;
617
                                }
618
                            }
619

    
620
                            bookmark = new Dictionary<string, object>();
621
                            bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
622
                            bookmark.Add("Page", data.PAGENUMBER + " Fit");
623
                            bookmark.Add("Action", "GoTo");
624
                            bookmark.Add("Kids", outlines);
625
                            root.Add(bookmark);
626
                        }
627

    
628

    
629
                        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
630
                        {
631
                            AcroFields pdfFormFields = pdfStamper.AcroFields;
632

    
633
                            try
634
                            {
635
                                if (pdfFormFields.GenerateAppearances != true)
636
                                {
637
                                    pdfFormFields.GenerateAppearances = true;
638
                                }
639
                            }
640
                            catch (Exception ex)
641
                            {
642
                                SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
643
                            }
644

    
645
                            var _SetColor = new SolidColorBrush(Colors.Red);
646

    
647
                            string[] delimiterChars = { "|DZ|" };
648
                            string[] delimiterChars2 = { "|" };
649

    
650
                            //pdfStamper.FormFlattening = true; //이미 선처리 작업함
651
                            pdfStamper.SetFullCompression();
652
                            _SetColor = new SolidColorBrush(Colors.Red);
653

    
654
                            foreach (var markupItem in MarkupDataSet)
655
                            {
656
                                pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER);
657
                                var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER).FirstOrDefault();
658

    
659
                                mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER);
660
                                var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER);                                
661

    
662
                                /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
663
                                if (cropBox != null && 
664
                                    (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
665
                                {
666
                                    PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
667

    
668
                                    PdfArray oNewMediaBox = new PdfArray();
669
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Left));
670
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Top));
671
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Right));
672
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
673
                                    dict.Put(PdfName.MEDIABOX, oNewMediaBox);
674

    
675
                                    pdfSize = cropBox; 
676
                                }
677
                                scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
678
                                scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
679

    
680
                                pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
681
                                _entity.SaveChanges();
682

    
683
                                string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
684

    
685
                                PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
686

    
687

    
688
                                foreach (var data in markedData)
689
                                {
690
                                    var item = JsonSerializerHelper.UnCompressString(data);
691
                                    var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
692

    
693
                                    try
694
                                    {
695
                                        switch (ControlT.Name)
696
                                        {
697
                                            #region LINE
698
                                            case "LineControl":
699
                                                {
700
                                                    using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
701
                                                    {
702
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
703
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
704
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
705
                                                        DoubleCollection DashSize = control.DashSize;
706
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
707

    
708
                                                        var Opacity = control.Opac;
709
                                                        string UserID = control.UserID;
710
                                                        double Interval = control.Interval;
711
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
712
                                                        Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, _SetColor, Opacity);
713
                                                        switch (control.LineStyleSet)
714
                                                        {
715
                                                            case LineStyleSet.ArrowLine:
716
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
717
                                                                break;
718
                                                            case LineStyleSet.CancelLine:
719
                                                                {
720
                                                                    var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X)));
721
                                                                    var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y)));
722

    
723
                                                                    if (x > y)
724
                                                                    {
725
                                                                        StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0));
726
                                                                        EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0));
727
                                                                        Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, Opacity);
728
                                                                    }
729
                                                                }
730
                                                                break;
731
                                                            case LineStyleSet.TwinLine:
732
                                                                {
733
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
734
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
735
                                                                }
736
                                                                break;
737
                                                            case LineStyleSet.DimLine:
738
                                                                {
739
                                                                    Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
740
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
741
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
742
                                                                }
743
                                                                break;
744
                                                            default:
745
                                                                break;
746
                                                        }
747

    
748

    
749
                                                    }
750
                                                }
751
                                                break;
752
                                            #endregion
753
                                            #region ArrowControlMulti
754
                                            case "ArrowControl_Multi":
755
                                                {
756
                                                    using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
757
                                                    {
758
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
759
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
760
                                                        Point MidPoint = GetPdfPointSystem(control.MidPoint);
761
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
762
                                                        DoubleCollection DashSize = control.DashSize;
763
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
764
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
765

    
766
                                                        double Opacity = control.Opac;
767

    
768
                                                        if (EndPoint == MidPoint)
769
                                                        {
770
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
771
                                                        }
772
                                                        else
773
                                                        {
774
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
775
                                                        }
776

    
777
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
778

    
779
                                                    }
780
                                                }
781
                                                break;
782
                                            #endregion
783
                                            #region PolyControl
784
                                            case "PolygonControl":
785
                                                using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
786
                                                {
787
                                                    string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
788
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
789
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
790
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
791
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
792
                                                    double Opacity = control.Opac;
793
                                                    DoubleCollection DashSize = control.DashSize;
794

    
795
                                                    Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
796
                                                }
797
                                                break;
798
                                            #endregion
799
                                            #region ArcControl or ArrowArcControl
800
                                            case "ArcControl":
801
                                            case "ArrowArcControl":
802
                                                {
803
                                                    using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
804
                                                    {
805
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
806
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
807
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
808
                                                        Point MidPoint = GetPdfPointSystem(control.MidPoint);
809
                                                        DoubleCollection DashSize = control.DashSize;
810
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
811

    
812
                                                        var Opacity = control.Opac;
813
                                                        string UserID = control.UserID;
814
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
815
                                                        bool IsTransOn = control.IsTransOn;
816

    
817
                                                        if (control.IsTransOn)
818
                                                        {
819
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
820
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
821
                                                        }
822
                                                        else
823
                                                        {
824
                                                            Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity);
825
                                                        }
826

    
827
                                                        if (ControlT.Name == "ArrowArcControl")
828
                                                        {
829
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
830
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
831
                                                        }
832
                                                    }
833
                                                }
834
                                                break;
835
                                            #endregion
836
                                            #region RectangleControl
837
                                            case "RectangleControl":
838
                                                using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
839
                                                {
840
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
841
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
842
                                                    var PaintStyle = control.PaintState;
843
                                                    double Angle = control.Angle;
844
                                                    DoubleCollection DashSize = control.DashSize;
845
                                                    double Opacity = control.Opac;
846
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
847

    
848
                                                    Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
849
                                                }
850
                                                break;
851
                                            #endregion
852
                                            #region TriControl
853
                                            case "TriControl":
854
                                                using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
855
                                                {
856
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
857
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
858
                                                    var PaintStyle = control.Paint;
859
                                                    double Angle = control.Angle;
860
                                                    //StrokeColor = _SetColor, //색상은 레드
861
                                                    DoubleCollection DashSize = control.DashSize;
862
                                                    double Opacity = control.Opac;
863
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
864

    
865
                                                    Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
866
                                                }
867
                                                break;
868
                                            #endregion
869
                                            #region CircleControl
870
                                            case "CircleControl":
871
                                                using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
872
                                                {
873
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
874
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
875
                                                    var StartPoint = GetPdfPointSystem(control.StartPoint);
876
                                                    var EndPoint = GetPdfPointSystem(control.EndPoint);
877
                                                    var PaintStyle = control.PaintState;
878
                                                    double Angle = control.Angle;
879
                                                    DoubleCollection DashSize = control.DashSize;
880
                                                    double Opacity = control.Opac;
881
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
882
                                                    Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
883

    
884
                                                }
885
                                                break;
886
                                            #endregion
887
                                            #region RectCloudControl
888
                                            case "RectCloudControl":
889
                                                using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
890
                                                {
891
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
892
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
893
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
894
                                                    double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
895

    
896
                                                    double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
897

    
898
                                                    var PaintStyle = control.PaintState;
899
                                                    double Opacity = control.Opac;
900
                                                    DoubleCollection DashSize = control.DashSize;
901

    
902
                                                    //드로잉 방식이 표현되지 않음
903
                                                    var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
904

    
905
                                                    double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
906
                                                    bool reverse = (area < 0);
907
                                                    if (PaintStyle == PaintSet.None)
908
                                                    {
909
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
910
                                                    }
911
                                                    else
912
                                                    {
913
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
914
                                                    }
915
                                                }
916
                                                break;
917
                                            #endregion
918
                                            #region CloudControl
919
                                            case "CloudControl":
920
                                                using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
921
                                                {
922
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
923
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
924
                                                    double Toler = control.Toler;
925
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
926
                                                    double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
927
                                                    var PaintStyle = control.PaintState;
928
                                                    double Opacity = control.Opac;
929
                                                    bool isTransOn = control.IsTrans;
930
                                                    bool isChain = control.IsChain;
931

    
932
                                                    DoubleCollection DashSize = control.DashSize;
933

    
934
                                                    if (isChain)
935
                                                    {
936
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
937
                                                    }
938
                                                    else
939
                                                    {
940
                                                        if (isTransOn)
941
                                                        {
942
                                                            double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
943
                                                            bool reverse = (area < 0);
944

    
945
                                                            if (PaintStyle == PaintSet.None)
946
                                                            {
947
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
948
                                                            }
949
                                                            else
950
                                                            {
951
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
952
                                                            }
953
                                                        }
954
                                                        else
955
                                                        {
956
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
957
                                                        }
958
                                                    }
959
                                                }
960
                                                break;
961
                                            #endregion
962
                                            #region TEXT
963
                                            case "TextControl":
964
                                                using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
965
                                                {
966
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
967
                                                    string Text = control.Text;
968

    
969
                                                    bool isUnderline = false;
970
                                                    control.BoxW -= scaleWidth;
971
                                                    control.BoxH -= scaleHeight;
972
                                                    System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
973
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
974
                                                    Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
975

    
976
                                                    List<Point> pointSet = new List<Point>();
977
                                                    pointSet.Add(StartPoint);
978
                                                    pointSet.Add(EndPoint);
979

    
980
                                                    PaintSet paint = PaintSet.None;
981
                                                    switch (control.paintMethod)
982
                                                    {
983
                                                        case 1:
984
                                                            {
985
                                                                paint = PaintSet.Fill;
986
                                                            }
987
                                                            break;
988
                                                        case 2:
989
                                                            {
990
                                                                paint = PaintSet.Hatch;
991
                                                            }
992
                                                            break;
993
                                                        default:
994
                                                            break;
995
                                                    }
996
                                                    if (control.isHighLight) paint |= PaintSet.Highlight;
997

    
998
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
999
                                                    double TextSize = Convert.ToDouble(data2[1]);
1000
                                                    SolidColorBrush FontColor = _SetColor;
1001
                                                    double Angle = control.Angle;
1002
                                                    double Opacity = control.Opac;
1003
                                                    FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
1004
                                                    var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1005
                                                    
1006
                                                    FontStyle fontStyle = FontStyles.Normal;
1007
                                                    if (FontStyles.Italic == TextStyle)
1008
                                                    {
1009
                                                        fontStyle = FontStyles.Italic;
1010
                                                    }
1011

    
1012
                                                    FontWeight fontWeight = FontWeights.Black;
1013

    
1014
                                                    var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1015
                                                    //강인구 수정(2018.04.17)
1016
                                                    if (FontWeights.Bold == TextWeight)
1017
                                                    //if (FontWeights.ExtraBold == TextWeight)
1018
                                                    {
1019
                                                        fontWeight = FontWeights.Bold;
1020
                                                    }
1021

    
1022
                                                    TextDecorationCollection decoration = TextDecorations.Baseline;
1023
                                                    if (control.fontConfig.Count() == 4)
1024
                                                    {
1025
                                                        decoration = TextDecorations.Underline;
1026
                                                    }
1027

    
1028
                                                    Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, _SetColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1029
                                                }
1030
                                                break;
1031
                                            #endregion
1032
                                            #region ArrowTextControl
1033
                                            case "ArrowTextControl":
1034
                                                using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
1035
                                                {
1036
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1037
                                                    Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
1038
                                                    Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
1039
                                                    Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
1040
                                                    bool isUnderLine = false;
1041
                                                    string Text = "";
1042
                                                    double fontsize = 30;
1043

    
1044
                                                    System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
1045
                                                    Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight));
1046
                                                    List<Point> tempPoint = new List<Point>();
1047

    
1048
                                                    var tempRectMidPoint = MathSet.getRectMiddlePoint(rect);
1049

    
1050
                                                    tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y));
1051
                                                    tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top));
1052
                                                    tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y));
1053
                                                    tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom));
1054
                                                    double Angle = control.Angle;
1055
                                                    var newStartPoint = tempStartPoint;
1056
                                                    var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint);
1057
                                                    var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint);
1058

    
1059
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1060
                                                    SolidColorBrush FontColor = _SetColor;
1061
                                                    bool isHighlight = control.isHighLight;
1062
                                                    double Opacity = control.Opac;
1063
                                                    PaintSet Paint = PaintSet.None;
1064

    
1065
                                                    switch (control.ArrowStyle)
1066
                                                    {
1067
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
1068
                                                            {
1069
                                                                Paint = PaintSet.None;
1070
                                                            }
1071
                                                            break;
1072
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
1073
                                                            {
1074
                                                                Paint = PaintSet.Hatch;
1075
                                                            }
1076
                                                            break;
1077
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
1078
                                                            {
1079
                                                                Paint = PaintSet.Fill;
1080
                                                            }
1081
                                                            break;
1082
                                                        default:
1083
                                                            break;
1084
                                                    }
1085
                                                    if (control.isHighLight) Paint |= PaintSet.Highlight;
1086

    
1087
                                                    if (Paint == PaintSet.Hatch)
1088
                                                    {
1089
                                                        Text = control.ArrowText;
1090
                                                    }
1091
                                                    else
1092
                                                    {
1093
                                                        Text = control.ArrowText;
1094
                                                    }
1095

    
1096
                                                    try
1097
                                                    {
1098
                                                        if (control.fontConfig.Count == 4)
1099
                                                        {
1100
                                                            fontsize = Convert.ToDouble(control.fontConfig[3]);
1101
                                                        }
1102

    
1103
                                                        //강인구 수정(2018.04.17)
1104
                                                        var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1105

    
1106
                                                        FontStyle fontStyle = FontStyles.Normal;
1107
                                                        if (FontStyles.Italic == TextStyle)
1108
                                                        {
1109
                                                            fontStyle = FontStyles.Italic;
1110
                                                        }
1111

    
1112
                                                        FontWeight fontWeight = FontWeights.Black;
1113

    
1114
                                                        var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1115
                                                        if (FontWeights.Bold == TextWeight)
1116
                                                        {
1117
                                                            fontWeight = FontWeights.Bold;
1118
                                                        }
1119

    
1120
                                                        TextDecorationCollection decoration = TextDecorations.Baseline;
1121
                                                        if (control.fontConfig.Count() == 5)
1122
                                                        {
1123
                                                            decoration = TextDecorations.Underline;
1124
                                                        }
1125

    
1126
                                                        if (control.isTrans)
1127
                                                        {
1128
                                                            //인구 수정 Arrow Text Style적용 되도록 변경
1129
                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1130
                                                                newStartPoint, tempMidPoint, control.isFixed,
1131
                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1132
                                                        }
1133
                                                        else
1134
                                                        {
1135
                                                            if (control.isFixed)
1136
                                                            {
1137
                                                                var testP = new Point(0, 0);
1138
                                                                if (control.isFixed)
1139
                                                                {
1140
                                                                    if (tempPoint[1] == newEndPoint)
1141
                                                                    {
1142
                                                                        testP = new Point(newEndPoint.X, newEndPoint.Y - 10);
1143
                                                                    }
1144
                                                                    else if (tempPoint[3] == newEndPoint)
1145
                                                                    {
1146
                                                                        testP = new Point(newEndPoint.X, newEndPoint.Y + 10);
1147
                                                                    }
1148
                                                                    else if (tempPoint[0] == newEndPoint)
1149
                                                                    {
1150
                                                                        testP = new Point(newEndPoint.X - 10, newEndPoint.Y);
1151
                                                                    }
1152
                                                                    else if (tempPoint[2] == newEndPoint)
1153
                                                                    {
1154
                                                                        testP = new Point(newEndPoint.X + 10, newEndPoint.Y);
1155
                                                                    }
1156
                                                                }
1157
                                                                //인구 수정 Arrow Text Style적용 되도록 변경
1158
                                                                Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1159
                                                                    tempStartPoint, testP, control.isFixed ,
1160
                                                                    LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
1161
                                                                FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1162
                                                            }
1163
                                                            else
1164
                                                            {
1165
                                                                //인구 수정 Arrow Text Style적용 되도록 변경
1166
                                                                Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1167
                                                                    newStartPoint, tempMidPoint, control.isFixed,
1168
                                                                    LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1169
                                                            }
1170
                                                        }
1171
                                                    }
1172
                                                    catch (Exception ex)
1173
                                                    {
1174
                                                        throw ex;
1175
                                                    }
1176
                                                }
1177
                                                break;
1178
                                            #endregion
1179
                                            #region SignControl
1180
                                            case "SignControl":
1181
                                                using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1182
                                                {
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 UserNumber = control.UserNumber;
1192
                                                    Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1193
                                                }
1194
                                                break;
1195
                                            #endregion
1196
                                            #region MyRegion
1197
                                            case "DateControl":
1198
                                                using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1199
                                                {
1200
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1201
                                                    string Text = control.Text;
1202
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1203
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1204
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1205
                                                    SolidColorBrush FontColor = _SetColor;
1206
                                                    double Angle = control.Angle;
1207
                                                    double Opacity = control.Opac;
1208
                                                    Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1209
                                                }
1210
                                                break;
1211
                                            #endregion
1212
                                            #region SymControlN (APPROVED)
1213
                                            case "SymControlN":
1214
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1215
                                                {
1216
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1217
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1218
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1219
                                                    SolidColorBrush FontColor = _SetColor;
1220
                                                    double Angle = control.Angle;
1221
                                                    double Opacity = control.Opac;
1222

    
1223
                                                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1224

    
1225
                                                    if (stamp.Count() > 0)
1226
                                                    {
1227
                                                        var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1228

    
1229
                                                        Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1230
                                                    }
1231

    
1232
                                                    string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1233
                                                    
1234
                                                }
1235
                                                break;
1236
                                            case "SymControl":
1237
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1238
                                                {
1239
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1240
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1241
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1242
                                                    SolidColorBrush FontColor = _SetColor;
1243
                                                    double Angle = control.Angle;
1244
                                                    double Opacity = control.Opac;
1245

    
1246
                                                    string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1247
                                                    Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1248
                                                }
1249
                                                break;
1250
                                            #endregion
1251
                                            #region Image
1252
                                            case "ImgControl":
1253
                                                using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1254
                                                {
1255
                                                    double Angle = control.Angle;
1256
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1257
                                                    Point TopRightPoint = GetPdfPointSystem(control.TR);
1258
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1259
                                                    Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1260
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1261
                                                    double Opacity = control.Opac;
1262
                                                    string FilePath = control.ImagePath;
1263
                                                    //Uri uri = new Uri(s.ImagePath);
1264

    
1265
                                                    Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1266
                                                }
1267
                                                break;
1268
                                            #endregion
1269
                                            default:
1270
                                                StatusChange($"{ControlT.Name} Not Support", 0);
1271
                                                break;
1272
                                        }
1273
                                    }
1274
                                    catch (Exception ex)
1275
                                    {
1276
                                        StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1277
                                    }
1278
                                }
1279
                            }
1280
                            pdfStamper.Outlines = root;
1281
                            pdfStamper.Close();
1282
                            pdfReader.Close();
1283
                        }
1284
                    }
1285
                    #endregion
1286
                }
1287
                if (tempFileInfo.Exists)
1288
                {
1289
                    tempFileInfo.Delete();
1290
                }
1291

    
1292
                if (File.Exists(pdfFilePath))
1293
                {
1294
                    try
1295
                    {
1296
                        FinalPDFPath = new FileInfo(pdfFilePath);
1297

    
1298
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1299
                        string destfilepath = Path.Combine(pdfmovepath,FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1300
                        if (File.Exists(destfilepath))
1301
                            File.Delete(destfilepath);
1302
                        File.Move(FinalPDFPath.FullName, destfilepath);
1303
                        FinalPDFPath = new FileInfo(destfilepath);
1304
                        File.Delete(pdfFilePath);
1305
                    }
1306
                    catch (Exception ex)
1307
                    {
1308
                        SetNotice(finaldata.ID, "File move error: " + ex.ToString());
1309
                    }
1310

    
1311
                    return true;
1312
                }
1313
            }
1314
            catch (Exception ex)
1315
            {
1316
                SetNotice(finaldata.ID, "SetStempinPDF error: " + ex.ToString());
1317
            }
1318
            return false;
1319
        }
1320
    
1321

    
1322
        ~MarkupToPDF()
1323
        {
1324
            this.Dispose(false);
1325
        }
1326

    
1327
        private bool disposed;
1328

    
1329
        public void Dispose()
1330
        {
1331
            this.Dispose(true);
1332
            GC.SuppressFinalize(this);
1333
        }
1334

    
1335
        protected virtual void Dispose(bool disposing)
1336
        {
1337
            if (this.disposed) return;
1338
            if (disposing)
1339
            {
1340
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1341
            }
1342
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1343
            this.disposed = true;
1344
        }
1345

    
1346
        #endregion
1347
    }
1348
}
클립보드 이미지 추가 (최대 크기: 500 MB)