프로젝트

일반

사용자정보

개정판 e56c1739

IDe56c1739deb843ac28bce4c2319c7062e5ef0330
상위 515eb348
하위 e4a4f96d

백흠경이(가) 5달 전에 추가함

Fix: PDF 생성 시 ZIndex로 소팅하여 생성하도록 수정

Change-Id: I2956dadd2a80fa82fa666843934cdc791ad9dfcc

차이점 보기:

FinalService/KCOM_FinalService/MarkupToPDF/MarkupToPDF.cs
178 178

  
179 179
        }
180 180

  
181
        /// <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
            //var list = Markus.Fonts.FontHelper.GetFontStream("Arial Unicode MS");
189
            //System.Diagnostics.Debug.WriteLine(list);
190

  
191
            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 181
        #region 생성자 & 소멸자
261 182
        public void MakeFinalPDF(object _FinalPDF)
262 183
        {
......
458 379
                using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
459 380
                {
460 381
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
461

  
462 382
                    if (finalList.Count() > 0)
463 383
                    {
464 384
                        //TestFile = SetFlattingPDF(TestFile);
......
490 410
        #endregion
491 411

  
492 412
        #region PDF
493
        public static float scaleWidth = 0;
494
        public static float scaleHeight = 0;
413
        public static float scaleWidth { get; set; } = 0;
414
        public static float scaleHeight { get; set; } = 0;
495 415

  
496 416
        private string SetFlattingPDF(string tempFileInfo)
497 417
        {
......
576 496
            }
577 497
        }
578 498

  
499
        /// <summary>
500
        /// PDF에 Markup 데이터를 쓴다.
501
        /// </summary>
502
        /// <param name="finaldata"></param>
503
        /// <param name="testFile"></param>
504
        /// <param name="markupInfo"></param>
505
        /// <returns></returns>
579 506
        public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo)
580 507
        {
581 508
            try
582 509
            {
583
        
584 510
                FileInfo tempFileInfo = new FileInfo(testFile);
585 511

  
586 512
                if (!Directory.Exists(_FinalPDFStorgeLocal))
......
611 537

  
612 538
                            var dic = new Dictionary<string, object>();
613 539

  
540
                            #region  북마크 생성
614 541
                            foreach (var data in MarkupDataSet)
615 542
                            {
616 543
                                //StatusChange("MarkupDataSet", 0);
......
624 551
                                {
625 552
                                    var memberlist = KCOMDataModel.Common.ObjectQuery.GetMemberQuery(cIEntities, userid);
626 553

  
627
                                    if(memberlist.Count() > 0)
554
                                    if(memberlist.Any())
628 555
                                    {
629
                                        username = memberlist.First().NAME;
630
                                        userdept = memberlist.First().DEPARTMENT;
556
                                        username = memberlist[0].NAME;
557
                                        userdept = memberlist[0].DEPARTMENT;
631 558
                                    }
632 559
                                }
633 560

  
......
638 565
                                bookmark.Add("Kids", outlines);
639 566
                                root.Add(bookmark);
640 567
                            }
568
                            #endregion
641 569

  
642 570
                            iTextSharp.text.Version.GetInstance();
643 571

  
......
655 583
                                    SetNotice(FinalItem.ID, "this pdf is not AcroForm.");
656 584
                                }
657 585

  
586
                                #region Markup 색상을 설정한다.(DB에 값이 있으면 DB 값으로 설정한다.)
658 587
                                System.Drawing.Color _SetColor = System.Drawing.Color.FromArgb(255, System.Drawing.Color.Red);
659
                                
588
                                #endregion
660 589

  
661 590
                                string[] delimiterChars = { "|DZ|" };
662 591
                                string[] delimiterChars2 = { "|" };
......
670 599

  
671 600
                                //strLog.Append($"Write {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")} markup Count : {MarkupDataSet.Count()} / ");
672 601

  
673
                                foreach (var markupItem in MarkupDataSet)
602
                                var groups = MarkupDataSet.GroupBy(x => x.PAGENUMBER);
603
                                foreach (var group in groups)
674 604
                                {
675
                                    /// 2020.11.13 김태성
676
                                    /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함.
677
                                    var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER);
605
                                    int PageNumber = group.Key;
606
                                    #region ZIndex 값으로 정렬한다.
607
                                    var items = new List<Tuple<string, S_BaseControl>>();
608
                                    foreach (var item in group)
609
                                    {
610
                                        var tokens = item.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries).ToList();
611
                                        items.AddRange(tokens.ConvertAll(x =>
612
                                        {
613
                                            var str = JsonSerializerHelper.UnCompressString(x);
614
                                            var control = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(str);
615
                                            return new Tuple<string, S_BaseControl>(str, control);
616
                                        }));
617
                                    }
618

  
619
                                    var ordered = items.OrderBy(x => x.Item2.ZIndex);
620
                                    #endregion
678 621

  
679
                                    if (pageitems.Count() > 0)
622
                                    foreach (var order in ordered)
680 623
                                    {
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))
624
                                        /// 2020.11.13 김태성
625
                                        /// 원본 PDF의 페이지수가 변경된 경우 이전 markup의 페이지를 찾지 못해 수정함.
626
                                        var pageitems = DocPageItem.Where(d => d.PAGE_NUMBER == PageNumber);
627
                                        if (pageitems.Any())
703 628
                                        {
704
                                            PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER);
629
                                            var currentPage = pageitems.First();
630
                                            pdfSize = pdfReader.GetPageSizeWithRotation(PageNumber);
631
                                            lastPageNo = PageNumber;
705 632

  
706
                                            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);
633
                                            mediaBox = pdfReader.GetPageSize(PageNumber);
634
                                            var cropBox = pdfReader.GetCropBox(PageNumber);
712 635

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

  
716
                                        scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
717
                                        scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
642
                                                PdfArray oNewMediaBox = new PdfArray();
643
                                                oNewMediaBox.Add(new PdfNumber(cropBox.Left));
644
                                                oNewMediaBox.Add(new PdfNumber(cropBox.Top));
645
                                                oNewMediaBox.Add(new PdfNumber(cropBox.Right));
646
                                                oNewMediaBox.Add(new PdfNumber(cropBox.Bottom));
647
                                                dict.Put(PdfName.MEDIABOX, oNewMediaBox);
718 648

  
719
                                        pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER;
720
                                        _entity.SaveChanges();
649
                                                pdfSize = cropBox;
650
                                            }
721 651

  
722
                                        string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
652
                                            scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width;
653
                                            scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height;
723 654

  
724
                                        PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER);
725
                                        //strLog.Append($"p.{markupItem.PAGENUMBER}:{markupItem.DATA_TYPE}/");
655
                                            pdfLink.CURRENT_PAGE = PageNumber;
656
                                            _entity.SaveChanges();
726 657

  
727
                                        foreach (var data in markedData)
728
                                        {
729
                                            var item = JsonSerializerHelper.UnCompressString(data);
730
                                            var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item);
658
                                            PdfContentByte contentByte = pdfStamper.GetOverContent(PageNumber);
659
                                            var item = order.Item1;
660
                                            var ControlT = order.Item2;
731 661

  
732 662
                                            try
733 663
                                            {
......
766 696
                                                            double Opacity = control.Opac;
767 697
                                                            DoubleCollection DashSize = control.DashSize;
768 698

  
769
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor,PaintStyle| PaintSet.Outline, Opacity);
699
                                                            Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle | PaintSet.Outline, Opacity);
770 700
                                                            //Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity);
771 701
                                                        }
772 702
                                                        break;
......
881 811
                                                            bool reverse = (area < 0);
882 812

  
883 813
                                                            Controls_PDF.DrawSet_Cloud.DrawCloudRect(PointSet, LineSize, (int)rotate, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity);
884
                                                       }
814
                                                        }
885 815
                                                        break;
886 816
                                                    #endregion
887 817
                                                    #region CloudControl
......
1190 1120
                                                                var xamldata = Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(stamp.First().VALUE);
1191 1121

  
1192 1122
                                                                var Contents = _entity.PROPERTIES.Where(x => x.TYPE == "STAMP_CONTENTS");
1193
                                                                
1123

  
1194 1124
                                                                if (Contents?.Count() > 0)
1195 1125
                                                                {
1196 1126
                                                                    foreach (var content in Contents)
......
1247 1177
                                            }
1248 1178
                                            catch (Exception ex)
1249 1179
                                            {
1250
                                                StatusChange($"markupItem : {markupItem.ID}" + ex.ToString(), 0);
1180
                                                StatusChange($"markupItem : {ControlT.Name}" + ex.ToString(), 0);
1251 1181
                                            }
1252 1182
                                            finally
1253 1183
                                            {
......
1257 1187
                                                //}
1258 1188
                                            }
1259 1189
                                        }
1260

  
1261 1190
                                    }
1262 1191
                                }
1263 1192

  

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)