프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 24c5e56c

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
145
        #endregion
146

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

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

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

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

    
170
                throw;
171
            }
172

    
173
            return result;
174

    
175
        }
176

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

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

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

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

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

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

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

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

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

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

    
253
            return result;
254
        }
255

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

    
263

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

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

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

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

    
296

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
444
            try
445
            {
446

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

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

    
456
                        SetStampInPDF(FinalItem, TestFile, MarkupInfoItem);
457

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

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

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

    
490
                PdfReader pdfReader = new PdfReader(tempFileInfo);
491

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

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

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

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

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

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

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

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

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

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

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

    
574
                if (!Directory.Exists(_FinalPDFStorgeLocal))
575
                {
576
                    Directory.CreateDirectory(_FinalPDFStorgeLocal);
577
                }
578
                string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name);
579
                using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
580
                {
581
                    memberlist = cIEntities.MEMBER.ToList();
582
                }
583
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
584
                {
585
                    FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault();
586

    
587
                    #region 코멘트 적용 + 커버시트
588
                    using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) //
589
                    {
590
                        StatusChange("comment Cover",0);
591

    
592
                        PdfReader pdfReader = new PdfReader(pdfStream);
593
                        //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
594
                        Dictionary<string, object> bookmark;
595
                        List<Dictionary<string, object>> outlines;
596
                        outlines = new List<Dictionary<string, object>>();
597
                        List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
598

    
599
                        var dic = new Dictionary<string, object>();
600
                        foreach (var data in MarkupDataSet)
601
                        {
602
                            StatusChange("MarkupDataSet", 0);
603

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

    
606
                            var member = memberlist.Where(u => u.ID == userid).FirstOrDefault();
607
                            string username = member.NAME;
608
                            string userdept = member.DEPARTMENT;
609
                            bookmark = new Dictionary<string, object>();
610
                            bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
611
                            bookmark.Add("Page", data.PAGENUMBER + " Fit");
612
                            bookmark.Add("Action", "GoTo");
613
                            bookmark.Add("Kids", outlines);
614
                            root.Add(bookmark);
615
                        }
616

    
617

    
618
                        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
619
                        {
620
                            AcroFields pdfFormFields = pdfStamper.AcroFields;
621
                            pdfFormFields.GenerateAppearances = true;
622

    
623
                            var _SetColor = new SolidColorBrush(Colors.Red);
624

    
625
                            string[] delimiterChars = { "|DZ|" };
626
                            string[] delimiterChars2 = { "|" };
627

    
628
                            //pdfStamper.FormFlattening = true; //이미 선처리 작업함
629
                            pdfStamper.SetFullCompression();
630
                            _SetColor = new SolidColorBrush(Colors.Red);
631

    
632
                            foreach (var markupItem in MarkupDataSet)
633
                            {
634
                                pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER);
635
                                var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER).FirstOrDefault();
636

    
637
                                mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER);
638
                                var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER);                                
639

    
640
                                /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
641
                                if (cropBox != null && 
642
                                    (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
643
                                {
644
                                    PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
645

    
646
                                    PdfArray oNewMediaBox = new PdfArray();
647
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Left));
648
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Top));
649
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Right));
650
                                    oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
651
                                    dict.Put(PdfName.MEDIABOX, oNewMediaBox);
652

    
653
                                    pdfSize = cropBox; 
654
                                }
655
                                scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
656
                                scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
657

    
658
                                pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
659
                                _entity.SaveChanges();
660

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

    
663
                                PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
664

    
665

    
666
                                foreach (var data in markedData)
667
                                {
668
                                    var item = JsonSerializerHelper.UnCompressString(data);
669
                                    var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
670

    
671
                                    try
672
                                    {
673
                                        switch (ControlT.Name)
674
                                        {
675
                                            #region LINE
676
                                            case "LineControl":
677
                                                {
678
                                                    using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
679
                                                    {
680
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
681
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
682
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
683
                                                        DoubleCollection DashSize = control.DashSize;
684
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
685

    
686
                                                        var Opacity = control.Opac;
687
                                                        string UserID = control.UserID;
688
                                                        double Interval = control.Interval;
689
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
690
                                                        Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, _SetColor, Opacity);
691
                                                        switch (control.LineStyleSet)
692
                                                        {
693
                                                            case LineStyleSet.ArrowLine:
694
                                                                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
695
                                                                break;
696
                                                            case LineStyleSet.CancelLine:
697
                                                                {
698
                                                                    var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X)));
699
                                                                    var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y)));
700

    
701
                                                                    if (x > y)
702
                                                                    {
703
                                                                        StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0));
704
                                                                        EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0));
705
                                                                        Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, Opacity);
706
                                                                    }
707
                                                                }
708
                                                                break;
709
                                                            case LineStyleSet.TwinLine:
710
                                                                {
711
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
712
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
713
                                                                }
714
                                                                break;
715
                                                            case LineStyleSet.DimLine:
716
                                                                {
717
                                                                    Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
718
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
719
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
720
                                                                }
721
                                                                break;
722
                                                            default:
723
                                                                break;
724
                                                        }
725

    
726

    
727
                                                    }
728
                                                }
729
                                                break;
730
                                            #endregion
731
                                            #region ArrowControlMulti
732
                                            case "ArrowControl_Multi":
733
                                                {
734
                                                    using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
735
                                                    {
736
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
737
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
738
                                                        Point MidPoint = GetPdfPointSystem(control.MidPoint);
739
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
740
                                                        DoubleCollection DashSize = control.DashSize;
741
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
742
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
743

    
744
                                                        double Opacity = control.Opac;
745

    
746
                                                        if (EndPoint == MidPoint)
747
                                                        {
748
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity);
749
                                                        }
750
                                                        else
751
                                                        {
752
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
753
                                                        }
754

    
755
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
756

    
757
                                                    }
758
                                                }
759
                                                break;
760
                                            #endregion
761
                                            #region PolyControl
762
                                            case "PolygonControl":
763
                                                using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
764
                                                {
765
                                                    string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
766
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
767
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
768
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
769
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
770
                                                    double Opacity = control.Opac;
771
                                                    DoubleCollection DashSize = control.DashSize;
772

    
773
                                                    Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
774
                                                }
775
                                                break;
776
                                            #endregion
777
                                            #region ArcControl or ArrowArcControl
778
                                            case "ArcControl":
779
                                            case "ArrowArcControl":
780
                                                {
781
                                                    using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
782
                                                    {
783
                                                        string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
784
                                                        Point StartPoint = GetPdfPointSystem(control.StartPoint);
785
                                                        Point EndPoint = GetPdfPointSystem(control.EndPoint);
786
                                                        Point MidPoint = GetPdfPointSystem(control.MidPoint);
787
                                                        DoubleCollection DashSize = control.DashSize;
788
                                                        List<Point> PointSet = GetPdfPointSystem(control.PointSet);
789

    
790
                                                        var Opacity = control.Opac;
791
                                                        string UserID = control.UserID;
792
                                                        double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
793
                                                        bool IsTransOn = control.IsTransOn;
794

    
795
                                                        if (control.IsTransOn)
796
                                                        {
797
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
798
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
799
                                                        }
800
                                                        else
801
                                                        {
802
                                                            Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity);
803
                                                        }
804

    
805
                                                        if (ControlT.Name == "ArrowArcControl")
806
                                                        {
807
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
808
                                                            Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
809
                                                        }
810
                                                    }
811
                                                }
812
                                                break;
813
                                            #endregion
814
                                            #region RectangleControl
815
                                            case "RectangleControl":
816
                                                using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
817
                                                {
818
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
819
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
820
                                                    var PaintStyle = control.PaintState;
821
                                                    double Angle = control.Angle;
822
                                                    DoubleCollection DashSize = control.DashSize;
823
                                                    double Opacity = control.Opac;
824
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
825

    
826
                                                    Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
827
                                                }
828
                                                break;
829
                                            #endregion
830
                                            #region TriControl
831
                                            case "TriControl":
832
                                                using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
833
                                                {
834
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
835
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
836
                                                    var PaintStyle = control.Paint;
837
                                                    double Angle = control.Angle;
838
                                                    //StrokeColor = _SetColor, //색상은 레드
839
                                                    DoubleCollection DashSize = control.DashSize;
840
                                                    double Opacity = control.Opac;
841
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
842

    
843
                                                    Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
844
                                                }
845
                                                break;
846
                                            #endregion
847
                                            #region CircleControl
848
                                            case "CircleControl":
849
                                                using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
850
                                                {
851
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
852
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
853
                                                    var StartPoint = GetPdfPointSystem(control.StartPoint);
854
                                                    var EndPoint = GetPdfPointSystem(control.EndPoint);
855
                                                    var PaintStyle = control.PaintState;
856
                                                    double Angle = control.Angle;
857
                                                    DoubleCollection DashSize = control.DashSize;
858
                                                    double Opacity = control.Opac;
859
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
860
                                                    Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
861

    
862
                                                }
863
                                                break;
864
                                            #endregion
865
                                            #region RectCloudControl
866
                                            case "RectCloudControl":
867
                                                using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
868
                                                {
869
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
870
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
871
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
872
                                                    double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
873

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

    
876
                                                    var PaintStyle = control.PaintState;
877
                                                    double Opacity = control.Opac;
878
                                                    DoubleCollection DashSize = control.DashSize;
879

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

    
883
                                                    double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
884
                                                    bool reverse = (area < 0);
885
                                                    if (PaintStyle == PaintSet.None)
886
                                                    {
887
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
888
                                                    }
889
                                                    else
890
                                                    {
891
                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
892
                                                    }
893
                                                }
894
                                                break;
895
                                            #endregion
896
                                            #region CloudControl
897
                                            case "CloudControl":
898
                                                using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
899
                                                {
900
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
901
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
902
                                                    double Toler = control.Toler;
903
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
904
                                                    double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
905
                                                    var PaintStyle = control.PaintState;
906
                                                    double Opacity = control.Opac;
907
                                                    bool isTransOn = control.IsTrans;
908
                                                    bool isChain = control.IsChain;
909

    
910
                                                    DoubleCollection DashSize = control.DashSize;
911

    
912
                                                    if (isChain)
913
                                                    {
914
                                                        Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
915
                                                    }
916
                                                    else
917
                                                    {
918
                                                        if (isTransOn)
919
                                                        {
920
                                                            double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
921
                                                            bool reverse = (area < 0);
922

    
923
                                                            if (PaintStyle == PaintSet.None)
924
                                                            {
925
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
926
                                                            }
927
                                                            else
928
                                                            {
929
                                                                Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
930
                                                            }
931
                                                        }
932
                                                        else
933
                                                        {
934
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
935
                                                        }
936
                                                    }
937
                                                }
938
                                                break;
939
                                            #endregion
940
                                            #region TEXT
941
                                            case "TextControl":
942
                                                using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
943
                                                {
944
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
945
                                                    string Text = control.Text;
946

    
947
                                                    bool isUnderline = false;
948
                                                    control.BoxW -= scaleWidth;
949
                                                    control.BoxH -= scaleHeight;
950
                                                    System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
951
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
952
                                                    Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
953

    
954
                                                    List<Point> pointSet = new List<Point>();
955
                                                    pointSet.Add(StartPoint);
956
                                                    pointSet.Add(EndPoint);
957

    
958
                                                    PaintSet paint = PaintSet.None;
959
                                                    switch (control.paintMethod)
960
                                                    {
961
                                                        case 1:
962
                                                            {
963
                                                                paint = PaintSet.Fill;
964
                                                            }
965
                                                            break;
966
                                                        case 2:
967
                                                            {
968
                                                                paint = PaintSet.Hatch;
969
                                                            }
970
                                                            break;
971
                                                        default:
972
                                                            break;
973
                                                    }
974
                                                    if (control.isHighLight) paint |= PaintSet.Highlight;
975

    
976
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
977
                                                    double TextSize = Convert.ToDouble(data2[1]);
978
                                                    SolidColorBrush FontColor = _SetColor;
979
                                                    double Angle = control.Angle;
980
                                                    double Opacity = control.Opac;
981
                                                    FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
982
                                                    var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
983
                                                    
984
                                                    FontStyle fontStyle = FontStyles.Normal;
985
                                                    if (FontStyles.Italic == TextStyle)
986
                                                    {
987
                                                        fontStyle = FontStyles.Italic;
988
                                                    }
989

    
990
                                                    FontWeight fontWeight = FontWeights.Black;
991

    
992
                                                    var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
993
                                                    //강인구 수정(2018.04.17)
994
                                                    if (FontWeights.Bold == TextWeight)
995
                                                    //if (FontWeights.ExtraBold == TextWeight)
996
                                                    {
997
                                                        fontWeight = FontWeights.Bold;
998
                                                    }
999

    
1000
                                                    TextDecorationCollection decoration = TextDecorations.Baseline;
1001
                                                    if (control.fontConfig.Count() == 4)
1002
                                                    {
1003
                                                        decoration = TextDecorations.Underline;
1004
                                                    }
1005

    
1006
                                                    Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, _SetColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1007
                                                }
1008
                                                break;
1009
                                            #endregion
1010
                                            #region ArrowTextControl
1011
                                            case "ArrowTextControl":
1012
                                                using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
1013
                                                {
1014
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1015
                                                    Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
1016
                                                    Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
1017
                                                    Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
1018
                                                    bool isUnderLine = false;
1019
                                                    string Text = "";
1020
                                                    double fontsize = 30;
1021

    
1022
                                                    System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
1023
                                                    Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight));
1024
                                                    List<Point> tempPoint = new List<Point>();
1025

    
1026
                                                    var tempRectMidPoint = MathSet.getRectMiddlePoint(rect);
1027

    
1028
                                                    tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y));
1029
                                                    tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top));
1030
                                                    tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y));
1031
                                                    tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom));
1032
                                                    double Angle = control.Angle;
1033
                                                    var newStartPoint = tempStartPoint;
1034
                                                    var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint);
1035
                                                    var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint);
1036

    
1037
                                                    double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1038
                                                    SolidColorBrush FontColor = _SetColor;
1039
                                                    bool isHighlight = control.isHighLight;
1040
                                                    double Opacity = control.Opac;
1041
                                                    PaintSet Paint = PaintSet.None;
1042

    
1043
                                                    switch (control.ArrowStyle)
1044
                                                    {
1045
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
1046
                                                            {
1047
                                                                Paint = PaintSet.None;
1048
                                                            }
1049
                                                            break;
1050
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
1051
                                                            {
1052
                                                                Paint = PaintSet.Hatch;
1053
                                                            }
1054
                                                            break;
1055
                                                        case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
1056
                                                            {
1057
                                                                Paint = PaintSet.Fill;
1058
                                                            }
1059
                                                            break;
1060
                                                        default:
1061
                                                            break;
1062
                                                    }
1063
                                                    if (control.isHighLight) Paint |= PaintSet.Highlight;
1064

    
1065
                                                    if (Paint == PaintSet.Hatch)
1066
                                                    {
1067
                                                        Text = control.ArrowText;
1068
                                                    }
1069
                                                    else
1070
                                                    {
1071
                                                        Text = control.ArrowText;
1072
                                                    }
1073

    
1074
                                                    try
1075
                                                    {
1076
                                                        if (control.fontConfig.Count == 4)
1077
                                                        {
1078
                                                            fontsize = Convert.ToDouble(control.fontConfig[3]);
1079
                                                        }
1080

    
1081
                                                        //강인구 수정(2018.04.17)
1082
                                                        var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1083

    
1084
                                                        FontStyle fontStyle = FontStyles.Normal;
1085
                                                        if (FontStyles.Italic == TextStyle)
1086
                                                        {
1087
                                                            fontStyle = FontStyles.Italic;
1088
                                                        }
1089

    
1090
                                                        FontWeight fontWeight = FontWeights.Black;
1091

    
1092
                                                        var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1093
                                                        if (FontWeights.Bold == TextWeight)
1094
                                                        {
1095
                                                            fontWeight = FontWeights.Bold;
1096
                                                        }
1097

    
1098
                                                        TextDecorationCollection decoration = TextDecorations.Baseline;
1099
                                                        if (control.fontConfig.Count() == 5)
1100
                                                        {
1101
                                                            decoration = TextDecorations.Underline;
1102
                                                        }
1103

    
1104
                                                        if (control.isTrans)
1105
                                                        {
1106
                                                            //인구 수정 Arrow Text Style적용 되도록 변경
1107
                                                            Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1108
                                                                newStartPoint, tempMidPoint, control.isFixed,
1109
                                                                LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1110
                                                        }
1111
                                                        else
1112
                                                        {
1113
                                                            if (control.isFixed)
1114
                                                            {
1115
                                                                var testP = new Point(0, 0);
1116
                                                                if (control.isFixed)
1117
                                                                {
1118
                                                                    if (tempPoint[1] == newEndPoint)
1119
                                                                    {
1120
                                                                        testP = new Point(newEndPoint.X, newEndPoint.Y - 10);
1121
                                                                    }
1122
                                                                    else if (tempPoint[3] == newEndPoint)
1123
                                                                    {
1124
                                                                        testP = new Point(newEndPoint.X, newEndPoint.Y + 10);
1125
                                                                    }
1126
                                                                    else if (tempPoint[0] == newEndPoint)
1127
                                                                    {
1128
                                                                        testP = new Point(newEndPoint.X - 10, newEndPoint.Y);
1129
                                                                    }
1130
                                                                    else if (tempPoint[2] == newEndPoint)
1131
                                                                    {
1132
                                                                        testP = new Point(newEndPoint.X + 10, newEndPoint.Y);
1133
                                                                    }
1134
                                                                }
1135
                                                                //인구 수정 Arrow Text Style적용 되도록 변경
1136
                                                                Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1137
                                                                    tempStartPoint, testP, control.isFixed ,
1138
                                                                    LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
1139
                                                                FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1140
                                                            }
1141
                                                            else
1142
                                                            {
1143
                                                                //인구 수정 Arrow Text Style적용 되도록 변경
1144
                                                                Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1145
                                                                    newStartPoint, tempMidPoint, control.isFixed,
1146
                                                                    LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1147
                                                            }
1148
                                                        }
1149
                                                    }
1150
                                                    catch (Exception ex)
1151
                                                    {
1152
                                                        throw ex;
1153
                                                    }
1154
                                                }
1155
                                                break;
1156
                                            #endregion
1157
                                            #region SignControl
1158
                                            case "SignControl":
1159
                                                using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1160
                                                {
1161

    
1162
                                                    double Angle = control.Angle;
1163
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1164
                                                    Point TopRightPoint = GetPdfPointSystem(control.TR);
1165
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1166
                                                    Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1167
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1168
                                                    double Opacity = control.Opac;
1169
                                                    string UserNumber = control.UserNumber;
1170
                                                    Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1171
                                                }
1172
                                                break;
1173
                                            #endregion
1174
                                            #region MyRegion
1175
                                            case "DateControl":
1176
                                                using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1177
                                                {
1178
                                                    string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1179
                                                    string Text = control.Text;
1180
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1181
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1182
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1183
                                                    SolidColorBrush FontColor = _SetColor;
1184
                                                    double Angle = control.Angle;
1185
                                                    double Opacity = control.Opac;
1186
                                                    Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1187
                                                }
1188
                                                break;
1189
                                            #endregion
1190
                                            #region SymControlN (APPROVED)
1191
                                            case "SymControlN":
1192
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1193
                                                {
1194
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1195
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1196
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1197
                                                    SolidColorBrush FontColor = _SetColor;
1198
                                                    double Angle = control.Angle;
1199
                                                    double Opacity = control.Opac;
1200

    
1201
                                                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1202

    
1203
                                                    if (stamp.Count() > 0)
1204
                                                    {
1205
                                                        var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1206

    
1207
                                                        Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1208
                                                    }
1209

    
1210
                                                    string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1211
                                                    
1212
                                                }
1213
                                                break;
1214
                                            case "SymControl":
1215
                                                using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1216
                                                {
1217
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1218
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1219
                                                    List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1220
                                                    SolidColorBrush FontColor = _SetColor;
1221
                                                    double Angle = control.Angle;
1222
                                                    double Opacity = control.Opac;
1223

    
1224
                                                    string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1225
                                                    Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1226
                                                }
1227
                                                break;
1228
                                            #endregion
1229
                                            #region Image
1230
                                            case "ImgControl":
1231
                                                using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1232
                                                {
1233
                                                    double Angle = control.Angle;
1234
                                                    Point StartPoint = GetPdfPointSystem(control.StartPoint);
1235
                                                    Point TopRightPoint = GetPdfPointSystem(control.TR);
1236
                                                    Point EndPoint = GetPdfPointSystem(control.EndPoint);
1237
                                                    Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1238
                                                    List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1239
                                                    double Opacity = control.Opac;
1240
                                                    string FilePath = control.ImagePath;
1241
                                                    //Uri uri = new Uri(s.ImagePath);
1242

    
1243
                                                    Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1244
                                                }
1245
                                                break;
1246
                                            #endregion
1247
                                            default:
1248
                                                StatusChange($"{ControlT.Name} Not Support", 0);
1249
                                                break;
1250
                                        }
1251
                                    }
1252
                                    catch (Exception ex)
1253
                                    {
1254
                                        StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1255
                                    }
1256
                                }
1257
                            }
1258
                            pdfStamper.Outlines = root;
1259
                            pdfStamper.Close();
1260
                            pdfReader.Close();
1261
                        }
1262
                    }
1263
                    #endregion
1264
                }
1265
                if (tempFileInfo.Exists)
1266
                {
1267
                    tempFileInfo.Delete();
1268
                }
1269

    
1270
                if (File.Exists(pdfFilePath))
1271
                {
1272
                    try
1273
                    {
1274
                        FinalPDFPath = new FileInfo(pdfFilePath);
1275

    
1276
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1277
                        string destfilepath = Path.Combine(pdfmovepath,FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1278
                        if (File.Exists(destfilepath))
1279
                            File.Delete(destfilepath);
1280
                        File.Move(FinalPDFPath.FullName, destfilepath);
1281
                        FinalPDFPath = new FileInfo(destfilepath);
1282
                        File.Delete(pdfFilePath);
1283
                    }
1284
                    catch (Exception ex)
1285
                    {
1286
                        SetNotice(finaldata.ID, "File move error: " + ex.ToString());
1287
                    }
1288

    
1289
                    return true;
1290
                }
1291
            }
1292
            catch (Exception ex)
1293
            {
1294
                throw ex;
1295
            }
1296
            return false;
1297
        }
1298
    
1299

    
1300
        ~MarkupToPDF()
1301
        {
1302
            this.Dispose(false);
1303
        }
1304

    
1305
        private bool disposed;
1306

    
1307
        public void Dispose()
1308
        {
1309
            this.Dispose(true);
1310
            GC.SuppressFinalize(this);
1311
        }
1312

    
1313
        protected virtual void Dispose(bool disposing)
1314
        {
1315
            if (this.disposed) return;
1316
            if (disposing)
1317
            {
1318
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1319
            }
1320
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1321
            this.disposed = true;
1322
        }
1323

    
1324
        #endregion
1325
    }
1326
}
클립보드 이미지 추가 (최대 크기: 500 MB)