프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (88 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
        public MarkupToPDF()
26
        {
27
        }
28

    
29
        #region 초기 데이터
30
        private FileInfo PdfFilePath = null;
31
        private FileInfo FinalPDFPath = null;
32
        private string _FinalPDFStorgeLocal = null;
33
        private string _FinalPDFStorgeRemote = null;
34
        private string OriginFileName = null;
35
        public FINAL_PDF FinalItem;
36
        public DOCINFO DocInfoItem = null;
37
        public List<DOCPAGE> DocPageItem = null;
38
        public MARKUP_INFO MarkupInfoItem = null;
39
        public List<MARKUP_DATA> MarkupDataSet = null;
40
        //private string _PrintPDFStorgeLocal = null;
41
        //private string _PrintPDFStorgeRemote = null;
42
        public event EventHandler<MakeFinalErrorArgs> FinalMakeError;
43
        public event EventHandler<EndFinalEventArgs> EndFinal;
44
        public event EventHandler<StatusChangedEventArgs> StatusChanged;
45

    
46
        private iTextSharp.text.Rectangle pdfSize { get; set; }
47
        private double pageW = 0;
48
        private double pageH = 0;
49

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

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

    
62
                foreach (IPAddress hostIP in hostIPs)
63
                {
64
                    if (IPAddress.IsLoopback(hostIP)) return true;
65

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

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

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

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

    
120
        public double GetPdfSize(double size)
121
        {
122
            return (size / scaleWidth);
123
        }
124

    
125
        public List<Point> GetPdfPointSystem(List<Point> points)
126
        {
127
            return points.ConvertAll(x => GetPdfPointSystem(x));
128
        }
129

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

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

    
143
        #endregion
144

    
145
        public bool AddStamp(string stampData)
146
        {
147
            bool result = false;
148

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

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

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

    
168
                throw;
169
            }
170

    
171
            return result;
172

    
173
        }
174

    
175
        #region 생성자 & 소멸자
176
        /// <summary>
177
        /// 주어진 _FinalPDF 데이터로 Final PDF를 생성한다.
178
        /// </summary>
179
        /// <param name="_FinalPDF"></param>
180
        public void MakeFinalPDF(object _FinalPDF)
181
        {
182
            DOCUMENT_ITEM documentItem;
183
            FINAL_PDF FinalPDF = (FINAL_PDF)_FinalPDF;
184
            FinalItem = FinalPDF;
185

    
186

    
187
            string PdfFilePathRoot = null;
188
            string TestFile = System.IO.Path.GetTempFileName();
189

    
190
            #region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정
191
            try
192
            {
193
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
194
                {
195
                    var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO);
196
                    if (_properties.Any())
197
                    {
198
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).Count() == 0)
199
                        {
200
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found.");
201
                            return;
202
                        }
203
                        else
204
                        {
205
                            PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE;
206
                        }
207

    
208
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).Count() == 0)
209
                        {
210
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found.");
211
                            return;
212
                        }
213
                        else
214
                        {
215
                            _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE;
216
                        }
217

    
218

    
219
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).Count() == 0)
220
                        {
221
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found.");
222
                            return;
223
                        }
224
                        else
225
                        {
226
                            _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE;
227
                        }
228
                    }
229
                    else
230
                    {
231
                        SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found.");
232
                        return;
233
                    }
234

    
235
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
236

    
237
                    if (finalList.Count() > 0)
238
                    {
239
                        finalList.FirstOrDefault().START_DATETIME = DateTime.Now;
240
                        finalList.FirstOrDefault().STATUS = (int)FinalStatus.Create;
241
                        _entity.SaveChanges();
242
                    }
243

    
244
                }
245
            }
246
            catch (Exception ex)
247
            {
248
                SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString());
249
                return;
250
            }
251
            #endregion
252

    
253
            #region 원본 PDF를 TempFile로 복사
254
            try
255
            {
256
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString()))
257
                {
258
                    var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
259

    
260
                    if (_DOCINFO.Count() > 0)
261
                    {
262
                        DocInfoItem = _DOCINFO.First();
263

    
264
                        DocPageItem = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == DocInfoItem.ID).ToList();
265

    
266
                        PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\"
267
                                         + (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5))
268
                                         + @"\" + FinalPDF.DOCUMENT_ID + @"\";
269

    
270
                        var infoItems = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == DocInfoItem.ID && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0);
271

    
272
                        if (infoItems.Count() == 0)
273
                        {
274
                            throw new InvalidOperationException("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다");
275
                        }
276
                        else
277
                        {
278
                            MarkupInfoItem = infoItems.First();
279

    
280
                            var markupInfoVerItems = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == MarkupInfoItem.ID).ToList();
281

    
282
                            if (markupInfoVerItems.Count() > 0)
283
                            {
284
                                var markupInfoVerItem = markupInfoVerItems.OrderByDescending(x => x.CREATE_DATE).First();
285

    
286
                                MarkupDataSet = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupInfoVerItem.ID).OrderBy(d => d.PAGENUMBER).ToList();
287
                            }
288
                            else
289
                            {
290
                                throw new InvalidOperationException("MARKUP_INFO_VERSION 이 존재 하지 않습니다");
291
                            }
292
                        }
293

    
294
                        documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault();
295
                        if (documentItem == null)
296
                        {
297
                            throw new InvalidOperationException("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요");
298
                        }
299

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

    
302
                        #region 파일 체크
303
                        if (_files.Count() == 1)
304
                        {
305
                            /// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정
306
                            //if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()))
307
                            //{
308
                            OriginFileName = _files.First().Name;
309
                            PdfFilePath = _files.First().CopyTo(TestFile, true);
310
                            StatusChange($"Copy File  file Count = 1 : {PdfFilePath}", 0);
311
                            //}
312
                            //else
313
                            //{
314
                            //    throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower());
315
                            //}
316
                        }
317
                        else if (_files.Count() > 1)
318
                        {
319
                            var originalFile = _files.FirstOrDefault(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE)));
320

    
321
                            if (originalFile == null)
322
                            {
323
                                throw new FileNotFoundException("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다");
324
                            }
325
                            else
326
                            {
327
                                OriginFileName = originalFile.Name;
328
                                PdfFilePath = originalFile.CopyTo(TestFile, true);
329
                                StatusChange($"Copy File file Count  > 1 : {PdfFilePath}", 0);
330
                            }
331
                        }
332
                        else
333
                        {
334
                            throw new FileNotFoundException("PDF를 찾지 못하였습니다");
335
                        }
336
                        #endregion
337

    
338
                        #region 예외처리
339
                        if (PdfFilePath == null)
340
                        {
341
                            throw new InvalidOperationException("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다");
342
                        }
343
                        if (!PdfFilePath.Exists)
344
                        {
345
                            throw new FileNotFoundException("PDF원본이 존재하지 않습니다");
346
                        }
347
                        #endregion
348

    
349
                    }
350
                    else
351
                    {
352
                        throw new InvalidOperationException("일치하는 DocInfo가 없습니다");
353
                    }
354
                }
355
            }
356
            catch (Exception ex)
357
            {
358
                if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다")
359
                {
360
                    SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다");
361
                    //System.Diagnostics.Process process = new System.Diagnostics.Process();
362
                    //process.StartInfo.FileName = "cmd";
363
                    //process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\"";
364
                    //process.Start();
365
                }
366
                else
367
                {
368
                    SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message);
369
                }
370
            }
371
            #endregion
372

    
373
            try
374
            {
375

    
376
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
377
                {
378
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
379
                    if (finalList.Count() > 0)
380
                    {
381
                        //TestFile = SetFlattingPDF(TestFile);
382
                        //StatusChange($"SetFlattingPDF : {TestFile}", 0);
383

    
384
                        SetStampInPDF(FinalItem, TestFile, MarkupInfoItem);
385

    
386
                        StatusChange($"SetStampInPDF : {TestFile}", 0);
387
                    }
388
                }
389
                if (EndFinal != null)
390
                {
391
                    EndFinal(this, new EndFinalEventArgs
392
                    {
393
                        FinalPDFRemotePath = _FinalPDFStorgeRemote + @"\" + FinalPDFPath.Name,
394
                        OriginPDFName = OriginFileName,
395
                        FinalPDFPath = FinalPDFPath.FullName,
396
                        Error = "",
397
                        Message = "",
398
                        FinalPDF = FinalPDF,
399
                    });
400
                }
401
            }
402
            catch (Exception ex)
403
            {
404
                SetNotice(FinalPDF.ID, "MarkFinalPDF Error : " + ex.Message);
405
            }
406
        }
407
        #endregion
408

    
409
        #region PDF
410
        public static float scaleWidth { get; set; } = 0;
411
        public static float scaleHeight { get; set; } = 0;
412

    
413
        private string SetFlattingPDF(string tempFileInfo)
414
        {
415
            if (File.Exists(tempFileInfo))
416
            {
417
                FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName());
418

    
419
                PdfReader pdfReader = new PdfReader(tempFileInfo);
420

    
421
                for (int i = 1; i <= pdfReader.NumberOfPages; i++)
422
                {
423
                    var mediaBox = pdfReader.GetPageSize(i);
424
                    var cropbox = pdfReader.GetCropBox(i);
425

    
426
                    //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString()))
427
                    //{
428
                    //    _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE)
429
                    //}
430
                    var currentPage = DocPageItem.Find(d => d.PAGE_NUMBER == i);
431

    
432
                    //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width;
433
                    //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height;
434
                    //scaleWidth = 2.0832634F;
435
                    //scaleHeight = 3.0F;
436

    
437
                    PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i));
438
                    //강인구 수정
439
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height))
440
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height))
441
                    //{
442
                    //    var pageDict = pdfReader.GetPageN(i);
443
                    //    pageDict.Put(PdfName.MEDIABOX, rect);
444
                    //}
445
                }
446

    
447
                var memStream = new MemoryStream();
448
                var stamper = new PdfStamper(pdfReader, memStream)
449
                {
450
                    FormFlattening = true,                     
451
                    //FreeTextFlattening = true,
452
                    //AnnotationFlattening = true,                     
453
                };
454
                
455
                stamper.Close();
456
                pdfReader.Close();
457
                var array = memStream.ToArray();
458
                File.Delete(tempFileInfo);
459
                File.WriteAllBytes(TestFile.FullName, array);
460

    
461
                return TestFile.FullName;
462
            }
463
            else
464
            {
465
                return tempFileInfo;
466
            }
467
        }
468

    
469
        public void flattenPdfFile(string src, ref string dest)
470
        {
471
            PdfReader reader = new PdfReader(src);
472
            var memStream = new MemoryStream();
473
            var stamper = new PdfStamper(reader, memStream)
474
            {
475
                FormFlattening = true,
476
                FreeTextFlattening = true,
477
                AnnotationFlattening = true,
478
            };
479

    
480
            stamper.Close();
481
            var array = memStream.ToArray();
482
            File.WriteAllBytes(dest, array);
483
        }
484

    
485
        public void StatusChange(string message,int CurrentPage)
486
        {
487
            if(StatusChanged != null)
488
            {
489
                //var sb = new StringBuilder();
490
                //sb.AppendLine(message);
491

    
492
                StatusChanged(this, new StatusChangedEventArgs { CurrentPage = CurrentPage, Message = message });
493
            }
494
        }
495

    
496
        /// <summary>
497
        /// 원본 PDF에 Markup을 생성한다.
498
        /// </summary>
499
        /// <param name="finaldata"></param>
500
        /// <param name="testFile"></param>
501
        /// <param name="markupInfo"></param>
502
        /// <returns></returns>
503
        public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo)
504
        {
505
            try
506
            {
507
                FileInfo tempFileInfo = new FileInfo(testFile);
508

    
509
                if (!Directory.Exists(_FinalPDFStorgeLocal))
510
                {
511
                    Directory.CreateDirectory(_FinalPDFStorgeLocal);
512
                }
513

    
514
                string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name);
515
          
516

    
517
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
518
                {
519
                    FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault();
520

    
521
                    #region 코멘트 적용 + 커버시트
522
                    using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) //
523
                    {
524
                        StatusChange("comment Cover",0);
525

    
526
                        using (PdfReader pdfReader = new PdfReader(pdfStream))
527
                        { 
528
                            //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
529
                            Dictionary<string, object> bookmark;
530
                            List<Dictionary<string, object>> outlines;
531

    
532
                            outlines = new List<Dictionary<string, object>>();
533
                            List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
534

    
535
                            var dic = new Dictionary<string, object>();
536

    
537
                            #region  북마크 생성
538
                            foreach (var data in MarkupDataSet)
539
                            {
540
                                //StatusChange("MarkupDataSet", 0);
541

    
542
                                string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
543

    
544
                                string username = "";
545
                                string userdept = "";
546

    
547
                                using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
548
                                {
549
                                    var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
550

    
551
                                    if(memberlist.Any())
552
                                    {
553
                                        username = memberlist[0].NAME;
554
                                        userdept = memberlist[0].DEPARTMENT;
555
                                    }
556
                                }
557

    
558
                                bookmark = new Dictionary<string, object>();
559
                                bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
560
                                bookmark.Add("Page", data.PAGENUMBER + " Fit");
561
                                bookmark.Add("Action", "GoTo");
562
                                bookmark.Add("Kids", outlines);
563
                                root.Add(bookmark);
564
                            }
565
                            #endregion
566

    
567
                            iTextSharp.text.Version.GetInstance();
568

    
569
                            using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
570
                            {
571
                                try
572
                                {
573
                                    if (pdfStamper.AcroFields != null && pdfStamper.AcroFields.GenerateAppearances != true)
574
                                    {
575
                                        pdfStamper.AcroFields.GenerateAppearances = true;
576
                                    }
577
                                }
578
                                catch (Exception ex)
579
                                {
580
                                    SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
581
                                }
582

    
583
                                #region Markup 색상을 설정한다.(DB에 값이 있으면 DB 값으로 설정한다.)
584
                                System.Drawing.Color _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red);
585
                                #endregion
586

    
587
                                string[] delimiterChars = { "|DZ|" };
588
                                string[] delimiterChars2 = { "|" };
589

    
590
                                //pdfStamper.FormFlattening = true; //이미 선처리 작업함
591
                                pdfStamper.SetFullCompression();
592
                                _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red);
593

    
594
                                StringBuilder strLog = new StringBuilder();
595
                                int lastPageNo = 0;
596

    
597
                                var groups = MarkupDataSet.GroupBy(x => x.PAGENUMBER);
598
                                foreach (var group in groups)
599
                                {
600
                                    int PageNumber = group.Key;
601
                                    #region ZIndex 값으로 정렬한다.
602
                                    var items = new List<Tuple<string, S_BaseControl>>();
603
                                    foreach (var item in group)
604
                                    {
605
                                        var tokens = item.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries).ToList();
606
                                        items.AddRange(tokens.ConvertAll(x =>
607
                                        {
608
                                            var str = JsonSerializerHelper.UnCompressString(x);
609
                                            var control = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(str);
610
                                            return new Tuple<string, S_BaseControl>(str, control);
611
                                        }));
612
                                    }
613

    
614
                                    var zgroups = items.GroupBy(x => x.Item2.ZIndex).OrderBy(x => x.Key);
615
                                    #endregion
616

    
617
                                    foreach (var zgroup in zgroups)
618
                                    {
619
                                        var ordered = zgroup.OrderBy(x => x.Item2.Index);
620
                                        foreach (var order in ordered)
621
                                        {
622
                                            /// 2020.11.13 김태성
623
                                            /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함.
624
                                            var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == PageNumber);
625
                                            if (pageitems.Any())
626
                                            {
627
                                                var currentPage = pageitems.First();
628
                                                pdfSize = pdfReader.GetPageSizeWithRotation(PageNumber);
629
                                                lastPageNo = PageNumber;
630

    
631
                                                iTextSharp.text.Rectangle mediaBox = pdfReader.GetPageSize(PageNumber);
632
                                                var cropBox = pdfReader.GetCropBox(PageNumber);
633

    
634
                                                /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
635
                                                if (cropBox != null &&
636
                                                    (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
637
                                                {
638
                                                    PdfDictionary dict = pdfReader.GetPageN(PageNumber);
639

    
640
                                                    PdfArray oNewMediaBox = new PdfArray();
641
                                                    oNewMediaBox.Add(new PdfNumber(cropBox.Left));
642
                                                    oNewMediaBox.Add(new PdfNumber(cropBox.Top));
643
                                                    oNewMediaBox.Add(new PdfNumber(cropBox.Right));
644
                                                    oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
645
                                                    dict.Put(PdfName.MEDIABOX, oNewMediaBox);
646

    
647
                                                    pdfSize = cropBox;
648
                                                }
649

    
650
                                                scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
651
                                                scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
652

    
653
                                                pdfLink.CURRENT_PAGE = PageNumber;
654
                                                _entity.SaveChanges();
655

    
656
                                                PdfContentByte contentByte = pdfStamper.GetOverContent(PageNumber);
657
                                                var item = order.Item1;
658
                                                var ControlT = order.Item2;
659

    
660
                                                try
661
                                                {
662
                                                    switch (ControlT.Name)
663
                                                    {
664
                                                        #region LINE
665
                                                        case "LineControl":
666
                                                            {
667
                                                                using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
668
                                                                {
669
                                                                    DrawLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
670
                                                                }
671
                                                            }
672
                                                            break;
673
                                                        #endregion
674
                                                        #region ArrowControlMulti
675
                                                        case "ArrowControl_Multi":
676
                                                            {
677
                                                                using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
678
                                                                {
679
                                                                    DrawMultiArrowLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
680
                                                                }
681
                                                            }
682
                                                            break;
683
                                                        #endregion
684
                                                        #region PolyControl
685
                                                        case "PolygonControl":
686
                                                            using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
687
                                                            {
688
                                                                string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
689
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
690
                                                                var PaintStyle = control.PaintState;
691
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
692
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
693
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()), scaleWidth);
694
                                                                double Opacity = control.Opac;
695
                                                                DoubleCollection DashSize = control.DashSize;
696

    
697
                                                                Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle | PaintSet.Outline, Opacity);
698
                                                                //Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
699
                                                            }
700
                                                            break;
701
                                                        #endregion
702
                                                        #region ArcControl or ArrowArcControl
703
                                                        case "ArcControl":
704
                                                        case "ArrowArcControl":
705
                                                            {
706
                                                                using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
707
                                                                {
708
                                                                    string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
709
                                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
710
                                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
711
                                                                    Point MidPoint = GetPdfPointSystem(control.MidPoint);
712
                                                                    DoubleCollection DashSize = control.DashSize;
713
                                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
714

    
715
                                                                    var Opacity = control.Opac;
716
                                                                    string UserID = control.UserID;
717
                                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()), scaleWidth);
718
                                                                    bool IsTransOn = control.IsTransOn;
719

    
720
                                                                    if (control.IsTransOn)
721
                                                                    {
722
                                                                        Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
723
                                                                        Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
724
                                                                    }
725
                                                                    else
726
                                                                    {
727
                                                                        Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
728
                                                                    }
729

    
730
                                                                    if (ControlT.Name == "ArrowArcControl")
731
                                                                    {
732
                                                                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
733
                                                                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
734
                                                                    }
735
                                                                }
736
                                                            }
737
                                                            break;
738
                                                        #endregion
739
                                                        #region RectangleControl
740
                                                        case "RectangleControl":
741
                                                            using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
742
                                                            {
743
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
744
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
745
                                                                var PaintStyle = control.PaintState;
746
                                                                double Angle = control.Angle;
747
                                                                DoubleCollection DashSize = control.DashSize;
748
                                                                double Opacity = control.Opac;
749
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
750

    
751
                                                                Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
752
                                                            }
753
                                                            break;
754
                                                        #endregion
755
                                                        #region TriControl
756
                                                        case "TriControl":
757
                                                            using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
758
                                                            {
759
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
760
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
761
                                                                var PaintStyle = control.Paint;
762
                                                                double Angle = control.Angle;
763
                                                                //StrokeColor = _SetColor, //색상은 레드
764
                                                                DoubleCollection DashSize = control.DashSize;
765
                                                                double Opacity = control.Opac;
766
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
767

    
768
                                                                Controls_PDF.DrawSet_Shape.DrawTriangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle | PaintSet.Outline, Opacity);
769
                                                            }
770
                                                            break;
771
                                                        #endregion
772
                                                        #region CircleControl
773
                                                        case "CircleControl":
774
                                                            using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
775
                                                            {
776
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
777
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
778
                                                                var StartPoint = GetPdfPointSystem(control.StartPoint);
779
                                                                var EndPoint = GetPdfPointSystem(control.EndPoint);
780
                                                                var PaintStyle = control.PaintState;
781
                                                                double Angle = control.Angle;
782
                                                                DoubleCollection DashSize = control.DashSize;
783
                                                                double Opacity = control.Opac;
784
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
785
                                                                Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
786

    
787
                                                            }
788
                                                            break;
789
                                                        #endregion
790
                                                        #region RectCloudControl
791
                                                        case "RectCloudControl":
792
                                                            using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
793
                                                            {
794
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
795
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
796
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
797
                                                                double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
798

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

    
801
                                                                var PaintStyle = control.PaintState;
802
                                                                double Opacity = control.Opac;
803
                                                                DoubleCollection DashSize = control.DashSize;
804

    
805
                                                                //드로잉 방식이 표현되지 않음
806
                                                                var rotate = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
807

    
808
                                                                double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
809
                                                                bool reverse = (area < 0);
810

    
811
                                                                Controls_PDF.DrawSet_Cloud.DrawCloudRect(PointSet, LineSize, (int)rotate, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
812
                                                            }
813
                                                            break;
814
                                                        #endregion
815
                                                        #region CloudControl
816
                                                        case "CloudControl":
817
                                                            using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
818
                                                            {
819
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
820
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
821
                                                                double Toler = control.Toler;
822
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
823
                                                                double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
824
                                                                var PaintStyle = control.PaintState;
825
                                                                double Opacity = control.Opac;
826
                                                                bool isTransOn = control.IsTrans;
827
                                                                bool isChain = control.IsChain;
828

    
829
                                                                DoubleCollection DashSize = control.DashSize;
830

    
831
                                                                if (isChain)
832
                                                                {
833
                                                                    Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
834
                                                                }
835
                                                                else
836
                                                                {
837
                                                                    if (isTransOn)
838
                                                                    {
839
                                                                        double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
840
                                                                        bool reverse = (area < 0);
841

    
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
                                                                    else
852
                                                                    {
853
                                                                        Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
854
                                                                    }
855
                                                                }
856
                                                            }
857
                                                            break;
858
                                                        #endregion
859
                                                        #region TEXT
860
                                                        case "TextControl":
861
                                                            using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
862
                                                            {
863
                                                                control.Draw(this, contentByte, delimiterChars, delimiterChars2, _SetColor, scaleWidth, scaleHeight);
864
                                                            }
865
                                                            break;
866
                                                        #endregion
867
                                                        #region ArrowTextControl
868
                                                        case "ArrowTextControl":
869
                                                            using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
870
                                                            {
871
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
872
                                                                Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
873
                                                                Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
874
                                                                Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
875
                                                                bool isUnderLine = false;
876
                                                                string Text = "";
877
                                                                double fontsize = 30;
878

    
879
                                                                System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
880
                                                                List<Point> Connections = new List<Point>(control.GetConnectionPoints(tempEndPoint, scaleWidth, scaleHeight));
881

    
882
                                                                double Angle = control.Angle;
883

    
884
                                                                var newStartPoint = tempStartPoint;
885
                                                                var ConnectionPoint = MathSet.getNearPoint(Connections, tempMidPoint);
886

    
887
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2[0]), scaleWidth);
888
                                                                System.Drawing.Color FontColor = _SetColor;
889
                                                                bool isHighlight = control.isHighLight;
890
                                                                double Opacity = control.Opac;
891
                                                                PaintSet Paint = PaintSet.None;
892

    
893
                                                                switch (control.ArrowStyle)
894
                                                                {
895
                                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
896
                                                                        {
897
                                                                            Paint = PaintSet.None;
898
                                                                        }
899
                                                                        break;
900
                                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
901
                                                                        {
902
                                                                            Paint = PaintSet.Hatch;
903
                                                                        }
904
                                                                        break;
905
                                                                    case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
906
                                                                        {
907
                                                                            Paint = PaintSet.Fill;
908
                                                                        }
909
                                                                        break;
910
                                                                    default:
911
                                                                        break;
912
                                                                }
913
                                                                if (control.isHighLight) Paint |= PaintSet.Highlight;
914

    
915
                                                                if (Paint == PaintSet.Hatch)
916
                                                                {
917
                                                                    Text = control.ArrowText;
918
                                                                }
919
                                                                else
920
                                                                {
921
                                                                    Text = control.ArrowText;
922
                                                                }
923

    
924
                                                                try
925
                                                                {
926
                                                                    if (control.fontConfig.Count == 4)
927
                                                                    {
928
                                                                        fontsize = Convert.ToDouble(control.fontConfig[3]);
929
                                                                    }
930

    
931
                                                                    //강인구 수정(2018.04.17)
932
                                                                    var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
933

    
934
                                                                    FontStyle fontStyle = FontStyles.Normal;
935
                                                                    if (FontStyles.Italic == TextStyle)
936
                                                                    {
937
                                                                        fontStyle = FontStyles.Italic;
938
                                                                    }
939

    
940
                                                                    FontWeight fontWeight = FontWeights.Black;
941

    
942
                                                                    var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
943
                                                                    if (FontWeights.Bold == TextWeight)
944
                                                                    {
945
                                                                        fontWeight = FontWeights.Bold;
946
                                                                    }
947

    
948
                                                                    TextDecorationCollection decoration = TextDecorations.Baseline;
949
                                                                    if (control.fontConfig.Count == 5)
950
                                                                    {
951
                                                                        decoration = TextDecorations.Underline;
952
                                                                    }
953

    
954
                                                                    if (control.isTrans)
955
                                                                    {
956
                                                                        var border = control.GetBorderRectangle(tempEndPoint, scaleWidth, scaleHeight);
957
                                                                        Controls_PDF.DrawSet_Text.DrawString_ArrowText(border,
958
                                                                        newStartPoint, tempMidPoint, ConnectionPoint, control.isFixed,
959
                                                                        LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
960
                                                                    }
961
                                                                    else
962
                                                                    {
963
                                                                        if (control.isFixed)
964
                                                                        {
965
                                                                            var testP = new Point(0, 0);
966
                                                                            if (control.isFixed)
967
                                                                            {
968
                                                                                if (Connections[1] == ConnectionPoint)
969
                                                                                {
970
                                                                                    testP = new Point(ConnectionPoint.X, ConnectionPoint.Y - 10);
971
                                                                                }
972
                                                                                else if (Connections[3] == ConnectionPoint)
973
                                                                                {
974
                                                                                    testP = new Point(ConnectionPoint.X, ConnectionPoint.Y + 10);
975
                                                                                }
976
                                                                                else if (Connections[0] == ConnectionPoint)
977
                                                                                {
978
                                                                                    testP = new Point(ConnectionPoint.X - 10, ConnectionPoint.Y);
979
                                                                                }
980
                                                                                else if (Connections[2] == ConnectionPoint)
981
                                                                                {
982
                                                                                    testP = new Point(ConnectionPoint.X + 10, ConnectionPoint.Y);
983
                                                                                }
984
                                                                            }
985

    
986
                                                                            var border = control.GetBorderRectangle(tempEndPoint, scaleWidth, scaleHeight);
987
                                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(border,
988
                                                                                tempStartPoint, testP, ConnectionPoint, control.isFixed,
989
                                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
990
                                                                            FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
991
                                                                        }
992
                                                                        else
993
                                                                        {
994
                                                                            var border = control.GetBorderRectangle(tempEndPoint, scaleWidth, scaleHeight);
995
                                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(border,
996
                                                                                newStartPoint, tempMidPoint, ConnectionPoint, control.isFixed,
997
                                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
998
                                                                        }
999
                                                                    }
1000
                                                                }
1001
                                                                catch (Exception ex)
1002
                                                                {
1003
                                                                    throw ex;
1004
                                                                }
1005
                                                            }
1006
                                                            break;
1007
                                                        #endregion
1008
                                                        #region SignControl
1009
                                                        case "SignControl":
1010
                                                            using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1011
                                                            {
1012

    
1013
                                                                double Angle = control.Angle;
1014
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
1015
                                                                Point TopRightPoint = GetPdfPointSystem(control.TR);
1016
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
1017
                                                                Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1018
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1019
                                                                double Opacity = control.Opac;
1020
                                                                string UserNumber = control.UserNumber;
1021
                                                                Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1022
                                                            }
1023
                                                            break;
1024
                                                        #endregion
1025
                                                        #region MyRegion
1026
                                                        case "DateControl":
1027
                                                            using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1028
                                                            {
1029
                                                                string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1030
                                                                string Text = control.Text;
1031
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
1032
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
1033
                                                                List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1034
                                                                System.Drawing.Color FontColor = _SetColor;
1035
                                                                double Angle = control.Angle;
1036
                                                                double Opacity = control.Opac;
1037
                                                                Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1038
                                                            }
1039
                                                            break;
1040
                                                        #endregion
1041
                                                        #region SymControlN (APPROVED)
1042
                                                        case "SymControlN":
1043
                                                            using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1044
                                                            {
1045
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
1046
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
1047
                                                                List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1048
                                                                System.Drawing.Color FontColor = _SetColor;
1049
                                                                double Angle = control.Angle;
1050
                                                                double Opacity = control.Opac;
1051

    
1052
                                                                var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1053

    
1054
                                                                if (stamp.Count() > 0)
1055
                                                                {
1056
                                                                    var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1057

    
1058
                                                                    var Contents = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP_CONTENTS");
1059

    
1060
                                                                    if (Contents?.Count() > 0)
1061
                                                                    {
1062
                                                                        foreach (var content in Contents)
1063
                                                                        {
1064
                                                                            xamldata = xamldata.Replace(content.PROPERTY, System.Security.SecurityElement.Escape(content.VALUE));
1065
                                                                        }
1066
                                                                    }
1067

    
1068
                                                                    Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1069
                                                                }
1070

    
1071
                                                                string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1072

    
1073
                                                            }
1074
                                                            break;
1075
                                                        case "SymControl":
1076
                                                            using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1077
                                                            {
1078
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
1079
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
1080
                                                                List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1081
                                                                System.Drawing.Color FontColor = _SetColor;
1082
                                                                double Angle = control.Angle;
1083
                                                                double Opacity = control.Opac;
1084

    
1085
                                                                string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1086
                                                                Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1087
                                                            }
1088
                                                            break;
1089
                                                        #endregion
1090
                                                        #region Image
1091
                                                        case "ImgControl":
1092
                                                            using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1093
                                                            {
1094
                                                                double Angle = control.Angle;
1095
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
1096
                                                                Point TopRightPoint = GetPdfPointSystem(control.TR);
1097
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
1098
                                                                Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1099
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1100
                                                                double Opacity = control.Opac;
1101
                                                                string FilePath = control.ImagePath;
1102
                                                                //Uri uri = new Uri(s.ImagePath);
1103

    
1104
                                                                Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1105
                                                            }
1106
                                                            break;
1107
                                                        #endregion
1108
                                                        default:
1109
                                                            StatusChange($"{ControlT.Name} Not Support", 0);
1110
                                                            break;
1111
                                                    }
1112

    
1113
                                                }
1114
                                                catch (Exception ex)
1115
                                                {
1116
                                                    StatusChange($"markupItem : {ControlT.Name}" + ex.ToString(), 0);
1117
                                                }
1118
                                                finally
1119
                                                {
1120
                                                }
1121
                                            }
1122
                                        }
1123
                                    }
1124
                                }
1125

    
1126
                                if (StatusChanged != null)
1127
                                {
1128
                                    StatusChanged(this, new StatusChangedEventArgs { CurrentPage = lastPageNo, Message = "" });
1129
                                }
1130
                                //PdfFileSpecification pfs = PdfFileSpecification.FileEmbedded(pdfStamper.Writer, @"C:\Users\kts\Documents\업무\CARS\엑셀양식\F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", "F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", null);
1131
                                //pdfStamper.AddFileAttachment("F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", pfs);
1132

    
1133
                                pdfStamper.Outlines = root;
1134
                                pdfStamper.Close();
1135
                                pdfReader.Close();
1136
                            }
1137
                        }
1138
                    }
1139
                    #endregion
1140
                }
1141

    
1142
                if (tempFileInfo.Exists)
1143
                {
1144
#if !DEBUG
1145
                    tempFileInfo.Delete();
1146
#endif
1147
                }
1148

    
1149
                if (File.Exists(pdfFilePath))
1150
                {
1151
                    string destfilepath = null;
1152
                    try
1153
                    {
1154
                        FinalPDFPath = new FileInfo(pdfFilePath);
1155

    
1156
                        /// 정리 필요함. DB로 변경
1157
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1158

    
1159
                        if(!string.IsNullOrEmpty(pdfmovepath))
1160
                        {
1161
                            _FinalPDFStorgeLocal = pdfmovepath;
1162
                        }
1163

    
1164
                        destfilepath = Path.Combine(_FinalPDFStorgeLocal, FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1165

    
1166
                        if (File.Exists(destfilepath))
1167
                            File.Delete(destfilepath);
1168

    
1169
                        File.Move(FinalPDFPath.FullName, destfilepath);
1170
                        FinalPDFPath = new FileInfo(destfilepath);
1171
                        File.Delete(pdfFilePath);
1172
                    }
1173
                    catch (Exception ex)
1174
                    {
1175
                        SetNotice(finaldata.ID, $"File move error - Source File : {FinalPDFPath.FullName} dest File : {destfilepath}" + ex.ToString());
1176
                    }
1177

    
1178
                    return true;
1179
                }
1180
            }
1181
            catch (Exception ex)
1182
            {
1183
                SetNotice(finaldata.ID, "SetStempinPDF error: " + ex.ToString());
1184
            }
1185
            return false;
1186
        }
1187

    
1188
        /// <summary>
1189
        /// kcom의 화살표방향과 틀려 추가함
1190
        /// </summary>
1191
        /// <param name="PageAngle"></param>
1192
        /// <param name="endP"></param>
1193
        /// <param name="ps">box Points</param>
1194
        /// <param name="IsFixed"></param>
1195
        /// <returns></returns>
1196
        private Point GetArrowTextControlTestPoint(double PageAngle,Point endP,List<Point> ps,bool IsFixed)
1197
        {
1198
            Point testP = endP;
1199

    
1200
            try
1201
            {
1202
                switch (Math.Abs(PageAngle).ToString())
1203
                {
1204
                    case "90":
1205
                        testP = new Point(endP.X + 50, endP.Y);
1206
                        break;
1207
                    case "270":
1208
                        testP = new Point(endP.X - 50, endP.Y);
1209
                        break;
1210
                }
1211

    
1212
                //20180910 LJY 각도에 따라.
1213
                switch (Math.Abs(PageAngle).ToString())
1214
                {
1215
                    case "90":
1216
                        if (IsFixed)
1217
                        {
1218
                            if (ps[0] == endP) //상단
1219
                            {
1220
                                testP = new Point(endP.X, endP.Y + 50);
1221
                                //System.Diagnostics.Debug.WriteLine("상단"+ testP);
1222
                            }
1223
                            else if (ps[1] == endP) //하단
1224
                            {
1225
                                testP = new Point(endP.X, endP.Y - 50);
1226
                                //System.Diagnostics.Debug.WriteLine("하단"+ testP);
1227
                            }
1228
                            else if (ps[2] == endP) //좌단
1229
                            {
1230
                                testP = new Point(endP.X - 50, endP.Y);
1231
                                //System.Diagnostics.Debug.WriteLine("좌단"+ testP);
1232
                            }
1233
                            else if (ps[3] == endP) //우단
1234
                            {
1235
                                testP = new Point(endP.X + 50, endP.Y);
1236
                                //System.Diagnostics.Debug.WriteLine("우단"+ testP);
1237
                            }
1238
                        }
1239
                        break;
1240
                    case "270":
1241
                        if (IsFixed)
1242
                        {
1243
                            if (ps[0] == endP) //상단
1244
                            {
1245
                                testP = new Point(endP.X, endP.Y - 50);
1246
                                //System.Diagnostics.Debug.WriteLine("상단" + testP);
1247
                            }
1248
                            else if (ps[1] == endP) //하단
1249
                            {
1250
                                testP = new Point(endP.X, endP.Y + 50);
1251
                                //System.Diagnostics.Debug.WriteLine("하단" + testP);
1252
                            }
1253
                            else if (ps[2] == endP) //좌단
1254
                            {
1255
                                testP = new Point(endP.X + 50, endP.Y);
1256
                                //System.Diagnostics.Debug.WriteLine("좌단" + testP);
1257
                            }
1258
                            else if (ps[3] == endP) //우단
1259
                            {
1260
                                testP = new Point(endP.X - 50, endP.Y);
1261
                                //System.Diagnostics.Debug.WriteLine("우단" + testP);
1262
                            }
1263
                        }
1264
                        break;
1265
                    default:
1266
                        if (IsFixed)
1267
                        {
1268

    
1269
                            if (ps[0] == endP) //상단
1270
                            {
1271
                                testP = new Point(endP.X, endP.Y - 50);
1272
                                //System.Diagnostics.Debug.WriteLine("상단");
1273
                            }
1274
                            else if (ps[1] == endP) //하단
1275
                            {
1276
                                testP = new Point(endP.X, endP.Y + 50);
1277
                                //System.Diagnostics.Debug.WriteLine("하단");
1278
                            }
1279
                            else if (ps[2] == endP) //좌단
1280
                            {
1281
                                testP = new Point(endP.X - 50, endP.Y);
1282
                                //System.Diagnostics.Debug.WriteLine("좌단");
1283
                            }
1284
                            else if (ps[3] == endP) //우단
1285
                            {
1286
                                testP = new Point(endP.X + 50, endP.Y);
1287
                                //System.Diagnostics.Debug.WriteLine("우단");
1288
                            }
1289
                        }
1290
                        break;
1291
                }
1292

    
1293
            }
1294
            catch (Exception)
1295
            {
1296
            }
1297

    
1298
            return testP;
1299
        }
1300

    
1301
        private Point Test(Rect rect,Point point)
1302
        {
1303
            Point result = new Point();
1304

    
1305
            Point newPoint = new Point();
1306

    
1307
            double oldNear = 0;
1308
            double newNear = 0;
1309

    
1310
            oldNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.TopRight, out result);
1311

    
1312
            newNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.BottomLeft, out newPoint);
1313

    
1314
            if (newNear < oldNear)
1315
            {
1316
                oldNear = newNear;
1317
                result = newPoint;
1318
            }
1319

    
1320
            newNear = MathSet.GetShortestDistance(point, rect.TopRight, rect.BottomRight, out newPoint);
1321

    
1322
            if (newNear < oldNear)
1323
            {
1324
                oldNear = newNear;
1325
                result = newPoint;
1326
            }
1327

    
1328

    
1329
            newNear = MathSet.GetShortestDistance(point, rect.BottomLeft, rect.BottomRight, out newPoint);
1330

    
1331
            if (newNear < oldNear)
1332
            {
1333
                oldNear = newNear;
1334
                result = newPoint;
1335
            }
1336

    
1337
            return result;
1338
        }
1339

    
1340
        private void DrawMultiArrowLine(S_ArrowControl_Multi control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor)
1341
        {
1342
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1343
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1344
            Point MidPoint = GetPdfPointSystem(control.MidPoint);
1345
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1346
            DoubleCollection DashSize = control.DashSize;
1347
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1348
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()), scaleWidth);
1349

    
1350
            double Opacity = control.Opac;
1351

    
1352
            if (EndPoint == MidPoint)
1353
            {
1354
                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1355
            }
1356
            else
1357
            {
1358
                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, setColor, Opacity);
1359
            }
1360

    
1361
            Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, setColor, Opacity);
1362

    
1363
        }
1364

    
1365
        private void DrawLine(S_LineControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor)
1366
        {
1367
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1368
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1369
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1370
            DoubleCollection DashSize = control.DashSize;
1371
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1372

    
1373
            var Opacity = control.Opac;
1374
            string UserID = control.UserID;
1375
            double Interval = control.Interval;
1376
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()), scaleWidth);
1377
            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, setColor, Opacity);
1378
            switch (control.LineStyleSet)
1379
            {
1380
                case LineStyleSet.ArrowLine:
1381
                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1382
                    break;
1383
                case LineStyleSet.CancelLine:
1384
                    {
1385
                        var x = Math.Abs((Math.Abs(control.StartPoint.X) - Math.Abs(control.EndPoint.X)));
1386
                        var y = Math.Abs((Math.Abs(control.StartPoint.Y) - Math.Abs(control.EndPoint.Y)));
1387

    
1388
                        Point newStartPoint = new Point();
1389
                        Point newEndPoint = new Point();
1390

    
1391
                        if (x > y)
1392
                        {
1393
                            newStartPoint = new Point(control.StartPoint.X, control.StartPoint.Y + control.Interval);
1394
                            newEndPoint = new Point(control.EndPoint.X, control.EndPoint.Y + control.Interval);
1395
                        }
1396
                        else
1397
                        {
1398
                            newStartPoint = new Point(control.StartPoint.X + control.Interval, control.StartPoint.Y);
1399
                            newEndPoint = new Point(control.EndPoint.X + control.Interval, control.EndPoint.Y);
1400
                        }
1401

    
1402
                        newStartPoint = GetPdfPointSystem(newStartPoint);
1403
                        newEndPoint = GetPdfPointSystem(newEndPoint);
1404

    
1405
                        Controls_PDF.DrawSet_Line.DrawLine(newStartPoint, newEndPoint, LineSize, contentByte, DashSize, setColor, Opacity);
1406
                    }
1407
                    break;
1408
                case LineStyleSet.TwinLine:
1409
                    {
1410
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1411
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1412
                    }
1413
                    break;
1414
                case LineStyleSet.DimLine:
1415
                    {
1416
                        Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1417
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1418
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1419
                    }
1420
                    break;
1421
                default:
1422
                    break;
1423
            }
1424

    
1425
        }
1426

    
1427
        /// <summary>
1428
        /// 텍스트와 보더를 그립니다.
1429
        /// </summary>
1430
        /// <param name="control"></param>
1431
        /// <param name="contentByte"></param>
1432
        /// <param name="delimiterChars"></param>
1433
        /// <param name="delimiterChars2"></param>
1434
        /// <param name="setColor"></param>
1435
        private void DrawTextBox(S_TextControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor)
1436
        {
1437
            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1438
            string Text = control.Text;
1439

    
1440
            bool isUnderline = false;
1441
            control.BoxW -= scaleWidth;
1442
            control.BoxH -= scaleHeight;
1443
            System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
1444
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1445
            Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
1446

    
1447
            var rect = control.GetBorderRectangle(StartPoint, scaleWidth, scaleHeight);
1448

    
1449
            List<Point> pointSet = new List<Point>();
1450
            pointSet.Add(StartPoint);
1451
            pointSet.Add(EndPoint);
1452

    
1453
            PaintSet paint = PaintSet.None;
1454
            switch (control.paintMethod)
1455
            {
1456
                case 1:
1457
                    {
1458
                        paint = PaintSet.Fill;
1459
                    }
1460
                    break;
1461
                case 2:
1462
                    {
1463
                        paint = PaintSet.Hatch;
1464
                    }
1465
                    break;
1466
                default:
1467
                    break;
1468
            }
1469
            if (control.isHighLight) paint |= PaintSet.Highlight;
1470

    
1471
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()), scaleWidth);
1472
            double TextSize = Convert.ToDouble(data2[1]);
1473
            System.Drawing.Color FontColor = setColor;
1474
            double Angle = control.Angle;
1475
            double Opacity = control.Opac;
1476
            FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
1477
            var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1478

    
1479
            FontStyle fontStyle = FontStyles.Normal;
1480
            if (FontStyles.Italic == TextStyle)
1481
            {
1482
                fontStyle = FontStyles.Italic;
1483
            }
1484

    
1485
            FontWeight fontWeight = FontWeights.Black;
1486

    
1487
            var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1488
            //강인구 수정(2018.04.17)
1489
            if (FontWeights.Bold == TextWeight)
1490
            {
1491
                fontWeight = FontWeights.Bold;
1492
            }
1493

    
1494
            TextDecorationCollection decoration = TextDecorations.Baseline;
1495
            if (control.fontConfig.Count == 4)
1496
            {
1497
                decoration = TextDecorations.Underline;
1498
            }
1499

    
1500
            Controls_PDF.DrawSet_Text.DrawString(rect.TopLeft, rect.BottomRight, LineSize, contentByte, setColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1501
        }
1502

    
1503

    
1504
        ~MarkupToPDF()
1505
        {
1506
            this.Dispose(false);
1507
        }
1508

    
1509
        private bool disposed;
1510

    
1511
        public void Dispose()
1512
        {
1513
            this.Dispose(true);
1514
            GC.SuppressFinalize(this);
1515
        }
1516

    
1517
        protected virtual void Dispose(bool disposing)
1518
        {
1519
            if (this.disposed) return;
1520
            if (disposing)
1521
            {
1522
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1523
            }
1524
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1525
            this.disposed = true;
1526
        }
1527

    
1528
#endregion
1529
    }
1530
}
클립보드 이미지 추가 (최대 크기: 500 MB)