프로젝트

일반

사용자정보

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

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

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

1 7ca218b3 KangIngu
using IFinalPDF;
2
using iTextSharp.text.pdf;
3
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5
using MarkupToPDF.Controls.Common;
6
using MarkupToPDF.Serialize.Core;
7
using MarkupToPDF.Serialize.S_Control;
8 c206d293 taeseongkim
using Markus.Fonts;
9 7ca218b3 KangIngu
using System;
10
using System.Collections.Generic;
11 7f01e35f ljiyeon
using System.Configuration;
12 7ca218b3 KangIngu
using System.IO;
13
using System.Linq;
14
using System.Net;
15 7f01e35f ljiyeon
using System.Runtime.InteropServices;
16 7ca218b3 KangIngu
using System.Text;
17 e05bed4e djkim
using System.Web;
18 7ca218b3 KangIngu
using System.Windows;
19
using System.Windows.Media;
20
21
namespace MarkupToPDF
22
{
23
    public class MarkupToPDF : IDisposable
24
    {
25 4b33593a taeseongkim
        public MarkupToPDF()
26
        {
27
        }
28 e77fc685 taeseongkim
29 7ca218b3 KangIngu
        #region 초기 데이터
30
        private static iTextSharp.text.Rectangle mediaBox;
31
        private FileInfo PdfFilePath = null;
32
        private FileInfo FinalPDFPath = null;
33
        private string _FinalPDFStorgeLocal = null;
34
        private string _FinalPDFStorgeRemote = null;
35
        private string OriginFileName = null;
36 8c3a888c djkim
        public FINAL_PDF FinalItem;
37
        public DOCINFO DocInfoItem = null;
38
        public List<DOCPAGE> DocPageItem = null;
39
        public MARKUP_INFO MarkupInfoItem = null;
40
        public List<MARKUP_DATA> MarkupDataSet = null;
41 7ca218b3 KangIngu
        //private string _PrintPDFStorgeLocal = null;
42
        //private string _PrintPDFStorgeRemote = null;
43
        public event EventHandler<MakeFinalErrorArgs> FinalMakeError;
44
        public event EventHandler<EndFinalEventArgs> EndFinal;
45 ab590000 taeseongkim
        public event EventHandler<StatusChangedEventArgs> StatusChanged;
46 7ca218b3 KangIngu
47
        private iTextSharp.text.Rectangle pdfSize { get; set; }
48
        private double pageW = 0;
49
        private double pageH = 0;
50
51
        //private const double zoomLevel = 3.0;
52
        private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음
53
        #endregion
54
55
        #region 메서드        
56
        public static bool IsLocalIPAddress(string host)
57
        {
58
            try
59
            {
60
                IPAddress[] hostIPs = Dns.GetHostAddresses(host);
61
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
62
63
                foreach (IPAddress hostIP in hostIPs)
64
                {
65
                    if (IPAddress.IsLoopback(hostIP)) return true;
66
67
                    foreach (IPAddress localIP in localIPs)
68
                    {
69
                        if (hostIP.Equals(localIP)) return true;
70
                    }
71
                }
72
            }
73
            catch { }
74
            return false;
75
        }
76
77 8c3a888c djkim
        private void SetNotice(string finalID, string message)
78 7ca218b3 KangIngu
        {
79
            if (FinalMakeError != null)
80
            {
81
                FinalMakeError(this, new MakeFinalErrorArgs { FinalID = finalID, Message = message });
82
            }
83
        }
84
85
        private string GetFileName(string hrefLink)
86
        {
87 e05bed4e djkim
            try
88
            {
89
                if (hrefLink.Contains("vpcs_doclib"))
90
                {
91
                    return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\"));
92
                }
93
                else
94
                {
95
                    Uri fileurl = new Uri(hrefLink);
96
                    int index = hrefLink.IndexOf("?");
97
                    string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName");
98
                    return filename;
99
                }
100
            }
101
            catch (Exception ex)
102
            {
103
                throw ex;
104
            }
105 7ca218b3 KangIngu
        }
106
107
        public Point GetPdfPointSystem(Point point)
108
        {
109 9dec2e0a humkyung
            /// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다.
110 9ced2402 djkim
            /// Rotation 90 일 경우 pdfsize box 와 media box 가 달라 다른 계산식 적용
111
            if (pdfSize.Rotation == 90)
112
            {
113
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom);
114
            }
115
            else
116
            {
117
                return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Height - (float)(point.Y / scaleHeight) + pdfSize.Bottom);
118
            }  
119 7ca218b3 KangIngu
        }
120
121 488ba687 humkyung
        public double GetPdfSize(double size)
122
        {
123
            return (size / scaleWidth);
124
        }
125
126 8c3a888c djkim
        public List<Point> GetPdfPointSystem(List<Point> point)
127 7ca218b3 KangIngu
        {
128
            List<Point> dummy = new List<Point>();
129
            foreach (var item in point)
130
            {
131
                dummy.Add(GetPdfPointSystem(item));
132
            }
133
            return dummy;
134
        }
135
136
        public double returnAngle(Point start, Point end)
137
        {
138
            double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y);
139
            //angle *= -1;
140
141
            angle += 90;
142
            //if (angle < 0)
143
            //{
144
            //    angle = angle + 360;
145
            //}
146
            return angle;
147
        }
148
149
        #endregion
150
151 c206d293 taeseongkim
        public bool AddStamp(string stampData)
152
        {
153
            bool result = false;
154
155
            try
156
            {
157
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
158
                {
159
                    var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
160
161
                    if(stamp.Count() > 0)
162
                    {
163
                        var xamldata = Serialize.Core.JsonSerializerHelper.CompressStamp(stampData);
164
165
                        stamp.First().VALUE = xamldata;
166
                        _entity.SaveChanges();
167
                        result = true;
168
                    }
169
                }
170
            }
171
            catch (Exception)
172
            {
173
174
                throw;
175
            }
176
177
            return result;
178
179
        }
180
181 077fb153 taeseongkim
        /// <summary>
182
        /// local에서 final 생성하는 경우 이 함수로 추가 후 실행
183
        /// </summary>
184
        /// <param name="finalpdf"></param>
185
        /// <returns></returns>
186
        public AddFinalPDFResult AddFinalPDF(string ProjectNo,string DocumentID,string UserID)
187
        {
188 c206d293 taeseongkim
            //var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS");
189
            //System.Diagnostics.Debug.WriteLine(list);
190
191 077fb153 taeseongkim
            AddFinalPDFResult result = new AddFinalPDFResult { Success = false };
192
193
            try
194
            {
195
                FINAL_PDF addItem = new FINAL_PDF{
196
                    ID = CommonLib.Guid.shortGuid(),
197
                    PROJECT_NO = ProjectNo,
198
                    DOCUMENT_ID = DocumentID,
199
                    CREATE_USER_ID = UserID,
200
                    CREATE_DATETIME = DateTime.Now,
201
                    STATUS = 4
202
                };
203
204
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString()))
205
                {
206
                    var docitems = _entity.DOCINFO.Where(x => x.PROJECT_NO == ProjectNo && x.DOCUMENT_ID == DocumentID);
207
208
                    if(docitems.Count() > 0)
209
                    {
210
                        addItem.DOCINFO_ID = docitems.First().ID;
211
                        result.Success = true;
212
                    }
213
                    else
214
                    {
215
                        result.Exception = "docInfo Not Found.";
216
                        result.Success = false;
217
                    }
218
219
                    var markupInfoItems = _entity.MARKUP_INFO.Where(x =>x.DOCINFO_ID == addItem.DOCINFO_ID);
220
221
                    if (markupInfoItems.Count() > 0)
222
                    {
223
                        addItem.MARKUPINFO_ID = markupInfoItems.First().ID;
224
                        result.Success = true;
225
                    }
226
                    else
227
                    {
228
                        result.Exception = "Markup Info Not Found.";
229
                        result.Success = false;
230
                    }
231
                }
232
233
                if (result.Success)
234
                {
235
                    using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
236
                    {
237
                        var finalList = _entity.FINAL_PDF.Where(final => final.ID == addItem.ID);
238
239
                        /// Insrt and Update
240
                        if (finalList.Count() == 0)
241
                        {
242
                            _entity.FINAL_PDF.AddObject(addItem);
243
                            _entity.SaveChanges();
244
245
                            result.FinalPDF = addItem;
246
                            result.Success = true;
247
                        }
248
                    }
249
                }
250
            }
251
            catch (Exception ex)
252
            {
253
                System.Diagnostics.Debug.WriteLine(ex);
254
                result.Success = false;
255
            }
256
257
            return result;
258
        }
259
260 7ca218b3 KangIngu
        #region 생성자 & 소멸자
261 cf1cc862 taeseongkim
        public void MakeFinalPDF(object _FinalPDF)
262 7ca218b3 KangIngu
        {
263 8c3a888c djkim
            DOCUMENT_ITEM documentItem;
264
            FINAL_PDF FinalPDF = (FINAL_PDF)_FinalPDF;
265 7ca218b3 KangIngu
            FinalItem = FinalPDF;
266
267
268
            string PdfFilePathRoot = null;
269
            string TestFile = System.IO.Path.GetTempFileName();
270
271
            #region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정
272 488ba687 humkyung
            try
273 7ca218b3 KangIngu
            {
274 8c3a888c djkim
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
275 7ca218b3 KangIngu
                {
276 8c3a888c djkim
                    var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO);
277
278
                    if (_properties.Count() > 0)
279 7ca218b3 KangIngu
                    {
280 077fb153 taeseongkim
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).Count() == 0)
281
                        {
282 cf1cc862 taeseongkim
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : TileSourcePath Not Found.");
283
                            return;
284 077fb153 taeseongkim
                        }
285
                        else
286 cf1cc862 taeseongkim
                        {
287 077fb153 taeseongkim
                            PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE;
288
                        }
289
290
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).Count() == 0)
291
                        {
292 cf1cc862 taeseongkim
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeLocal Not Found.");
293
                            return;
294 077fb153 taeseongkim
                        }
295
                        else
296
                        {
297
                            _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE;
298
                        }
299
300
301
                        if (_properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).Count() == 0)
302
                        {
303 cf1cc862 taeseongkim
                            SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : FinalPDFStorgeRemote Not Found.");
304
                            return;
305 077fb153 taeseongkim
                        }
306
                        else
307
                        {
308
                            _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE;
309
                        }
310 7ca218b3 KangIngu
                    }
311
                    else
312
                    {
313 cf1cc862 taeseongkim
                        SetNotice(FinalPDF.ID, $"Project {FinalPDF.PROJECT_NO} : Final PDF Properties Not Found.");
314
                        return;
315 7ca218b3 KangIngu
                    }
316 077fb153 taeseongkim
317 e0f00e26 djkim
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
318 077fb153 taeseongkim
319 8c3a888c djkim
                    if (finalList.Count() > 0)
320
                    {
321
                        finalList.FirstOrDefault().START_DATETIME = DateTime.Now;
322
                        finalList.FirstOrDefault().STATUS = (int)FinalStatus.Create;
323
                        _entity.SaveChanges();
324
                    }
325 e0f00e26 djkim
326 8c3a888c djkim
                }
327 7ca218b3 KangIngu
            }
328
            catch (Exception ex)
329
            {
330 cf1cc862 taeseongkim
                SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString());
331
                return;
332 7ca218b3 KangIngu
            }
333
            #endregion
334
335
            #region 문서 복사
336
            try
337
            {
338 8c3a888c djkim
                using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString()))
339 7ca218b3 KangIngu
                {
340 8c3a888c djkim
                    var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID);
341 7ca218b3 KangIngu
342 8c3a888c djkim
                    if (_DOCINFO.Count() > 0)
343 7ca218b3 KangIngu
                    {
344 b42dd24d taeseongkim
                        DocInfoItem = _DOCINFO.First();
345
346
                        DocPageItem = _entity.DOCPAGE.Where(x => x.DOCINFO_ID == DocInfoItem.ID).ToList();
347 7ca218b3 KangIngu
348
                        PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\"
349 a371522c humkyung
                                         + (FinalPDF.DOCUMENT_ID.All(char.IsDigit) ? (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() : FinalPDF.DOCUMENT_ID.Substring(0, 5))
350 7ca218b3 KangIngu
                                         + @"\" + FinalPDF.DOCUMENT_ID + @"\";
351
352 cf1cc862 taeseongkim
                        var infoItems = _entity.MARKUP_INFO.Where(x => x.DOCINFO_ID == DocInfoItem.ID && x.CONSOLIDATE == 1 && x.AVOID_CONSOLIDATE == 0 && x.PART_CONSOLIDATE == 0);
353 7ca218b3 KangIngu
354 b42dd24d taeseongkim
                        if (infoItems.Count() == 0)
355 7ca218b3 KangIngu
                        {
356
                            throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다");
357
                        }
358
                        else
359
                        {
360 b42dd24d taeseongkim
                            MarkupInfoItem = infoItems.First();
361
362
                            var markupInfoVerItems = _entity.MARKUP_INFO_VERSION.Where(x => x.MARKUPINFO_ID == MarkupInfoItem.ID).ToList();
363 cf1cc862 taeseongkim
364 b42dd24d taeseongkim
                            if (markupInfoVerItems.Count() > 0)
365 8c3a888c djkim
                            {
366 b42dd24d taeseongkim
                                var markupInfoVerItem = markupInfoVerItems.OrderByDescending(x => x.CREATE_DATE).First();
367
368 cf1cc862 taeseongkim
                                MarkupDataSet = _entity.MARKUP_DATA.Where(x => x.MARKUPINFO_VERSION_ID == markupInfoVerItem.ID).OrderBy(d => d.PAGENUMBER).ToList();
369 8c3a888c djkim
                            }
370
                            else
371 7ca218b3 KangIngu
                            {
372
                                throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다");
373 8c3a888c djkim
                            }
374 6c9fec59 djkim
                        }
375 7ca218b3 KangIngu
376 645f6f94 djkim
                        documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID && data.PROJECT_NO == FinalPDF.PROJECT_NO).FirstOrDefault();
377 e0f00e26 djkim
                        if (documentItem == null)
378 6c9fec59 djkim
                        {
379 e0f00e26 djkim
                            throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요");
380
                        }
381 8c3a888c djkim
382 e0f00e26 djkim
                        var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 
383 8c3a888c djkim
384 e0f00e26 djkim
                        #region 파일 체크
385
                        if (_files.Count() == 1)
386
                        {
387 ff01c725 humkyung
                            /// 문서 관리 시스템의 원본 PDF 파일과 비교 --> 삭제될 예정
388
                            //if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()))
389
                            //{
390 cf1cc862 taeseongkim
                            OriginFileName = _files.First().Name;
391
                            PdfFilePath = _files.First().CopyTo(TestFile, true);
392
                            StatusChange($"Copy File  file Count = 1 : {PdfFilePath}", 0);
393 ff01c725 humkyung
                            //}
394
                            //else
395
                            //{
396
                            //    throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower());
397
                            //}
398 e0f00e26 djkim
                        }
399
                        else if (_files.Count() > 1)
400
                        {
401
                            var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault();
402 6c9fec59 djkim
403 e0f00e26 djkim
                            if (originalFile == null)
404 8c3a888c djkim
                            {
405 e0f00e26 djkim
                                throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다");
406 8c3a888c djkim
                            }
407 e0f00e26 djkim
                            else
408 8c3a888c djkim
                            {
409 e0f00e26 djkim
                                OriginFileName = originalFile.Name;
410
                                PdfFilePath = originalFile.CopyTo(TestFile, true);
411 c206d293 taeseongkim
                                StatusChange($"Copy File file Count  > 1 : {PdfFilePath}", 0);
412 8c3a888c djkim
                            }
413 6c9fec59 djkim
                        }
414 e0f00e26 djkim
                        else
415
                        {
416 cbea3c14 humkyung
                            throw new FileNotFoundException("PDF를 찾지 못하였습니다");
417 e0f00e26 djkim
                        }
418
                        #endregion
419
420
                        #region 예외처리
421
                        if (PdfFilePath == null)
422
                        {
423
                            throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다");
424
                        }
425
                        if (!PdfFilePath.Exists)
426
                        {
427
                            throw new Exception("PDF원본이 존재하지 않습니다");
428
                        }
429
                        #endregion
430 cf1cc862 taeseongkim
431 7ca218b3 KangIngu
                    }
432
                    else
433
                    {
434
                        throw new Exception("일치하는 DocInfo가 없습니다");
435
                    }
436
                }
437
            }
438
            catch (Exception ex)
439
            {
440 cf1cc862 taeseongkim
                if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다")
441
                {
442
                    SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다");
443
                    //System.Diagnostics.Process process = new System.Diagnostics.Process();
444
                    //process.StartInfo.FileName = "cmd";
445
                    //process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\"";
446
                    //process.Start();
447
                }
448
                else
449
                {
450
                    SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message);
451
                }
452 7ca218b3 KangIngu
            }
453
            #endregion
454
455
            try
456
            {
457
458 8c3a888c djkim
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
459
                {
460
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
461
462
                    if (finalList.Count() > 0)
463 7ca218b3 KangIngu
                    {
464 c206d293 taeseongkim
                        //TestFile = SetFlattingPDF(TestFile);
465
                        //StatusChange($"SetFlattingPDF : {TestFile}", 0);
466
467 cf1cc862 taeseongkim
                        SetStampInPDF(FinalItem, TestFile, MarkupInfoItem);
468 c206d293 taeseongkim
469 cf1cc862 taeseongkim
                        StatusChange($"SetStampInPDF : {TestFile}", 0);
470 7ca218b3 KangIngu
                    }
471 8c3a888c djkim
                }
472 cf1cc862 taeseongkim
                if (EndFinal != null)
473
                {
474
                    EndFinal(this, new EndFinalEventArgs
475
                    {
476
                        FinalPDFRemotePath = _FinalPDFStorgeRemote + @"\" + FinalPDFPath.Name,
477
                        OriginPDFName = OriginFileName,
478
                        FinalPDFPath = FinalPDFPath.FullName,
479
                        Error = "",
480
                        Message = "",
481
                        FinalPDF = FinalPDF,
482
                    });
483
                }
484 7ca218b3 KangIngu
            }
485
            catch (Exception ex)
486
            {
487 782ad7b1 taeseongkim
                SetNotice(FinalPDF.ID, "MarkFinalPDF Error : " + ex.Message);
488 7ca218b3 KangIngu
            }
489
        }
490
        #endregion
491
492
        #region PDF
493 4804a4fb humkyung
        public static float scaleWidth = 0;
494
        public static float scaleHeight = 0;
495 8c3a888c djkim
496 7ca218b3 KangIngu
        private string SetFlattingPDF(string tempFileInfo)
497
        {
498
            if (File.Exists(tempFileInfo))
499
            {
500
                FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName());
501
502
                PdfReader pdfReader = new PdfReader(tempFileInfo);
503 c206d293 taeseongkim
504 dc0bfdad djkim
                for (int i = 1; i <= pdfReader.NumberOfPages; i++)
505 7ca218b3 KangIngu
                {
506
                    var mediaBox = pdfReader.GetPageSize(i);
507
                    var cropbox = pdfReader.GetCropBox(i);
508
509 8c3a888c djkim
                    //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString()))
510
                    //{
511
                    //    _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE)
512
                    //}
513 7ca218b3 KangIngu
                    var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault();
514
515 8c3a888c djkim
                    //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width;
516
                    //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height;
517
                    //scaleWidth = 2.0832634F;
518
                    //scaleHeight = 3.0F;
519
520 7ca218b3 KangIngu
                    PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i));
521 8c3a888c djkim
                    //강인구 수정
522
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height))
523
                    //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height))
524
                    //{
525
                    //    var pageDict = pdfReader.GetPageN(i);
526
                    //    pageDict.Put(PdfName.MEDIABOX, rect);
527
                    //}
528 7ca218b3 KangIngu
                }
529
530
                var memStream = new MemoryStream();
531
                var stamper = new PdfStamper(pdfReader, memStream)
532
                {
533 dc0bfdad djkim
                    FormFlattening = true,                     
534
                    //FreeTextFlattening = true,
535
                    //AnnotationFlattening = true,                     
536 7ca218b3 KangIngu
                };
537 dc0bfdad djkim
                
538 7ca218b3 KangIngu
                stamper.Close();
539
                pdfReader.Close();
540
                var array = memStream.ToArray();
541
                File.Delete(tempFileInfo);
542
                File.WriteAllBytes(TestFile.FullName, array);
543
544
                return TestFile.FullName;
545
            }
546
            else
547
            {
548
                return tempFileInfo;
549
            }
550
        }
551
552
        public void flattenPdfFile(string src, ref string dest)
553
        {
554
            PdfReader reader = new PdfReader(src);
555
            var memStream = new MemoryStream();
556
            var stamper = new PdfStamper(reader, memStream)
557
            {
558
                FormFlattening = true,
559
                FreeTextFlattening = true,
560
                AnnotationFlattening = true,
561
            };
562
563
            stamper.Close();
564
            var array = memStream.ToArray();
565
            File.WriteAllBytes(dest, array);
566
        }
567 8c3a888c djkim
568 ab590000 taeseongkim
        public void StatusChange(string message,int CurrentPage)
569
        {
570
            if(StatusChanged != null)
571
            {
572 b42dd24d taeseongkim
                //var sb = new StringBuilder();
573
                //sb.AppendLine(message);
574 c206d293 taeseongkim
575 b42dd24d taeseongkim
                StatusChanged(this, new StatusChangedEventArgs { CurrentPage = CurrentPage, Message = message });
576 ab590000 taeseongkim
            }
577
        }
578
579 8c3a888c djkim
        public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo)
580 7ca218b3 KangIngu
        {
581 e0f00e26 djkim
            try
582 8c3a888c djkim
            {
583 faebcce2 taeseongkim
        
584 e0f00e26 djkim
                FileInfo tempFileInfo = new FileInfo(testFile);
585 abaa85b4 djkim
586 e0f00e26 djkim
                if (!Directory.Exists(_FinalPDFStorgeLocal))
587 8c3a888c djkim
                {
588 e0f00e26 djkim
                    Directory.CreateDirectory(_FinalPDFStorgeLocal);
589
                }
590 77cdac33 taeseongkim
591 cbea3c14 humkyung
                string pdfFilePath = Path.Combine(_FinalPDFStorgeLocal, tempFileInfo.Name);
592 faebcce2 taeseongkim
          
593
594 e0f00e26 djkim
                using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
595
                {
596
                    FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault();
597 7ca218b3 KangIngu
598 e0f00e26 djkim
                    #region 코멘트 적용 + 커버시트
599
                    using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) //
600 8c3a888c djkim
                    {
601 ab590000 taeseongkim
                        StatusChange("comment Cover",0);
602 faebcce2 taeseongkim
603 5ba8f2d5 taeseongkim
                        using (PdfReader pdfReader = new PdfReader(pdfStream))
604
                        { 
605
                            //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>();
606
                            Dictionary<string, object> bookmark;
607
                            List<Dictionary<string, object>> outlines;
608 e0f00e26 djkim
609 5ba8f2d5 taeseongkim
                            outlines = new List<Dictionary<string, object>>();
610
                            List<Dictionary<string, object>> root = new List<Dictionary<string, object>>();
611 faebcce2 taeseongkim
612 5ba8f2d5 taeseongkim
                            var dic = new Dictionary<string, object>();
613 abaa85b4 djkim
614 5ba8f2d5 taeseongkim
                            foreach (var data in MarkupDataSet)
615
                            {
616
                                //StatusChange("MarkupDataSet", 0);
617 e0f00e26 djkim
618 5ba8f2d5 taeseongkim
                                string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID;
619 faebcce2 taeseongkim
620 5ba8f2d5 taeseongkim
                                string username = "";
621
                                string userdept = "";
622 faebcce2 taeseongkim
623 5ba8f2d5 taeseongkim
                                using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString()))
624 faebcce2 taeseongkim
                                {
625 5ba8f2d5 taeseongkim
                                    var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
626
627
                                    if(memberlist.Count() > 0)
628
                                    {
629
                                        username = memberlist.First().NAME;
630
                                        userdept = memberlist.First().DEPARTMENT;
631
                                    }
632 faebcce2 taeseongkim
                                }
633
634 5ba8f2d5 taeseongkim
                                bookmark = new Dictionary<string, object>();
635
                                bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER));
636
                                bookmark.Add("Page", data.PAGENUMBER + " Fit");
637
                                bookmark.Add("Action", "GoTo");
638
                                bookmark.Add("Kids", outlines);
639
                                root.Add(bookmark);
640
                            }
641 abaa85b4 djkim
642 43e1d368 taeseongkim
                            iTextSharp.text.Version.GetInstance();
643 4b33593a taeseongkim
644 5ba8f2d5 taeseongkim
                            using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create)))
645 782ad7b1 taeseongkim
                            {
646 5ba8f2d5 taeseongkim
                                try
647 782ad7b1 taeseongkim
                                {
648 5ba8f2d5 taeseongkim
                                    if (pdfStamper.AcroFields != null && pdfStamper.AcroFields.GenerateAppearances != true)
649
                                    {
650
                                        pdfStamper.AcroFields.GenerateAppearances = true;
651
                                    }
652
                                }
653
                                catch (Exception ex)
654
                                {
655
                                    SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
656 782ad7b1 taeseongkim
                                }
657 c206d293 taeseongkim
658 43e1d368 taeseongkim
                                System.Drawing.Color _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red);
659
                                
660 7ca218b3 KangIngu
661 5ba8f2d5 taeseongkim
                                string[] delimiterChars = { "|DZ|" };
662
                                string[] delimiterChars2 = { "|" };
663 7ca218b3 KangIngu
664 5ba8f2d5 taeseongkim
                                //pdfStamper.FormFlattening = true; //이미 선처리 작업함
665
                                pdfStamper.SetFullCompression();
666 43e1d368 taeseongkim
                                _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red);
667 7ca218b3 KangIngu
668 5ba8f2d5 taeseongkim
                                StringBuilder strLog = new StringBuilder();
669
                                int lastPageNo = 0;
670 b42dd24d taeseongkim
671 5ba8f2d5 taeseongkim
                                strLog.Append($"Write {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} markup Count : {MarkupDataSet.Count()} / ");
672 b42dd24d taeseongkim
673 5ba8f2d5 taeseongkim
                                foreach (var markupItem in MarkupDataSet)
674 2e1d6c99 djkim
                                {
675 5ba8f2d5 taeseongkim
                                    /// 2020.11.13 김태성
676
                                    /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함.
677
                                    var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER);
678 7aa36857 humkyung
679 5ba8f2d5 taeseongkim
                                    if (pageitems.Count() > 0)
680
                                    {
681
                                        var currentPage = pageitems.First();
682
                                        pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER);
683
                                        lastPageNo = markupItem.PAGENUMBER;
684
                                        //try
685
                                        //{
686
687
                                        //}
688
                                        //catch (Exception ex)
689
                                        //{
690
                                        //    SetNotice(finaldata.ID, $"GetPageSizeWithRotation Error PageNO : {markupItem.PAGENUMBER} " + ex.ToString());
691
                                        //}
692
                                        //finally
693
                                        //{
694
                                        //    pdfSize = new iTextSharp.text.Rectangle(0, 0, float.Parse(currentPage.PAGE_WIDTH), float.Parse(currentPage.PAGE_HEIGHT));
695
                                        //}
696
697
                                        mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER);
698
                                        var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER);
699
700
                                        /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다
701
                                        if (cropBox != null &&
702
                                            (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom))
703
                                        {
704
                                            PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
705 7aa36857 humkyung
706 5ba8f2d5 taeseongkim
                                            PdfArray oNewMediaBox = new PdfArray();
707
                                            oNewMediaBox.Add(new PdfNumber(cropBox.Left));
708
                                            oNewMediaBox.Add(new PdfNumber(cropBox.Top));
709
                                            oNewMediaBox.Add(new PdfNumber(cropBox.Right));
710
                                            oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
711
                                            dict.Put(PdfName.MEDIABOX, oNewMediaBox);
712 7ca218b3 KangIngu
713 5ba8f2d5 taeseongkim
                                            pdfSize = cropBox;
714
                                        }
715 8c3a888c djkim
716 5ba8f2d5 taeseongkim
                                        scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
717
                                        scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
718 e0f00e26 djkim
719 5ba8f2d5 taeseongkim
                                        pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
720
                                        _entity.SaveChanges();
721 e0f00e26 djkim
722 5ba8f2d5 taeseongkim
                                        string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
723 ff665e73 taeseongkim
724 5ba8f2d5 taeseongkim
                                        PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
725 4b33593a taeseongkim
                                        strLog.Append($"p.{markupItem.PAGENUMBER}:{markupItem.DATA_TYPE}/");
726 ff665e73 taeseongkim
727 5ba8f2d5 taeseongkim
                                        foreach (var data in markedData)
728 e0f00e26 djkim
                                        {
729 5ba8f2d5 taeseongkim
                                            var item = JsonSerializerHelper.UnCompressString(data);
730
                                            var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
731
732
                                            try
733 ff665e73 taeseongkim
                                            {
734 5ba8f2d5 taeseongkim
                                                switch (ControlT.Name)
735
                                                {
736
                                                    #region LINE
737
                                                    case "LineControl":
738 ff665e73 taeseongkim
                                                        {
739 5ba8f2d5 taeseongkim
                                                            using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item))
740
                                                            {
741
                                                                DrawLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
742
                                                            }
743 ff665e73 taeseongkim
                                                        }
744 5ba8f2d5 taeseongkim
                                                        break;
745
                                                    #endregion
746
                                                    #region ArrowControlMulti
747
                                                    case "ArrowControl_Multi":
748 ff665e73 taeseongkim
                                                        {
749 5ba8f2d5 taeseongkim
                                                            using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
750
                                                            {
751
                                                                DrawMultiArrowLine(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
752
                                                            }
753 ff665e73 taeseongkim
                                                        }
754 5ba8f2d5 taeseongkim
                                                        break;
755
                                                    #endregion
756
                                                    #region PolyControl
757
                                                    case "PolygonControl":
758
                                                        using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item))
759 8c3a888c djkim
                                                        {
760 ff665e73 taeseongkim
                                                            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
761
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
762 43e1d368 taeseongkim
                                                            var PaintStyle = control.PaintState;
763 ff665e73 taeseongkim
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
764
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
765
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
766 5ba8f2d5 taeseongkim
                                                            double Opacity = control.Opac;
767
                                                            DoubleCollection DashSize = control.DashSize;
768 ff665e73 taeseongkim
769 43e1d368 taeseongkim
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor,PaintStyle| PaintSet.Outline, Opacity);
770
                                                            //Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
771 5ba8f2d5 taeseongkim
                                                        }
772
                                                        break;
773
                                                    #endregion
774
                                                    #region ArcControl or ArrowArcControl
775
                                                    case "ArcControl":
776
                                                    case "ArrowArcControl":
777
                                                        {
778
                                                            using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item))
779 ff665e73 taeseongkim
                                                            {
780 5ba8f2d5 taeseongkim
                                                                string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
781
                                                                Point StartPoint = GetPdfPointSystem(control.StartPoint);
782
                                                                Point EndPoint = GetPdfPointSystem(control.EndPoint);
783
                                                                Point MidPoint = GetPdfPointSystem(control.MidPoint);
784
                                                                DoubleCollection DashSize = control.DashSize;
785
                                                                List<Point> PointSet = GetPdfPointSystem(control.PointSet);
786
787
                                                                var Opacity = control.Opac;
788
                                                                string UserID = control.UserID;
789
                                                                double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
790
                                                                bool IsTransOn = control.IsTransOn;
791
792
                                                                if (control.IsTransOn)
793
                                                                {
794
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
795
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true);
796
                                                                }
797
                                                                else
798
                                                                {
799
                                                                    Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity);
800
                                                                }
801 e0f00e26 djkim
802 5ba8f2d5 taeseongkim
                                                                if (ControlT.Name == "ArrowArcControl")
803
                                                                {
804
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
805
                                                                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity);
806
                                                                }
807 ff665e73 taeseongkim
                                                            }
808 c206d293 taeseongkim
                                                        }
809 5ba8f2d5 taeseongkim
                                                        break;
810
                                                    #endregion
811
                                                    #region RectangleControl
812
                                                    case "RectangleControl":
813
                                                        using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item))
814 8c3a888c djkim
                                                        {
815 5ba8f2d5 taeseongkim
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
816
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
817
                                                            var PaintStyle = control.PaintState;
818
                                                            double Angle = control.Angle;
819
                                                            DoubleCollection DashSize = control.DashSize;
820
                                                            double Opacity = control.Opac;
821
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
822
823
                                                            Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity);
824 ff665e73 taeseongkim
                                                        }
825 5ba8f2d5 taeseongkim
                                                        break;
826
                                                    #endregion
827
                                                    #region TriControl
828
                                                    case "TriControl":
829
                                                        using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item))
830 ff665e73 taeseongkim
                                                        {
831 5ba8f2d5 taeseongkim
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
832
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
833
                                                            var PaintStyle = control.Paint;
834
                                                            double Angle = control.Angle;
835
                                                            //StrokeColor = _SetColor, //색상은 레드
836
                                                            DoubleCollection DashSize = control.DashSize;
837
                                                            double Opacity = control.Opac;
838
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
839
840 43e1d368 taeseongkim
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle | PaintSet.Outline, Opacity);
841 ff665e73 taeseongkim
                                                        }
842 5ba8f2d5 taeseongkim
                                                        break;
843
                                                    #endregion
844
                                                    #region CircleControl
845
                                                    case "CircleControl":
846
                                                        using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item))
847 ff665e73 taeseongkim
                                                        {
848 5ba8f2d5 taeseongkim
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
849
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
850
                                                            var StartPoint = GetPdfPointSystem(control.StartPoint);
851
                                                            var EndPoint = GetPdfPointSystem(control.EndPoint);
852
                                                            var PaintStyle = control.PaintState;
853
                                                            double Angle = control.Angle;
854
                                                            DoubleCollection DashSize = control.DashSize;
855
                                                            double Opacity = control.Opac;
856
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
857
                                                            Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet);
858
859 ff665e73 taeseongkim
                                                        }
860 5ba8f2d5 taeseongkim
                                                        break;
861
                                                    #endregion
862
                                                    #region RectCloudControl
863
                                                    case "RectCloudControl":
864
                                                        using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item))
865 ff665e73 taeseongkim
                                                        {
866 5ba8f2d5 taeseongkim
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
867
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
868
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
869
                                                            double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
870 ff665e73 taeseongkim
871 5ba8f2d5 taeseongkim
                                                            double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
872
873
                                                            var PaintStyle = control.PaintState;
874
                                                            double Opacity = control.Opac;
875
                                                            DoubleCollection DashSize = control.DashSize;
876
877
                                                            //드로잉 방식이 표현되지 않음
878
                                                            var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint));
879
880
                                                            double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
881
                                                            bool reverse = (area < 0);
882 43e1d368 taeseongkim
                                                    
883
                                                            Controls_PDF.DrawSet_Cloud.DrawCloudRect(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
884 8c3a888c djkim
                                                        }
885 5ba8f2d5 taeseongkim
                                                        break;
886
                                                    #endregion
887
                                                    #region CloudControl
888
                                                    case "CloudControl":
889
                                                        using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item))
890 4f017ed3 taeseongkim
                                                        {
891 5ba8f2d5 taeseongkim
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
892
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
893
                                                            double Toler = control.Toler;
894
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
895
                                                            double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight);
896
                                                            var PaintStyle = control.PaintState;
897
                                                            double Opacity = control.Opac;
898
                                                            bool isTransOn = control.IsTrans;
899
                                                            bool isChain = control.IsChain;
900 ff665e73 taeseongkim
901 5ba8f2d5 taeseongkim
                                                            DoubleCollection DashSize = control.DashSize;
902
903
                                                            if (isChain)
904
                                                            {
905
                                                                Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
906
                                                            }
907
                                                            else
908
                                                            {
909
                                                                if (isTransOn)
910 ff665e73 taeseongkim
                                                                {
911 5ba8f2d5 taeseongkim
                                                                    double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet));
912
                                                                    bool reverse = (area < 0);
913
914
                                                                    if (PaintStyle == PaintSet.None)
915
                                                                    {
916
                                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
917
                                                                    }
918
                                                                    else
919
                                                                    {
920
                                                                        Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
921
                                                                    }
922 ff665e73 taeseongkim
                                                                }
923 5ba8f2d5 taeseongkim
                                                                else
924 ff665e73 taeseongkim
                                                                {
925 5ba8f2d5 taeseongkim
                                                                    Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity);
926 ff665e73 taeseongkim
                                                                }
927 5ba8f2d5 taeseongkim
                                                            }
928 4f017ed3 taeseongkim
                                                        }
929 5ba8f2d5 taeseongkim
                                                        break;
930
                                                    #endregion
931
                                                    #region TEXT
932
                                                    case "TextControl":
933
                                                        using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
934 4f017ed3 taeseongkim
                                                        {
935 5ba8f2d5 taeseongkim
                                                            DrawTextBox(control, contentByte, delimiterChars, delimiterChars2, _SetColor);
936 4f017ed3 taeseongkim
                                                        }
937 5ba8f2d5 taeseongkim
                                                        break;
938
                                                    #endregion
939
                                                    #region ArrowTextControl
940
                                                    case "ArrowTextControl":
941
                                                        using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item))
942 ff665e73 taeseongkim
                                                        {
943 5ba8f2d5 taeseongkim
                                                            //using (S_TextControl textcontrol = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item))
944
                                                            //{
945
                                                            //    textcontrol.Angle = control.Angle;
946
                                                            //    textcontrol.BoxH = control.BoxHeight;
947
                                                            //    textcontrol.BoxW = control.BoxWidth;
948
                                                            //    textcontrol.EndPoint = control.EndPoint;
949
                                                            //    textcontrol.FontColor = "#FFFF0000";
950
                                                            //    textcontrol.Name = "TextControl";
951
                                                            //    textcontrol.Opac = control.Opac;
952
                                                            //    textcontrol.PointSet = new List<Point>();
953
                                                            //    textcontrol.SizeSet = string.Join(delimiterChars2.First(), control.SizeSet.First(), control.fontConfig[3]);
954
                                                            //    textcontrol.StartPoint = control.StartPoint;
955
                                                            //    textcontrol.Text = control.ArrowText;
956
                                                            //    textcontrol.TransformPoint = control.TransformPoint;
957
                                                            //    textcontrol.UserID = null;
958
                                                            //    textcontrol.fontConfig = control.fontConfig;
959
                                                            //    textcontrol.isHighLight = control.isHighLight;
960
                                                            //    textcontrol.paintMethod = 1;
961
962
                                                            //    DrawTextBox(textcontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
963
                                                            //}
964
965
                                                            //using (S_ArrowControl_Multi linecontrol = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item))
966
                                                            //{
967
                                                            //    linecontrol.Angle = control.Angle;
968
                                                            //    linecontrol.DashSize = new DoubleCollection(new[] {(double)999999 });
969
                                                            //    linecontrol.EndPoint = control.EndPoint;
970
                                                            //    linecontrol.MidPoint = control.MidPoint;
971
                                                            //    linecontrol.Name = "ArrowControl_Multi";
972
                                                            //    linecontrol.Opac = control.Opac;
973
                                                            //    linecontrol.PointSet = control.PointSet;
974
                                                            //    linecontrol.SizeSet = control.SizeSet;
975
                                                            //    linecontrol.StartPoint = control.StartPoint;
976
                                                            //    linecontrol.StrokeColor = control.StrokeColor;
977
                                                            //    linecontrol.TransformPoint = control.TransformPoint;
978
979
                                                            //    DrawMultiArrowLine(linecontrol, contentByte, delimiterChars, delimiterChars2, _SetColor);
980
                                                            //}
981
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
982
                                                            Point tempStartPoint = GetPdfPointSystem(control.StartPoint);
983
                                                            Point tempMidPoint = GetPdfPointSystem(control.MidPoint);
984
                                                            Point tempEndPoint = GetPdfPointSystem(control.EndPoint);
985
                                                            bool isUnderLine = false;
986
                                                            string Text = "";
987
                                                            double fontsize = 30;
988
989
                                                            System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight);
990
                                                            Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight));
991
                                                            List<Point> tempPoint = new List<Point>();
992
993
                                                            double Angle = control.Angle;
994
995
                                                            if (Math.Abs(Angle).ToString() == "90")
996 ff665e73 taeseongkim
                                                            {
997 5ba8f2d5 taeseongkim
                                                                Angle = 270;
998 ff665e73 taeseongkim
                                                            }
999 5ba8f2d5 taeseongkim
                                                            else if (Math.Abs(Angle).ToString() == "270")
1000 ff665e73 taeseongkim
                                                            {
1001 5ba8f2d5 taeseongkim
                                                                Angle = 90;
1002 ff665e73 taeseongkim
                                                            }
1003 8c3a888c djkim
1004 5ba8f2d5 taeseongkim
                                                            var tempRectMidPoint = MathSet.getRectMiddlePoint(rect);
1005
                                                            tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y));
1006
                                                            tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top));
1007
                                                            tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y));
1008
                                                            tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom));
1009
1010
                                                            var newStartPoint = tempStartPoint;
1011
                                                            var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint);
1012
                                                            var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint);
1013
1014
                                                            //Point testPoint = tempEndPoint;
1015
                                                            //if (Angle != 0)
1016
                                                            //{
1017
                                                            //    testPoint = GetArrowTextControlTestPoint(0, newMidPoint, tempPoint, control.isFixed);
1018
                                                            //   //testPoint = Test(rect, newMidPoint);
1019
                                                            //}
1020
1021
                                                            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1022 43e1d368 taeseongkim
                                                            System.Drawing.Color FontColor = _SetColor;
1023 5ba8f2d5 taeseongkim
                                                            bool isHighlight = control.isHighLight;
1024
                                                            double Opacity = control.Opac;
1025
                                                            PaintSet Paint = PaintSet.None;
1026
1027
                                                            switch (control.ArrowStyle)
1028 ff665e73 taeseongkim
                                                            {
1029 5ba8f2d5 taeseongkim
                                                                case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal:
1030
                                                                    {
1031
                                                                        Paint = PaintSet.None;
1032
                                                                    }
1033
                                                                    break;
1034
                                                                case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud:
1035
                                                                    {
1036
                                                                        Paint = PaintSet.Hatch;
1037
                                                                    }
1038
                                                                    break;
1039
                                                                case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect:
1040
                                                                    {
1041
                                                                        Paint = PaintSet.Fill;
1042
                                                                    }
1043
                                                                    break;
1044
                                                                default:
1045
                                                                    break;
1046 ff665e73 taeseongkim
                                                            }
1047 5ba8f2d5 taeseongkim
                                                            if (control.isHighLight) Paint |= PaintSet.Highlight;
1048 8c3a888c djkim
1049 5ba8f2d5 taeseongkim
                                                            if (Paint == PaintSet.Hatch)
1050 e0f00e26 djkim
                                                            {
1051 5ba8f2d5 taeseongkim
                                                                Text = control.ArrowText;
1052 ff665e73 taeseongkim
                                                            }
1053 5ba8f2d5 taeseongkim
                                                            else
1054 ff665e73 taeseongkim
                                                            {
1055 5ba8f2d5 taeseongkim
                                                                Text = control.ArrowText;
1056 ff665e73 taeseongkim
                                                            }
1057 5ba8f2d5 taeseongkim
1058
                                                            try
1059 ff665e73 taeseongkim
                                                            {
1060 5ba8f2d5 taeseongkim
                                                                if (control.fontConfig.Count == 4)
1061
                                                                {
1062
                                                                    fontsize = Convert.ToDouble(control.fontConfig[3]);
1063
                                                                }
1064
1065
                                                                //강인구 수정(2018.04.17)
1066
                                                                var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1067
1068
                                                                FontStyle fontStyle = FontStyles.Normal;
1069
                                                                if (FontStyles.Italic == TextStyle)
1070
                                                                {
1071
                                                                    fontStyle = FontStyles.Italic;
1072
                                                                }
1073
1074
                                                                FontWeight fontWeight = FontWeights.Black;
1075
1076
                                                                var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1077
                                                                if (FontWeights.Bold == TextWeight)
1078
                                                                {
1079
                                                                    fontWeight = FontWeights.Bold;
1080
                                                                }
1081
1082
                                                                TextDecorationCollection decoration = TextDecorations.Baseline;
1083
                                                                if (control.fontConfig.Count() == 5)
1084
                                                                {
1085
                                                                    decoration = TextDecorations.Underline;
1086
                                                                }
1087
1088
                                                                if (control.isTrans)
1089 4f017ed3 taeseongkim
                                                                {
1090 ff665e73 taeseongkim
                                                                    //인구 수정 Arrow Text Style적용 되도록 변경
1091
                                                                    Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1092 5ba8f2d5 taeseongkim
                                                                    newStartPoint, tempMidPoint, newEndPoint, control.isFixed,
1093
                                                                    LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1094 4f017ed3 taeseongkim
                                                                }
1095 ff665e73 taeseongkim
                                                                else
1096 4f017ed3 taeseongkim
                                                                {
1097 5ba8f2d5 taeseongkim
                                                                    if (control.isFixed)
1098
                                                                    {
1099
                                                                        var testP = new Point(0, 0);
1100
                                                                        if (control.isFixed)
1101
                                                                        {
1102
                                                                            if (tempPoint[1] == newEndPoint)
1103
                                                                            {
1104
                                                                                testP = new Point(newEndPoint.X, newEndPoint.Y - 10);
1105
                                                                            }
1106
                                                                            else if (tempPoint[3] == newEndPoint)
1107
                                                                            {
1108
                                                                                testP = new Point(newEndPoint.X, newEndPoint.Y + 10);
1109
                                                                            }
1110
                                                                            else if (tempPoint[0] == newEndPoint)
1111
                                                                            {
1112
                                                                                testP = new Point(newEndPoint.X - 10, newEndPoint.Y);
1113
                                                                            }
1114
                                                                            else if (tempPoint[2] == newEndPoint)
1115
                                                                            {
1116
                                                                                testP = new Point(newEndPoint.X + 10, newEndPoint.Y);
1117
                                                                            }
1118
                                                                        }
1119
                                                                        //인구 수정 Arrow Text Style적용 되도록 변경
1120
                                                                        Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1121
                                                                            tempStartPoint, testP, tempEndPoint, control.isFixed,
1122
                                                                            LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight,
1123
                                                                        FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1124
                                                                    }
1125
                                                                    else
1126
                                                                    {
1127
                                                                        //인구 수정 Arrow Text Style적용 되도록 변경
1128
                                                                        Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight),
1129
                                                                            newStartPoint, tempMidPoint, tempEndPoint, control.isFixed,
1130
                                                                            LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, FontHelper.GetFontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1131
                                                                    }
1132 e0f00e26 djkim
                                                                }
1133
                                                            }
1134 5ba8f2d5 taeseongkim
                                                            catch (Exception ex)
1135
                                                            {
1136
                                                                throw ex;
1137
                                                            }
1138
1139 4f017ed3 taeseongkim
                                                        }
1140 5ba8f2d5 taeseongkim
                                                        break;
1141
                                                    #endregion
1142
                                                    #region SignControl
1143
                                                    case "SignControl":
1144
                                                        using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item))
1145 4f017ed3 taeseongkim
                                                        {
1146 5ba8f2d5 taeseongkim
1147
                                                            double Angle = control.Angle;
1148
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1149
                                                            Point TopRightPoint = GetPdfPointSystem(control.TR);
1150
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1151
                                                            Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1152
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1153
                                                            double Opacity = control.Opac;
1154
                                                            string UserNumber = control.UserNumber;
1155
                                                            Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO);
1156 e0f00e26 djkim
                                                        }
1157 5ba8f2d5 taeseongkim
                                                        break;
1158
                                                    #endregion
1159
                                                    #region MyRegion
1160
                                                    case "DateControl":
1161
                                                        using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item))
1162
                                                        {
1163
                                                            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1164
                                                            string Text = control.Text;
1165
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1166
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1167
                                                            List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1168 43e1d368 taeseongkim
                                                            System.Drawing.Color FontColor = _SetColor;
1169 5ba8f2d5 taeseongkim
                                                            double Angle = control.Angle;
1170
                                                            double Opacity = control.Opac;
1171
                                                            Controls_PDF.PDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity);
1172
                                                        }
1173
                                                        break;
1174
                                                    #endregion
1175
                                                    #region SymControlN (APPROVED)
1176
                                                    case "SymControlN":
1177
                                                        using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1178
                                                        {
1179
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1180
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1181
                                                            List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1182 43e1d368 taeseongkim
                                                            System.Drawing.Color FontColor = _SetColor;
1183 5ba8f2d5 taeseongkim
                                                            double Angle = control.Angle;
1184
                                                            double Opacity = control.Opac;
1185
1186
                                                            var stamp = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP");
1187
1188
                                                            if (stamp.Count() > 0)
1189
                                                            {
1190
                                                                var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1191
1192 43e1d368 taeseongkim
                                                                var Contents = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP_CONTENTS");
1193
                                                                
1194
                                                                if (Contents?.Count() > 0)
1195
                                                                {
1196
                                                                    foreach (var content in Contents)
1197
                                                                    {
1198
                                                                        xamldata = xamldata.Replace(content.PROPERTY, System.Security.SecurityElement.Escape(content.VALUE));
1199
                                                                    }
1200
                                                                }
1201
1202 5ba8f2d5 taeseongkim
                                                                Controls_PDF.PDFLib_DrawSet_Symbol.DrawApprovalXamlData(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, xamldata);
1203
                                                            }
1204
1205
                                                            string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", "");
1206 ff665e73 taeseongkim
1207 5ba8f2d5 taeseongkim
                                                        }
1208
                                                        break;
1209
                                                    case "SymControl":
1210
                                                        using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item))
1211 ff665e73 taeseongkim
                                                        {
1212 5ba8f2d5 taeseongkim
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1213
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1214
                                                            List<Point> pointSet = GetPdfPointSystem(control.PointSet);
1215 43e1d368 taeseongkim
                                                            System.Drawing.Color FontColor = _SetColor;
1216 5ba8f2d5 taeseongkim
                                                            double Angle = control.Angle;
1217
                                                            double Opacity = control.Opac;
1218 ff665e73 taeseongkim
1219 5ba8f2d5 taeseongkim
                                                            string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", "");
1220
                                                            Controls_PDF.PDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath);
1221 ff665e73 taeseongkim
                                                        }
1222 5ba8f2d5 taeseongkim
                                                        break;
1223
                                                    #endregion
1224
                                                    #region Image
1225
                                                    case "ImgControl":
1226
                                                        using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item))
1227
                                                        {
1228
                                                            double Angle = control.Angle;
1229
                                                            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1230
                                                            Point TopRightPoint = GetPdfPointSystem(control.TR);
1231
                                                            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1232
                                                            Point LeftBottomPoint = GetPdfPointSystem(control.LB);
1233
                                                            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1234
                                                            double Opacity = control.Opac;
1235
                                                            string FilePath = control.ImagePath;
1236
                                                            //Uri uri = new Uri(s.ImagePath);
1237 ff665e73 taeseongkim
1238 5ba8f2d5 taeseongkim
                                                            Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity);
1239
                                                        }
1240
                                                        break;
1241
                                                    #endregion
1242
                                                    default:
1243
                                                        StatusChange($"{ControlT.Name} Not Support", 0);
1244
                                                        break;
1245
                                                }
1246 c206d293 taeseongkim
1247 5ba8f2d5 taeseongkim
                                            }
1248
                                            catch (Exception ex)
1249 b42dd24d taeseongkim
                                            {
1250 5ba8f2d5 taeseongkim
                                                StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1251
                                            }
1252
                                            finally
1253
                                            {
1254 4b33593a taeseongkim
                                                //if (ControlT?.Name != null)
1255
                                                //{
1256
                                                //    strLog.Append($"{ControlT.Name},");
1257
                                                //}
1258 b42dd24d taeseongkim
                                            }
1259
                                        }
1260 5ba8f2d5 taeseongkim
1261 e0f00e26 djkim
                                    }
1262 5ba8f2d5 taeseongkim
                                }
1263 b42dd24d taeseongkim
1264 5ba8f2d5 taeseongkim
                                if (StatusChanged != null)
1265
                                {
1266
                                    StatusChanged(this, new StatusChangedEventArgs { CurrentPage = lastPageNo, Message = strLog.ToString() });
1267 ed705a3d taeseongkim
                                }
1268 5ba8f2d5 taeseongkim
                                //PdfFileSpecification pfs = PdfFileSpecification.FileEmbedded(pdfStamper.Writer, @"C:\Users\kts\Documents\업무\CARS\엑셀양식\F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", "F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", null);
1269
                                //pdfStamper.AddFileAttachment("F-000-5378-702_R2_계장 Cable Schedule Sample.xlsx", pfs);
1270 b42dd24d taeseongkim
1271 5ba8f2d5 taeseongkim
                                pdfStamper.Outlines = root;
1272
                                pdfStamper.Close();
1273
                                pdfReader.Close();
1274 b42dd24d taeseongkim
                            }
1275 7ca218b3 KangIngu
                        }
1276 abaa85b4 djkim
                    }
1277 e0f00e26 djkim
                    #endregion
1278 7ca218b3 KangIngu
                }
1279 a1e2ba68 taeseongkim
1280 7ca218b3 KangIngu
                if (tempFileInfo.Exists)
1281
                {
1282 a1e2ba68 taeseongkim
#if !DEBUG
1283 7ca218b3 KangIngu
                    tempFileInfo.Delete();
1284 a1e2ba68 taeseongkim
#endif
1285 7ca218b3 KangIngu
                }
1286
1287
                if (File.Exists(pdfFilePath))
1288
                {
1289 e77fc685 taeseongkim
                    string destfilepath = null;
1290 7ca218b3 KangIngu
                    try
1291
                    {
1292 6e5f7eaf djkim
                        FinalPDFPath = new FileInfo(pdfFilePath);
1293
1294 907a99b3 taeseongkim
                        /// 정리 필요함. DB로 변경
1295
                        string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", "");
1296
1297
                        if(!string.IsNullOrEmpty(pdfmovepath))
1298
                        {
1299
                            _FinalPDFStorgeLocal = pdfmovepath;
1300
                        }
1301
1302 e77fc685 taeseongkim
                        destfilepath = Path.Combine(_FinalPDFStorgeLocal, FinalPDFPath.Name.Replace(".tmp", ".pdf"));
1303
1304 6e5f7eaf djkim
                        if (File.Exists(destfilepath))
1305
                            File.Delete(destfilepath);
1306 e77fc685 taeseongkim
1307 6e5f7eaf djkim
                        File.Move(FinalPDFPath.FullName, destfilepath);
1308
                        FinalPDFPath = new FileInfo(destfilepath);
1309 7ca218b3 KangIngu
                        File.Delete(pdfFilePath);
1310
                    }
1311
                    catch (Exception ex)
1312
                    {
1313 e77fc685 taeseongkim
                        SetNotice(finaldata.ID, $"File move error - Source File : {FinalPDFPath.FullName} dest File : {destfilepath}" + ex.ToString());
1314 7ca218b3 KangIngu
                    }
1315
1316
                    return true;
1317
                }
1318
            }
1319 7aa36857 humkyung
            catch (Exception ex)
1320 7ca218b3 KangIngu
            {
1321 782ad7b1 taeseongkim
                SetNotice(finaldata.ID, "SetStempinPDF error: " + ex.ToString());
1322 7ca218b3 KangIngu
            }
1323
            return false;
1324
        }
1325 4f017ed3 taeseongkim
1326
        /// <summary>
1327
        /// kcom의 화살표방향과 틀려 추가함
1328
        /// </summary>
1329
        /// <param name="PageAngle"></param>
1330
        /// <param name="endP"></param>
1331
        /// <param name="ps">box Points</param>
1332
        /// <param name="IsFixed"></param>
1333
        /// <returns></returns>
1334
        private Point GetArrowTextControlTestPoint(double PageAngle,Point endP,List<Point> ps,bool IsFixed)
1335
        {
1336
            Point testP = endP;
1337
1338
            try
1339
            {
1340
                switch (Math.Abs(PageAngle).ToString())
1341
                {
1342
                    case "90":
1343
                        testP = new Point(endP.X + 50, endP.Y);
1344
                        break;
1345
                    case "270":
1346
                        testP = new Point(endP.X - 50, endP.Y);
1347
                        break;
1348
                }
1349
1350
                //20180910 LJY 각도에 따라.
1351
                switch (Math.Abs(PageAngle).ToString())
1352
                {
1353
                    case "90":
1354
                        if (IsFixed)
1355
                        {
1356
                            if (ps[0] == endP) //상단
1357
                            {
1358
                                testP = new Point(endP.X, endP.Y + 50);
1359
                                //System.Diagnostics.Debug.WriteLine("상단"+ testP);
1360
                            }
1361
                            else if (ps[1] == endP) //하단
1362
                            {
1363
                                testP = new Point(endP.X, endP.Y - 50);
1364
                                //System.Diagnostics.Debug.WriteLine("하단"+ testP);
1365
                            }
1366
                            else if (ps[2] == endP) //좌단
1367
                            {
1368
                                testP = new Point(endP.X - 50, endP.Y);
1369
                                //System.Diagnostics.Debug.WriteLine("좌단"+ testP);
1370
                            }
1371
                            else if (ps[3] == endP) //우단
1372
                            {
1373
                                testP = new Point(endP.X + 50, endP.Y);
1374
                                //System.Diagnostics.Debug.WriteLine("우단"+ testP);
1375
                            }
1376
                        }
1377
                        break;
1378
                    case "270":
1379
                        if (IsFixed)
1380
                        {
1381
                            if (ps[0] == endP) //상단
1382
                            {
1383
                                testP = new Point(endP.X, endP.Y - 50);
1384
                                //System.Diagnostics.Debug.WriteLine("상단" + testP);
1385
                            }
1386
                            else if (ps[1] == endP) //하단
1387
                            {
1388
                                testP = new Point(endP.X, endP.Y + 50);
1389
                                //System.Diagnostics.Debug.WriteLine("하단" + testP);
1390
                            }
1391
                            else if (ps[2] == endP) //좌단
1392
                            {
1393
                                testP = new Point(endP.X + 50, endP.Y);
1394
                                //System.Diagnostics.Debug.WriteLine("좌단" + testP);
1395
                            }
1396
                            else if (ps[3] == endP) //우단
1397
                            {
1398
                                testP = new Point(endP.X - 50, endP.Y);
1399
                                //System.Diagnostics.Debug.WriteLine("우단" + testP);
1400
                            }
1401
                        }
1402
                        break;
1403
                    default:
1404
                        if (IsFixed)
1405
                        {
1406
1407
                            if (ps[0] == endP) //상단
1408
                            {
1409
                                testP = new Point(endP.X, endP.Y - 50);
1410
                                //System.Diagnostics.Debug.WriteLine("상단");
1411
                            }
1412
                            else if (ps[1] == endP) //하단
1413
                            {
1414
                                testP = new Point(endP.X, endP.Y + 50);
1415
                                //System.Diagnostics.Debug.WriteLine("하단");
1416
                            }
1417
                            else if (ps[2] == endP) //좌단
1418
                            {
1419
                                testP = new Point(endP.X - 50, endP.Y);
1420
                                //System.Diagnostics.Debug.WriteLine("좌단");
1421
                            }
1422
                            else if (ps[3] == endP) //우단
1423
                            {
1424
                                testP = new Point(endP.X + 50, endP.Y);
1425
                                //System.Diagnostics.Debug.WriteLine("우단");
1426
                            }
1427
                        }
1428
                        break;
1429
                }
1430
1431
            }
1432
            catch (Exception)
1433
            {
1434
            }
1435
1436
            return testP;
1437
        }
1438
1439
        private Point Test(Rect rect,Point point)
1440
        {
1441
            Point result = new Point();
1442
1443
            Point newPoint = new Point();
1444
1445
            double oldNear = 0;
1446
            double newNear = 0;
1447
1448
            oldNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.TopRight, out result);
1449
1450
            newNear = MathSet.GetShortestDistance(point, rect.TopLeft, rect.BottomLeft, out newPoint);
1451
1452
            if (newNear < oldNear)
1453
            {
1454
                oldNear = newNear;
1455
                result = newPoint;
1456
            }
1457
1458
            newNear = MathSet.GetShortestDistance(point, rect.TopRight, rect.BottomRight, out newPoint);
1459
1460
            if (newNear < oldNear)
1461
            {
1462
                oldNear = newNear;
1463
                result = newPoint;
1464
            }
1465
1466
1467
            newNear = MathSet.GetShortestDistance(point, rect.BottomLeft, rect.BottomRight, out newPoint);
1468
1469
            if (newNear < oldNear)
1470
            {
1471
                oldNear = newNear;
1472
                result = newPoint;
1473
            }
1474
1475
            return result;
1476
        }
1477
1478 43e1d368 taeseongkim
        private void DrawMultiArrowLine(S_ArrowControl_Multi control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor)
1479 4f017ed3 taeseongkim
        {
1480
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1481
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1482
            Point MidPoint = GetPdfPointSystem(control.MidPoint);
1483
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1484
            DoubleCollection DashSize = control.DashSize;
1485
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1486
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1487
1488
            double Opacity = control.Opac;
1489
1490
            if (EndPoint == MidPoint)
1491
            {
1492
                Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1493
            }
1494
            else
1495
            {
1496
                Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, setColor, Opacity);
1497
            }
1498
1499
            Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, setColor, Opacity);
1500
1501
        }
1502
1503 43e1d368 taeseongkim
        private void DrawLine(S_LineControl control, PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2, System.Drawing.Color setColor)
1504 4f017ed3 taeseongkim
        {
1505
            string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1506
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1507
            Point EndPoint = GetPdfPointSystem(control.EndPoint);
1508
            DoubleCollection DashSize = control.DashSize;
1509
            List<Point> PointSet = GetPdfPointSystem(control.PointSet);
1510
1511
            var Opacity = control.Opac;
1512
            string UserID = control.UserID;
1513
            double Interval = control.Interval;
1514
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First()));
1515
            Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, setColor, Opacity);
1516
            switch (control.LineStyleSet)
1517
            {
1518
                case LineStyleSet.ArrowLine:
1519
                    Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1520
                    break;
1521
                case LineStyleSet.CancelLine:
1522
                    {
1523 43e1d368 taeseongkim
                        var x = Math.Abs((Math.Abs(control.StartPoint.X) - Math.Abs(control.EndPoint.X)));
1524
                        var y = Math.Abs((Math.Abs(control.StartPoint.Y) - Math.Abs(control.EndPoint.Y)));
1525
1526
                        Point newStartPoint = new Point();
1527
                        Point newEndPoint = new Point();
1528 4f017ed3 taeseongkim
1529
                        if (x > y)
1530
                        {
1531 43e1d368 taeseongkim
                            newStartPoint = new Point(control.StartPoint.X, control.StartPoint.Y + control.Interval);
1532
                            newEndPoint = new Point(control.EndPoint.X, control.EndPoint.Y + control.Interval);
1533 4f017ed3 taeseongkim
                        }
1534 43e1d368 taeseongkim
                        else
1535
                        {
1536
                            newStartPoint = new Point(control.StartPoint.X + control.Interval, control.StartPoint.Y);
1537
                            newEndPoint = new Point(control.EndPoint.X + control.Interval, control.EndPoint.Y);
1538
                        }
1539
1540
                        newStartPoint = GetPdfPointSystem(newStartPoint);
1541
                        newEndPoint = GetPdfPointSystem(newEndPoint);
1542
1543
                        Controls_PDF.DrawSet_Line.DrawLine(newStartPoint, newEndPoint, LineSize, contentByte, DashSize, setColor, Opacity);
1544 4f017ed3 taeseongkim
                    }
1545
                    break;
1546
                case LineStyleSet.TwinLine:
1547
                    {
1548
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1549
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1550
                    }
1551
                    break;
1552
                case LineStyleSet.DimLine:
1553
                    {
1554
                        Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1555
                        Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, setColor, Opacity);
1556
                        Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, setColor, Opacity);
1557
                    }
1558
                    break;
1559
                default:
1560
                    break;
1561
            }
1562
1563
        }
1564
1565 43e1d368 taeseongkim
        private void DrawTextBox(S_TextControl control,PdfContentByte contentByte, string[] delimiterChars, string[] delimiterChars2,System.Drawing.Color setColor)
1566 4f017ed3 taeseongkim
        {
1567
            string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1568
            string Text = control.Text;
1569
1570
            bool isUnderline = false;
1571
            control.BoxW -= scaleWidth;
1572
            control.BoxH -= scaleHeight;
1573
            System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH);
1574
            Point StartPoint = GetPdfPointSystem(control.StartPoint);
1575
            Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH));
1576
1577
            List<Point> pointSet = new List<Point>();
1578
            pointSet.Add(StartPoint);
1579
            pointSet.Add(EndPoint);
1580 43e1d368 taeseongkim
            
1581 4f017ed3 taeseongkim
            PaintSet paint = PaintSet.None;
1582
            switch (control.paintMethod)
1583
            {
1584
                case 1:
1585
                    {
1586
                        paint = PaintSet.Fill;
1587
                    }
1588
                    break;
1589
                case 2:
1590
                    {
1591
                        paint = PaintSet.Hatch;
1592
                    }
1593
                    break;
1594
                default:
1595
                    break;
1596
            }
1597
            if (control.isHighLight) paint |= PaintSet.Highlight;
1598
1599
            double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First()));
1600
            double TextSize = Convert.ToDouble(data2[1]);
1601 43e1d368 taeseongkim
            System.Drawing.Color FontColor = setColor;
1602 4f017ed3 taeseongkim
            double Angle = control.Angle;
1603
            double Opacity = control.Opac;
1604
            FontFamily fontfamilly = FontHelper.GetFontFamily(control.fontConfig[0]);
1605
            var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]);
1606
1607
            FontStyle fontStyle = FontStyles.Normal;
1608
            if (FontStyles.Italic == TextStyle)
1609
            {
1610
                fontStyle = FontStyles.Italic;
1611
            }
1612
1613
            FontWeight fontWeight = FontWeights.Black;
1614
1615
            var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]);
1616
            //강인구 수정(2018.04.17)
1617
            if (FontWeights.Bold == TextWeight)
1618
            //if (FontWeights.ExtraBold == TextWeight)
1619
            {
1620
                fontWeight = FontWeights.Bold;
1621
            }
1622
1623
            TextDecorationCollection decoration = TextDecorations.Baseline;
1624
            if (control.fontConfig.Count() == 4)
1625
            {
1626
                decoration = TextDecorations.Underline;
1627
            }
1628
1629
            Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, setColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle);
1630
        }
1631 c206d293 taeseongkim
    
1632 7ca218b3 KangIngu
1633 40cf5bf7 humkyung
        ~MarkupToPDF()
1634
        {
1635
            this.Dispose(false);
1636
        }
1637
1638
        private bool disposed;
1639
1640 7ca218b3 KangIngu
        public void Dispose()
1641
        {
1642 40cf5bf7 humkyung
            this.Dispose(true);
1643
            GC.SuppressFinalize(this);
1644
        }
1645
1646
        protected virtual void Dispose(bool disposing)
1647
        {
1648
            if (this.disposed) return;
1649
            if (disposing)
1650
            {
1651
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
1652
            }
1653
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
1654
            this.disposed = true;
1655 8c3a888c djkim
        }
1656 7f01e35f ljiyeon
1657 a1e2ba68 taeseongkim
#endregion
1658 7ca218b3 KangIngu
    }
1659
}
클립보드 이미지 추가 (최대 크기: 500 MB)