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