markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ 9dec2e0a
이력 | 보기 | 이력해설 | 다운로드 (69.2 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 | using System; |
||
9 | using System.Collections.Generic; |
||
10 | 7f01e35f | ljiyeon | using System.Configuration; |
11 | 7ca218b3 | KangIngu | using System.IO; |
12 | using System.Linq; |
||
13 | using System.Net; |
||
14 | 7f01e35f | ljiyeon | using System.Runtime.InteropServices; |
15 | 7ca218b3 | KangIngu | using System.Text; |
16 | e05bed4e | djkim | using System.Web; |
17 | 7ca218b3 | KangIngu | using System.Windows; |
18 | using System.Windows.Media; |
||
19 | |||
20 | namespace MarkupToPDF |
||
21 | { |
||
22 | public class MarkupToPDF : IDisposable |
||
23 | { |
||
24 | #region 초기 데이터 |
||
25 | private static iTextSharp.text.Rectangle mediaBox; |
||
26 | private FileInfo PdfFilePath = null; |
||
27 | private FileInfo FinalPDFPath = null; |
||
28 | private string _FinalPDFStorgeLocal = null; |
||
29 | private string _FinalPDFStorgeRemote = null; |
||
30 | private string OriginFileName = null; |
||
31 | 8c3a888c | djkim | public FINAL_PDF FinalItem; |
32 | public DOCINFO DocInfoItem = null; |
||
33 | public List<DOCPAGE> DocPageItem = null; |
||
34 | public MARKUP_INFO MarkupInfoItem = null; |
||
35 | public List<MARKUP_DATA> MarkupDataSet = null; |
||
36 | 7ca218b3 | KangIngu | //private string _PrintPDFStorgeLocal = null; |
37 | //private string _PrintPDFStorgeRemote = null; |
||
38 | public event EventHandler<MakeFinalErrorArgs> FinalMakeError; |
||
39 | public event EventHandler<EndFinalEventArgs> EndFinal; |
||
40 | |||
41 | private iTextSharp.text.Rectangle pdfSize { get; set; } |
||
42 | private double pageW = 0; |
||
43 | private double pageH = 0; |
||
44 | |||
45 | //private const double zoomLevel = 3.0; |
||
46 | private const double zoomLevel = 1.0; // 지금은 3배수로 곱하지 않고 있음 |
||
47 | #endregion |
||
48 | |||
49 | #region 메서드 |
||
50 | public static bool IsLocalIPAddress(string host) |
||
51 | { |
||
52 | try |
||
53 | { |
||
54 | IPAddress[] hostIPs = Dns.GetHostAddresses(host); |
||
55 | IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); |
||
56 | |||
57 | foreach (IPAddress hostIP in hostIPs) |
||
58 | { |
||
59 | if (IPAddress.IsLoopback(hostIP)) return true; |
||
60 | |||
61 | foreach (IPAddress localIP in localIPs) |
||
62 | { |
||
63 | if (hostIP.Equals(localIP)) return true; |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | catch { } |
||
68 | return false; |
||
69 | } |
||
70 | |||
71 | 8c3a888c | djkim | private void SetNotice(string finalID, string message) |
72 | 7ca218b3 | KangIngu | { |
73 | if (FinalMakeError != null) |
||
74 | { |
||
75 | FinalMakeError(this, new MakeFinalErrorArgs { FinalID = finalID, Message = message }); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | private string GetFileName(string hrefLink) |
||
80 | { |
||
81 | e05bed4e | djkim | try |
82 | { |
||
83 | if (hrefLink.Contains("vpcs_doclib")) |
||
84 | { |
||
85 | return System.IO.Path.GetFileName(hrefLink.Replace("/", "\\")); |
||
86 | } |
||
87 | else |
||
88 | { |
||
89 | Uri fileurl = new Uri(hrefLink); |
||
90 | int index = hrefLink.IndexOf("?"); |
||
91 | string filename = HttpUtility.ParseQueryString(fileurl.Query).Get("fileName"); |
||
92 | return filename; |
||
93 | } |
||
94 | } |
||
95 | catch (Exception ex) |
||
96 | { |
||
97 | throw ex; |
||
98 | } |
||
99 | 7ca218b3 | KangIngu | } |
100 | |||
101 | public Point GetPdfPointSystem(Point point) |
||
102 | { |
||
103 | 9dec2e0a | humkyung | /// 주어진 좌표를 pdf의 (Left, Top - Bottom(?)) 좌표에 맞추어 변환한다. |
104 | return new Point(pdfSize.Left + (float)(point.X / scaleWidth), pdfSize.Top - (float)(point.Y / scaleHeight) - pdfSize.Bottom); |
||
105 | 7ca218b3 | KangIngu | } |
106 | |||
107 | 488ba687 | humkyung | public double GetPdfSize(double size) |
108 | { |
||
109 | return (size / scaleWidth); |
||
110 | } |
||
111 | |||
112 | 8c3a888c | djkim | public List<Point> GetPdfPointSystem(List<Point> point) |
113 | 7ca218b3 | KangIngu | { |
114 | List<Point> dummy = new List<Point>(); |
||
115 | foreach (var item in point) |
||
116 | { |
||
117 | dummy.Add(GetPdfPointSystem(item)); |
||
118 | } |
||
119 | return dummy; |
||
120 | } |
||
121 | |||
122 | public double returnAngle(Point start, Point end) |
||
123 | { |
||
124 | double angle = MathSet.getAngle(start.X, start.Y, end.X, end.Y); |
||
125 | //angle *= -1; |
||
126 | |||
127 | angle += 90; |
||
128 | //if (angle < 0) |
||
129 | //{ |
||
130 | // angle = angle + 360; |
||
131 | //} |
||
132 | return angle; |
||
133 | } |
||
134 | |||
135 | #endregion |
||
136 | |||
137 | #region 생성자 & 소멸자 |
||
138 | public void MakeFinalPDF(object _FinalPDF) |
||
139 | { |
||
140 | 8c3a888c | djkim | |
141 | DOCUMENT_ITEM documentItem; |
||
142 | FINAL_PDF FinalPDF = (FINAL_PDF)_FinalPDF; |
||
143 | 7ca218b3 | KangIngu | FinalItem = FinalPDF; |
144 | |||
145 | |||
146 | string PdfFilePathRoot = null; |
||
147 | string TestFile = System.IO.Path.GetTempFileName(); |
||
148 | |||
149 | #region 문서 경로를 가져오는 것과 Status를 Create (1단계) 로 수정 |
||
150 | 488ba687 | humkyung | try |
151 | 7ca218b3 | KangIngu | { |
152 | 8c3a888c | djkim | using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
153 | 7ca218b3 | KangIngu | { |
154 | 8c3a888c | djkim | var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == FinalPDF.PROJECT_NO); |
155 | |||
156 | if (_properties.Count() > 0) |
||
157 | 7ca218b3 | KangIngu | { |
158 | 8c3a888c | djkim | PdfFilePathRoot = _properties.Where(t => t.TYPE == PropertiesType.Const_TileSorcePath).First().VALUE; |
159 | 7ca218b3 | KangIngu | _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE; |
160 | _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE; |
||
161 | } |
||
162 | else |
||
163 | { |
||
164 | SetNotice(FinalPDF.ID, "프로퍼티를 가지고 올 수 없습니다."); |
||
165 | return; |
||
166 | } |
||
167 | e0f00e26 | djkim | var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID); |
168 | 8c3a888c | djkim | if (finalList.Count() > 0) |
169 | { |
||
170 | finalList.FirstOrDefault().START_DATETIME = DateTime.Now; |
||
171 | finalList.FirstOrDefault().STATUS = (int)FinalStatus.Create; |
||
172 | _entity.SaveChanges(); |
||
173 | } |
||
174 | e0f00e26 | djkim | |
175 | 8c3a888c | djkim | } |
176 | 7ca218b3 | KangIngu | } |
177 | catch (Exception ex) |
||
178 | { |
||
179 | SetNotice(FinalPDF.ID, "프로퍼티 에러: " + ex.ToString()); |
||
180 | return; |
||
181 | } |
||
182 | #endregion |
||
183 | |||
184 | #region 문서 복사 |
||
185 | try |
||
186 | { |
||
187 | 8c3a888c | djkim | using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(FinalPDF.PROJECT_NO).ToString())) |
188 | 7ca218b3 | KangIngu | { |
189 | 8c3a888c | djkim | var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == FinalPDF.DOCINFO_ID); |
190 | 7ca218b3 | KangIngu | |
191 | 8c3a888c | djkim | if (_DOCINFO.Count() > 0) |
192 | 7ca218b3 | KangIngu | { |
193 | 8c3a888c | djkim | DocInfoItem = _DOCINFO.FirstOrDefault(); |
194 | DocPageItem = DocInfoItem.DOCPAGE.ToList(); |
||
195 | 7ca218b3 | KangIngu | |
196 | PdfFilePathRoot = PdfFilePathRoot + @"\" + FinalPDF.PROJECT_NO + "_Tile" + @"\" |
||
197 | + (System.Convert.ToInt64(FinalPDF.DOCUMENT_ID) / 100).ToString() |
||
198 | + @"\" + FinalPDF.DOCUMENT_ID + @"\"; |
||
199 | |||
200 | 8c3a888c | djkim | MarkupInfoItem = DocInfoItem.MARKUP_INFO.Where(data => data.CONSOLIDATE == 1 && data.AVOID_CONSOLIDATE == 0 && data.PART_CONSOLIDATE == 0).FirstOrDefault(); |
201 | 7ca218b3 | KangIngu | |
202 | if (MarkupInfoItem == null) |
||
203 | { |
||
204 | throw new Exception("콘솔리데잇이 작업 요청 후에 수정 / 삭제 되었습니다"); |
||
205 | } |
||
206 | else |
||
207 | { |
||
208 | 8c3a888c | djkim | if (MarkupInfoItem.MARKUP_INFO_VERSION.Count > 0) |
209 | { |
||
210 | MarkupDataSet = MarkupInfoItem.MARKUP_INFO_VERSION.OrderBy(d => d.CREATE_DATE).LastOrDefault().MARKUP_DATA.ToList().OrderBy(d => d.PAGENUMBER).ToList(); |
||
211 | } |
||
212 | else |
||
213 | 7ca218b3 | KangIngu | { |
214 | throw new Exception("MARKUP_INFO_VERSION 이 존재 하지 않습니다"); |
||
215 | 8c3a888c | djkim | } |
216 | 6c9fec59 | djkim | } |
217 | 7ca218b3 | KangIngu | |
218 | e0f00e26 | djkim | documentItem = _entity.DOCUMENT_ITEM.Where(data => data.DOCUMENT_ID == DocInfoItem.DOCUMENT_ID).FirstOrDefault(); |
219 | if (documentItem == null) |
||
220 | 6c9fec59 | djkim | { |
221 | e0f00e26 | djkim | throw new Exception("DocInfo와 DocumentItem의 documentItemID가 같지 않습니다. 데이터를 확인해주세요"); |
222 | } |
||
223 | 8c3a888c | djkim | |
224 | e0f00e26 | djkim | var _files = new DirectoryInfo(PdfFilePathRoot).GetFiles("*.pdf"); //해당 폴더에 파일을 |
225 | 8c3a888c | djkim | |
226 | e0f00e26 | djkim | #region 파일 체크 |
227 | if (_files.Count() == 1) |
||
228 | { |
||
229 | if (_files.First().Name.ToLower() == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower())) |
||
230 | 7ca218b3 | KangIngu | { |
231 | e0f00e26 | djkim | OriginFileName = _files.First().Name; |
232 | PdfFilePath = _files.First().CopyTo(TestFile, true); |
||
233 | 7ca218b3 | KangIngu | } |
234 | 6c9fec59 | djkim | else |
235 | 7ca218b3 | KangIngu | { |
236 | e0f00e26 | djkim | throw new Exception("현재 폴더 내 파일명이 데이터베이스와 상이합니다.filename:" + _files.First().Name.ToLower() + ",url:" + HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE).ToLower()); |
237 | 7ca218b3 | KangIngu | } |
238 | e0f00e26 | djkim | } |
239 | else if (_files.Count() > 1) |
||
240 | { |
||
241 | var originalFile = _files.Where(data => data.Name == GetFileName(HttpUtility.UrlDecode(documentItem.ORIGINAL_FILE))).FirstOrDefault(); |
||
242 | 6c9fec59 | djkim | |
243 | e0f00e26 | djkim | if (originalFile == null) |
244 | 8c3a888c | djkim | { |
245 | e0f00e26 | djkim | throw new Exception("해당 폴더에 복수로 PDF들 존재하고 document_Item의 문서는 존재하지 않습니다"); |
246 | 8c3a888c | djkim | } |
247 | e0f00e26 | djkim | else |
248 | 8c3a888c | djkim | { |
249 | e0f00e26 | djkim | OriginFileName = originalFile.Name; |
250 | PdfFilePath = originalFile.CopyTo(TestFile, true); |
||
251 | 8c3a888c | djkim | } |
252 | 6c9fec59 | djkim | } |
253 | e0f00e26 | djkim | else |
254 | { |
||
255 | throw new Exception("PDF를 찾지 못하였습니다"); |
||
256 | } |
||
257 | #endregion |
||
258 | |||
259 | #region 예외처리 |
||
260 | if (PdfFilePath == null) |
||
261 | { |
||
262 | throw new Exception("작업에 필요한 PDF가 정상적으로 복사되지 않았거나 DB정보가 상이합니다"); |
||
263 | } |
||
264 | if (!PdfFilePath.Exists) |
||
265 | { |
||
266 | throw new Exception("PDF원본이 존재하지 않습니다"); |
||
267 | } |
||
268 | #endregion |
||
269 | |||
270 | 7ca218b3 | KangIngu | } |
271 | else |
||
272 | { |
||
273 | throw new Exception("일치하는 DocInfo가 없습니다"); |
||
274 | } |
||
275 | } |
||
276 | } |
||
277 | catch (Exception ex) |
||
278 | { |
||
279 | if (ex.Message == "사용 가능한" || ex.Message == "작업을 완료했습니다") |
||
280 | { |
||
281 | SetNotice(FinalPDF.ID, "Desktop 내 힙메모리 부족으로 서비스 진행이 되지 않아 재시작 합니다"); |
||
282 | System.Diagnostics.Process process = new System.Diagnostics.Process(); |
||
283 | process.StartInfo.FileName = "cmd"; |
||
284 | process.StartInfo.Arguments = "/c net stop \"FinalService\" & net start \"FinalService\""; |
||
285 | process.Start(); |
||
286 | } |
||
287 | else |
||
288 | { |
||
289 | SetNotice(FinalPDF.ID, "PDF를 Stamp 중 에러 : " + ex.Message); |
||
290 | } |
||
291 | } |
||
292 | #endregion |
||
293 | |||
294 | try |
||
295 | { |
||
296 | |||
297 | 8c3a888c | djkim | using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString())) |
298 | { |
||
299 | var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID); |
||
300 | |||
301 | if (finalList.Count() > 0) |
||
302 | 7ca218b3 | KangIngu | { |
303 | 8c3a888c | djkim | TestFile = SetFlattingPDF(TestFile); |
304 | //finalList.FirstOrDefault().STATUS = (int)FinalStatus.Insert; |
||
305 | //_entity.SaveChanges(); |
||
306 | |||
307 | SetStampInPDF(FinalItem, TestFile, MarkupInfoItem); |
||
308 | //finalList.FirstOrDefault().STATUS = (int)FinalStatus.PdfStamp; |
||
309 | //_entity.SaveChanges(); |
||
310 | 7ca218b3 | KangIngu | } |
311 | 8c3a888c | djkim | } |
312 | if (EndFinal != null) |
||
313 | { |
||
314 | EndFinal(this, new EndFinalEventArgs |
||
315 | { |
||
316 | OriginPDFName = OriginFileName, |
||
317 | FinalPDFPath = FinalPDFPath.FullName, |
||
318 | Error = "", |
||
319 | Message = "", |
||
320 | FinalPDF = FinalPDF, |
||
321 | }); |
||
322 | } |
||
323 | 7ca218b3 | KangIngu | } |
324 | catch (Exception ex) |
||
325 | { |
||
326 | |||
327 | throw; |
||
328 | } |
||
329 | } |
||
330 | #endregion |
||
331 | |||
332 | #region PDF |
||
333 | 4804a4fb | humkyung | public static float scaleWidth = 0; |
334 | public static float scaleHeight = 0; |
||
335 | 8c3a888c | djkim | |
336 | 7ca218b3 | KangIngu | private string SetFlattingPDF(string tempFileInfo) |
337 | { |
||
338 | if (File.Exists(tempFileInfo)) |
||
339 | { |
||
340 | FileInfo TestFile = new FileInfo(System.IO.Path.GetTempFileName()); |
||
341 | |||
342 | PdfReader pdfReader = new PdfReader(tempFileInfo); |
||
343 | for (int i = 1; i < pdfReader.NumberOfPages; i++) |
||
344 | { |
||
345 | var mediaBox = pdfReader.GetPageSize(i); |
||
346 | var cropbox = pdfReader.GetCropBox(i); |
||
347 | |||
348 | 8c3a888c | djkim | //using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString().ToString())) |
349 | //{ |
||
350 | // _entity.DOCPAGE.Where(d=>d.DOCINFO_ID == DocInfoItem.DOCPAGE) |
||
351 | //} |
||
352 | 7ca218b3 | KangIngu | var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == i).FirstOrDefault(); |
353 | |||
354 | 8c3a888c | djkim | //scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / mediaBox.Width; |
355 | //scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / mediaBox.Height; |
||
356 | //scaleWidth = 2.0832634F; |
||
357 | //scaleHeight = 3.0F; |
||
358 | |||
359 | 7ca218b3 | KangIngu | PdfRectangle rect = new PdfRectangle(cropbox, pdfReader.GetPageRotation(i)); |
360 | 8c3a888c | djkim | //강인구 수정 |
361 | //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < cropbox.Height)) |
||
362 | //if (cropbox != null && (cropbox.Width < mediaBox.Width || cropbox.Height < mediaBox.Height)) |
||
363 | //{ |
||
364 | // var pageDict = pdfReader.GetPageN(i); |
||
365 | // pageDict.Put(PdfName.MEDIABOX, rect); |
||
366 | //} |
||
367 | 7ca218b3 | KangIngu | } |
368 | |||
369 | var memStream = new MemoryStream(); |
||
370 | var stamper = new PdfStamper(pdfReader, memStream) |
||
371 | { |
||
372 | FormFlattening = true, |
||
373 | FreeTextFlattening = true, |
||
374 | AnnotationFlattening = true, |
||
375 | }; |
||
376 | |||
377 | stamper.Close(); |
||
378 | pdfReader.Close(); |
||
379 | var array = memStream.ToArray(); |
||
380 | File.Delete(tempFileInfo); |
||
381 | File.WriteAllBytes(TestFile.FullName, array); |
||
382 | |||
383 | return TestFile.FullName; |
||
384 | } |
||
385 | else |
||
386 | { |
||
387 | return tempFileInfo; |
||
388 | } |
||
389 | } |
||
390 | |||
391 | public void flattenPdfFile(string src, ref string dest) |
||
392 | { |
||
393 | PdfReader reader = new PdfReader(src); |
||
394 | var memStream = new MemoryStream(); |
||
395 | var stamper = new PdfStamper(reader, memStream) |
||
396 | { |
||
397 | FormFlattening = true, |
||
398 | FreeTextFlattening = true, |
||
399 | AnnotationFlattening = true, |
||
400 | }; |
||
401 | |||
402 | stamper.Close(); |
||
403 | var array = memStream.ToArray(); |
||
404 | File.WriteAllBytes(dest, array); |
||
405 | } |
||
406 | 8c3a888c | djkim | |
407 | public bool SetStampInPDF(FINAL_PDF finaldata, string testFile, MARKUP_INFO markupInfo) |
||
408 | 7ca218b3 | KangIngu | { |
409 | e0f00e26 | djkim | try |
410 | 8c3a888c | djkim | { |
411 | e0f00e26 | djkim | string pdfFilePath = null; |
412 | List<MEMBER> memberlist = null; |
||
413 | FileInfo tempFileInfo = new FileInfo(testFile); |
||
414 | abaa85b4 | djkim | |
415 | e0f00e26 | djkim | if (!Directory.Exists(_FinalPDFStorgeLocal)) |
416 | 8c3a888c | djkim | { |
417 | e0f00e26 | djkim | Directory.CreateDirectory(_FinalPDFStorgeLocal); |
418 | } |
||
419 | pdfFilePath = _FinalPDFStorgeLocal + @"\" + tempFileInfo.Name; |
||
420 | using (CIEntities cIEntities = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(finaldata.PROJECT_NO).ToString())) |
||
421 | { |
||
422 | memberlist = cIEntities.MEMBER.ToList(); |
||
423 | } |
||
424 | using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
||
425 | { |
||
426 | FINAL_PDF pdfLink = _entity.FINAL_PDF.Where(data => data.ID == finaldata.ID).FirstOrDefault(); |
||
427 | 7ca218b3 | KangIngu | |
428 | e0f00e26 | djkim | #region 코멘트 적용 + 커버시트 |
429 | using (Stream pdfStream = new FileInfo(testFile).Open(FileMode.Open, FileAccess.ReadWrite)) // |
||
430 | 8c3a888c | djkim | { |
431 | e0f00e26 | djkim | PdfReader pdfReader = new PdfReader(pdfStream); |
432 | //List<Dictionary<string, object>> lstoutlineTop = new List<Dictionary<string, object>>(); |
||
433 | Dictionary<string, object> bookmark; |
||
434 | List<Dictionary<string, object>> outlines; |
||
435 | outlines = new List<Dictionary<string, object>>(); |
||
436 | List<Dictionary<string, object>> root = new List<Dictionary<string, object>>(); |
||
437 | |||
438 | var dic = new Dictionary<string, object>(); |
||
439 | foreach (var data in MarkupDataSet) |
||
440 | { |
||
441 | abaa85b4 | djkim | |
442 | e0f00e26 | djkim | string userid = data.MARKUP_INFO_VERSION.MARKUP_INFO.USER_ID; |
443 | |||
444 | var member = memberlist.Where(u => u.ID == userid).FirstOrDefault(); |
||
445 | string username = member.NAME; |
||
446 | string userdept = member.DEPARTMENT; |
||
447 | bookmark = new Dictionary<string, object>(); |
||
448 | bookmark.Add("Title", string.Format("User:{0}[{1}] Commented Page : {2}", username, userdept, data.PAGENUMBER)); |
||
449 | bookmark.Add("Page", data.PAGENUMBER + " Fit"); |
||
450 | bookmark.Add("Action", "GoTo"); |
||
451 | bookmark.Add("Kids", outlines); |
||
452 | root.Add(bookmark); |
||
453 | } |
||
454 | abaa85b4 | djkim | |
455 | |||
456 | e0f00e26 | djkim | using (PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pdfFilePath, FileMode.Create))) |
457 | 8c3a888c | djkim | { |
458 | e0f00e26 | djkim | var _SetColor = new SolidColorBrush(Colors.Red); |
459 | 7ca218b3 | KangIngu | |
460 | e0f00e26 | djkim | string[] delimiterChars = { "|DZ|" }; |
461 | string[] delimiterChars2 = { "|" }; |
||
462 | 7ca218b3 | KangIngu | |
463 | e0f00e26 | djkim | //pdfStamper.FormFlattening = true; //이미 선처리 작업함 |
464 | pdfStamper.SetFullCompression(); |
||
465 | _SetColor = new SolidColorBrush(Colors.Red); |
||
466 | 7ca218b3 | KangIngu | |
467 | e0f00e26 | djkim | foreach (var markupItem in MarkupDataSet) |
468 | 8c3a888c | djkim | { |
469 | e0f00e26 | djkim | pdfSize = pdfReader.GetPageSizeWithRotation(markupItem.PAGENUMBER); |
470 | var currentPage = DocPageItem.Where(d => d.PAGE_NUMBER == markupItem.PAGENUMBER).FirstOrDefault(); |
||
471 | 7ca218b3 | KangIngu | |
472 | e0f00e26 | djkim | mediaBox = pdfReader.GetPageSize(markupItem.PAGENUMBER); |
473 | 9dec2e0a | humkyung | mediaBox = mediaBox.Rotate(); |
474 | e0f00e26 | djkim | var cropBox = pdfReader.GetCropBox(markupItem.PAGENUMBER); |
475 | 7ca218b3 | KangIngu | |
476 | e0f00e26 | djkim | //강인구 테스트 |
477 | scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width; |
||
478 | scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height; |
||
479 | 7ca218b3 | KangIngu | |
480 | 9dec2e0a | humkyung | //if (cropBox != null && cropBox.Width < mediaBox.Width || cropBox.Height < mediaBox.Height) |
481 | //{ |
||
482 | // mediaBox = cropBox; |
||
483 | //} |
||
484 | 7ca218b3 | KangIngu | |
485 | e0f00e26 | djkim | pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER; |
486 | _entity.SaveChanges(); |
||
487 | 8c3a888c | djkim | |
488 | e0f00e26 | djkim | string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
489 | |||
490 | PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER); |
||
491 | |||
492 | |||
493 | foreach (var data in markedData) |
||
494 | 7ca218b3 | KangIngu | { |
495 | e0f00e26 | djkim | var item = JsonSerializerHelper.UnCompressString(data); |
496 | var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); |
||
497 | |||
498 | try |
||
499 | 8c3a888c | djkim | { |
500 | e0f00e26 | djkim | switch (ControlT.Name) |
501 | { |
||
502 | #region LINE |
||
503 | case "LineControl": |
||
504 | 7ca218b3 | KangIngu | { |
505 | e0f00e26 | djkim | using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item)) |
506 | 8c3a888c | djkim | { |
507 | e0f00e26 | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
508 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
509 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
510 | DoubleCollection DashSize = control.DashSize; |
||
511 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
512 | |||
513 | var Opacity = control.Opac; |
||
514 | string UserID = control.UserID; |
||
515 | double Interval = control.Interval; |
||
516 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
517 | Controls_PDF.HoneyPDFLib_DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, _SetColor, Opacity); |
||
518 | switch (control.LineStyleSet) |
||
519 | { |
||
520 | case LineStyleSet.ArrowLine: |
||
521 | 3c71b3a5 | taeseongkim | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
522 | e0f00e26 | djkim | break; |
523 | case LineStyleSet.CancelLine: |
||
524 | 8c3a888c | djkim | { |
525 | e0f00e26 | djkim | var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X))); |
526 | var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y))); |
||
527 | |||
528 | if (x > y) |
||
529 | { |
||
530 | StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0)); |
||
531 | EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0)); |
||
532 | Controls_PDF.HoneyPDFLib_DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, Opacity); |
||
533 | } |
||
534 | 8c3a888c | djkim | } |
535 | e0f00e26 | djkim | break; |
536 | case LineStyleSet.TwinLine: |
||
537 | { |
||
538 | 3c71b3a5 | taeseongkim | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
539 | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
||
540 | e0f00e26 | djkim | } |
541 | break; |
||
542 | case LineStyleSet.DimLine: |
||
543 | { |
||
544 | 3c71b3a5 | taeseongkim | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
545 | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
||
546 | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
||
547 | e0f00e26 | djkim | } |
548 | break; |
||
549 | default: |
||
550 | break; |
||
551 | } |
||
552 | 7ca218b3 | KangIngu | |
553 | |||
554 | e0f00e26 | djkim | } |
555 | 8c3a888c | djkim | } |
556 | e0f00e26 | djkim | break; |
557 | #endregion |
||
558 | #region ArrowControlMulti |
||
559 | case "ArrowControl_Multi": |
||
560 | 8c3a888c | djkim | { |
561 | e0f00e26 | djkim | using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item)) |
562 | { |
||
563 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
564 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
565 | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
||
566 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
567 | DoubleCollection DashSize = control.DashSize; |
||
568 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
569 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
570 | abaa85b4 | djkim | |
571 | e0f00e26 | djkim | double Opacity = control.Opac; |
572 | abaa85b4 | djkim | |
573 | e0f00e26 | djkim | if (EndPoint == MidPoint) |
574 | { |
||
575 | e68712b6 | humkyung | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
576 | e0f00e26 | djkim | } |
577 | else |
||
578 | { |
||
579 | e68712b6 | humkyung | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
580 | e0f00e26 | djkim | } |
581 | 7ca218b3 | KangIngu | |
582 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
583 | abaa85b4 | djkim | |
584 | e0f00e26 | djkim | } |
585 | 8c3a888c | djkim | } |
586 | e0f00e26 | djkim | break; |
587 | #endregion |
||
588 | #region PolyControl |
||
589 | case "PolygonControl": |
||
590 | using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item)) |
||
591 | 7ca218b3 | KangIngu | { |
592 | 8c3a888c | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
593 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
594 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
595 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
596 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
597 | e0f00e26 | djkim | double Opacity = control.Opac; |
598 | DoubleCollection DashSize = control.DashSize; |
||
599 | 8c3a888c | djkim | |
600 | Controls_PDF.HoneyPDFLib_DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
||
601 | } |
||
602 | e0f00e26 | djkim | break; |
603 | #endregion |
||
604 | #region ArcControl |
||
605 | case "ArcControl": |
||
606 | 8c3a888c | djkim | { |
607 | e0f00e26 | djkim | using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item)) |
608 | abaa85b4 | djkim | { |
609 | e0f00e26 | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
610 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
611 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
612 | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
||
613 | DoubleCollection DashSize = control.DashSize; |
||
614 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
615 | |||
616 | var Opacity = control.Opac; |
||
617 | string UserID = control.UserID; |
||
618 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
619 | bool IsTransOn = control.IsTransOn; |
||
620 | |||
621 | if (control.IsTransOn) |
||
622 | 8c3a888c | djkim | { |
623 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
624 | Controls_PDF.HoneyPDFLib_DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
||
625 | 8c3a888c | djkim | } |
626 | else |
||
627 | { |
||
628 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity); |
629 | 8c3a888c | djkim | } |
630 | e0f00e26 | djkim | |
631 | abaa85b4 | djkim | } |
632 | 8c3a888c | djkim | } |
633 | e0f00e26 | djkim | break; |
634 | #endregion |
||
635 | #region RectangleControl |
||
636 | case "RectangleControl": |
||
637 | using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item)) |
||
638 | 7ca218b3 | KangIngu | { |
639 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
640 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
641 | var PaintStyle = control.PaintState; |
||
642 | double Angle = control.Angle; |
||
643 | DoubleCollection DashSize = control.DashSize; |
||
644 | double Opacity = control.Opac; |
||
645 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
646 | |||
647 | Controls_PDF.HoneyPDFLib_DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
||
648 | 7ca218b3 | KangIngu | } |
649 | e0f00e26 | djkim | break; |
650 | #endregion |
||
651 | #region TriControl |
||
652 | case "TriControl": |
||
653 | using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item)) |
||
654 | 7ca218b3 | KangIngu | { |
655 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
656 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
657 | var PaintStyle = control.Paint; |
||
658 | double Angle = control.Angle; |
||
659 | //StrokeColor = _SetColor, //색상은 레드 |
||
660 | DoubleCollection DashSize = control.DashSize; |
||
661 | double Opacity = control.Opac; |
||
662 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
663 | 7ca218b3 | KangIngu | |
664 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
665 | 7ca218b3 | KangIngu | } |
666 | e0f00e26 | djkim | break; |
667 | #endregion |
||
668 | #region CircleControl |
||
669 | case "CircleControl": |
||
670 | using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item)) |
||
671 | 7ca218b3 | KangIngu | { |
672 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
673 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
674 | var StartPoint = GetPdfPointSystem(control.StartPoint); |
||
675 | var EndPoint = GetPdfPointSystem(control.EndPoint); |
||
676 | var PaintStyle = control.PaintState; |
||
677 | double Angle = control.Angle; |
||
678 | DoubleCollection DashSize = control.DashSize; |
||
679 | double Opacity = control.Opac; |
||
680 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
681 | Controls_PDF.HoneyPDFLib_DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet); |
||
682 | |||
683 | 7ca218b3 | KangIngu | } |
684 | e0f00e26 | djkim | break; |
685 | #endregion |
||
686 | #region RectCloudControl |
||
687 | case "RectCloudControl": |
||
688 | using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item)) |
||
689 | { |
||
690 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
691 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
692 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
693 | double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
694 | |||
695 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
696 | |||
697 | var PaintStyle = control.PaintState; |
||
698 | double Opacity = control.Opac; |
||
699 | DoubleCollection DashSize = control.DashSize; |
||
700 | 7ca218b3 | KangIngu | |
701 | e0f00e26 | djkim | //드로잉 방식이 표현되지 않음 |
702 | var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
703 | |||
704 | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
||
705 | bool reverse = (area < 0); |
||
706 | if (PaintStyle == PaintSet.None) |
||
707 | { |
||
708 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
709 | } |
||
710 | else |
||
711 | { |
||
712 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
713 | } |
||
714 | } |
||
715 | break; |
||
716 | #endregion |
||
717 | #region CloudControl |
||
718 | case "CloudControl": |
||
719 | using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item)) |
||
720 | 7ca218b3 | KangIngu | { |
721 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
722 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
723 | double Toler = control.Toler; |
||
724 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
725 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
726 | var PaintStyle = control.PaintState; |
||
727 | double Opacity = control.Opac; |
||
728 | bool isTransOn = control.IsTrans; |
||
729 | bool isChain = control.IsChain; |
||
730 | |||
731 | DoubleCollection DashSize = control.DashSize; |
||
732 | |||
733 | if (isChain) |
||
734 | { |
||
735 | Controls_PDF.HoneyPDFLib_DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
||
736 | } |
||
737 | else |
||
738 | { |
||
739 | if (isTransOn) |
||
740 | 8c3a888c | djkim | { |
741 | e0f00e26 | djkim | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
742 | bool reverse = (area < 0); |
||
743 | |||
744 | if (PaintStyle == PaintSet.None) |
||
745 | { |
||
746 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
747 | } |
||
748 | else |
||
749 | { |
||
750 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
751 | } |
||
752 | 8c3a888c | djkim | } |
753 | e0f00e26 | djkim | else |
754 | 8c3a888c | djkim | { |
755 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity); |
756 | 8c3a888c | djkim | } |
757 | e0f00e26 | djkim | } |
758 | 7ca218b3 | KangIngu | } |
759 | e0f00e26 | djkim | break; |
760 | #endregion |
||
761 | #region TEXT |
||
762 | case "TextControl": |
||
763 | using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item)) |
||
764 | 7ca218b3 | KangIngu | { |
765 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
766 | string Text = control.Text; |
||
767 | 8c3a888c | djkim | |
768 | e0f00e26 | djkim | bool isUnderline = false; |
769 | control.BoxW -= scaleWidth; |
||
770 | control.BoxH -= scaleHeight; |
||
771 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH); |
||
772 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
773 | Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH)); |
||
774 | |||
775 | List<Point> pointSet = new List<Point>(); |
||
776 | pointSet.Add(StartPoint); |
||
777 | pointSet.Add(EndPoint); |
||
778 | |||
779 | PaintSet paint = PaintSet.None; |
||
780 | switch (control.paintMethod) |
||
781 | 7ca218b3 | KangIngu | { |
782 | e0f00e26 | djkim | case 1: |
783 | { |
||
784 | paint = PaintSet.Fill; |
||
785 | } |
||
786 | break; |
||
787 | case 2: |
||
788 | { |
||
789 | paint = PaintSet.Hatch; |
||
790 | } |
||
791 | break; |
||
792 | default: |
||
793 | break; |
||
794 | 7ca218b3 | KangIngu | } |
795 | e0f00e26 | djkim | if (control.isHighLight) paint |= PaintSet.Highlight; |
796 | 8c3a888c | djkim | |
797 | e0f00e26 | djkim | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
798 | double TextSize = Convert.ToDouble(data2[1]); |
||
799 | SolidColorBrush FontColor = _SetColor; |
||
800 | double Angle = control.Angle; |
||
801 | double Opacity = control.Opac; |
||
802 | FontFamily fontfamilly = new FontFamily(control.fontConfig[0]); |
||
803 | 8c3a888c | djkim | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
804 | |||
805 | FontStyle fontStyle = FontStyles.Normal; |
||
806 | if (FontStyles.Italic == TextStyle) |
||
807 | { |
||
808 | fontStyle = FontStyles.Italic; |
||
809 | } |
||
810 | |||
811 | FontWeight fontWeight = FontWeights.Black; |
||
812 | |||
813 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
814 | e0f00e26 | djkim | //강인구 수정(2018.04.17) |
815 | 8c3a888c | djkim | if (FontWeights.Bold == TextWeight) |
816 | e0f00e26 | djkim | //if (FontWeights.ExtraBold == TextWeight) |
817 | 8c3a888c | djkim | { |
818 | fontWeight = FontWeights.Bold; |
||
819 | } |
||
820 | |||
821 | TextDecorationCollection decoration = TextDecorations.Baseline; |
||
822 | e0f00e26 | djkim | if (control.fontConfig.Count() == 4) |
823 | 8c3a888c | djkim | { |
824 | decoration = TextDecorations.Underline; |
||
825 | } |
||
826 | |||
827 | e0f00e26 | djkim | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, _SetColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
828 | } |
||
829 | break; |
||
830 | #endregion |
||
831 | #region ArrowTextControl |
||
832 | case "ArrowTextControl": |
||
833 | using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item)) |
||
834 | { |
||
835 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
836 | Point tempStartPoint = GetPdfPointSystem(control.StartPoint); |
||
837 | Point tempMidPoint = GetPdfPointSystem(control.MidPoint); |
||
838 | Point tempEndPoint = GetPdfPointSystem(control.EndPoint); |
||
839 | bool isUnderLine = false; |
||
840 | string Text = ""; |
||
841 | double fontsize = 30; |
||
842 | |||
843 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight); |
||
844 | Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight)); |
||
845 | List<Point> tempPoint = new List<Point>(); |
||
846 | |||
847 | var tempRectMidPoint = MathSet.getRectMiddlePoint(rect); |
||
848 | |||
849 | tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y)); |
||
850 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top)); |
||
851 | tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y)); |
||
852 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom)); |
||
853 | double Angle = control.Angle; |
||
854 | var newStartPoint = tempStartPoint; |
||
855 | var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint); |
||
856 | var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint); |
||
857 | |||
858 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
859 | SolidColorBrush FontColor = _SetColor; |
||
860 | bool isHighlight = control.isHighLight; |
||
861 | double Opacity = control.Opac; |
||
862 | PaintSet Paint = PaintSet.None; |
||
863 | |||
864 | switch (control.ArrowStyle) |
||
865 | 7ca218b3 | KangIngu | { |
866 | e0f00e26 | djkim | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal: |
867 | { |
||
868 | Paint = PaintSet.None; |
||
869 | } |
||
870 | break; |
||
871 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud: |
||
872 | { |
||
873 | Paint = PaintSet.Hatch; |
||
874 | } |
||
875 | break; |
||
876 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect: |
||
877 | { |
||
878 | Paint = PaintSet.Fill; |
||
879 | } |
||
880 | break; |
||
881 | default: |
||
882 | break; |
||
883 | } |
||
884 | if (control.isHighLight) Paint |= PaintSet.Highlight; |
||
885 | |||
886 | if (Paint == PaintSet.Hatch) |
||
887 | { |
||
888 | Text = control.ArrowText; |
||
889 | 4804a4fb | humkyung | } |
890 | 8c3a888c | djkim | else |
891 | { |
||
892 | e0f00e26 | djkim | Text = control.ArrowText; |
893 | } |
||
894 | |||
895 | try |
||
896 | { |
||
897 | if (control.fontConfig.Count == 4) |
||
898 | 8c3a888c | djkim | { |
899 | e0f00e26 | djkim | fontsize = Convert.ToDouble(control.fontConfig[3]); |
900 | 8c3a888c | djkim | } |
901 | e0f00e26 | djkim | |
902 | //강인구 수정(2018.04.17) |
||
903 | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
||
904 | |||
905 | FontStyle fontStyle = FontStyles.Normal; |
||
906 | if (FontStyles.Italic == TextStyle) |
||
907 | { |
||
908 | fontStyle = FontStyles.Italic; |
||
909 | } |
||
910 | |||
911 | FontWeight fontWeight = FontWeights.Black; |
||
912 | |||
913 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
914 | if (FontWeights.Bold == TextWeight) |
||
915 | { |
||
916 | fontWeight = FontWeights.Bold; |
||
917 | } |
||
918 | |||
919 | TextDecorationCollection decoration = TextDecorations.Baseline; |
||
920 | if (control.fontConfig.Count() == 5) |
||
921 | { |
||
922 | decoration = TextDecorations.Underline; |
||
923 | } |
||
924 | |||
925 | if (control.isTrans) |
||
926 | 8c3a888c | djkim | { |
927 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
928 | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
929 | e0f00e26 | djkim | newStartPoint, tempMidPoint, |
930 | 8c3a888c | djkim | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, new FontFamily(), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
931 | } |
||
932 | e0f00e26 | djkim | else |
933 | { |
||
934 | if (control.isFixed) |
||
935 | { |
||
936 | var testP = new Point(0, 0); |
||
937 | if (control.isFixed) |
||
938 | { |
||
939 | if (tempPoint[1] == newEndPoint) |
||
940 | { |
||
941 | testP = new Point(newEndPoint.X, newEndPoint.Y - 10); |
||
942 | } |
||
943 | else if (tempPoint[3] == newEndPoint) |
||
944 | { |
||
945 | testP = new Point(newEndPoint.X, newEndPoint.Y + 10); |
||
946 | } |
||
947 | else if (tempPoint[0] == newEndPoint) |
||
948 | { |
||
949 | testP = new Point(newEndPoint.X - 10, newEndPoint.Y); |
||
950 | } |
||
951 | else if (tempPoint[2] == newEndPoint) |
||
952 | { |
||
953 | testP = new Point(newEndPoint.X + 10, newEndPoint.Y); |
||
954 | } |
||
955 | } |
||
956 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
957 | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
958 | tempStartPoint, testP, |
||
959 | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, |
||
960 | new FontFamily(), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
961 | } |
||
962 | else |
||
963 | { |
||
964 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
965 | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
||
966 | newStartPoint, newMidPoint, |
||
967 | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, new FontFamily(), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
||
968 | } |
||
969 | } |
||
970 | 8c3a888c | djkim | } |
971 | e0f00e26 | djkim | catch (Exception ex) |
972 | { |
||
973 | |||
974 | } |
||
975 | } |
||
976 | break; |
||
977 | #endregion |
||
978 | #region SignControl |
||
979 | case "SignControl": |
||
980 | using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item)) |
||
981 | { |
||
982 | |||
983 | double Angle = control.Angle; |
||
984 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
985 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
986 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
987 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
988 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
989 | double Opacity = control.Opac; |
||
990 | string UserNumber = control.UserNumber; |
||
991 | Controls_PDF.HoneyPDFLib_DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO); |
||
992 | } |
||
993 | break; |
||
994 | #endregion |
||
995 | #region MyRegion |
||
996 | case "DateControl": |
||
997 | using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item)) |
||
998 | { |
||
999 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1000 | string Text = control.Text; |
||
1001 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1002 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1003 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1004 | SolidColorBrush FontColor = _SetColor; |
||
1005 | double Angle = control.Angle; |
||
1006 | double Opacity = control.Opac; |
||
1007 | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity); |
||
1008 | f633b10b | KangIngu | } |
1009 | e0f00e26 | djkim | break; |
1010 | #endregion |
||
1011 | #region SymControlN (APPROVED) |
||
1012 | case "SymControlN": |
||
1013 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1014 | 8c3a888c | djkim | { |
1015 | e0f00e26 | djkim | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1016 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1017 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1018 | SolidColorBrush FontColor = _SetColor; |
||
1019 | double Angle = control.Angle; |
||
1020 | double Opacity = control.Opac; |
||
1021 | |||
1022 | string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", ""); |
||
1023 | Controls_PDF.HoneyPDFLib_DrawSet_Symbol.DrawApproval(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
||
1024 | } |
||
1025 | break; |
||
1026 | case "SymControl": |
||
1027 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1028 | { |
||
1029 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1030 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1031 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1032 | SolidColorBrush FontColor = _SetColor; |
||
1033 | double Angle = control.Angle; |
||
1034 | double Opacity = control.Opac; |
||
1035 | 8c3a888c | djkim | |
1036 | e0f00e26 | djkim | string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", ""); |
1037 | Controls_PDF.HoneyPDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
||
1038 | 8c3a888c | djkim | } |
1039 | e0f00e26 | djkim | break; |
1040 | #endregion |
||
1041 | #region Image |
||
1042 | case "ImgControl": |
||
1043 | using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item)) |
||
1044 | { |
||
1045 | double Angle = control.Angle; |
||
1046 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1047 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
1048 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1049 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
1050 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1051 | double Opacity = control.Opac; |
||
1052 | string FilePath = control.ImagePath; |
||
1053 | //Uri uri = new Uri(s.ImagePath); |
||
1054 | |||
1055 | Controls_PDF.HoneyPDFLib_DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity); |
||
1056 | } |
||
1057 | break; |
||
1058 | #endregion |
||
1059 | default: |
||
1060 | break; |
||
1061 | } |
||
1062 | 8c3a888c | djkim | } |
1063 | e0f00e26 | djkim | catch (Exception ex) |
1064 | { |
||
1065 | abaa85b4 | djkim | |
1066 | e0f00e26 | djkim | } |
1067 | 8c3a888c | djkim | } |
1068 | abaa85b4 | djkim | } |
1069 | e0f00e26 | djkim | pdfStamper.Outlines = root; |
1070 | pdfStamper.Close(); |
||
1071 | pdfReader.Close(); |
||
1072 | 7ca218b3 | KangIngu | } |
1073 | abaa85b4 | djkim | } |
1074 | e0f00e26 | djkim | #endregion |
1075 | 7ca218b3 | KangIngu | } |
1076 | if (tempFileInfo.Exists) |
||
1077 | { |
||
1078 | tempFileInfo.Delete(); |
||
1079 | } |
||
1080 | |||
1081 | if (File.Exists(pdfFilePath)) |
||
1082 | { |
||
1083 | try |
||
1084 | { |
||
1085 | 6e5f7eaf | djkim | FinalPDFPath = new FileInfo(pdfFilePath); |
1086 | |||
1087 | string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", ""); |
||
1088 | string destfilepath = Path.Combine(pdfmovepath,FinalPDFPath.Name.Replace(".tmp", ".pdf")); |
||
1089 | if (File.Exists(destfilepath)) |
||
1090 | File.Delete(destfilepath); |
||
1091 | File.Move(FinalPDFPath.FullName, destfilepath); |
||
1092 | FinalPDFPath = new FileInfo(destfilepath); |
||
1093 | 7ca218b3 | KangIngu | File.Delete(pdfFilePath); |
1094 | } |
||
1095 | catch (Exception ex) |
||
1096 | { |
||
1097 | 6e5f7eaf | djkim | SetNotice(finaldata.ID, "File move error: " + ex.ToString()); |
1098 | 7ca218b3 | KangIngu | } |
1099 | // |
||
1100 | |||
1101 | return true; |
||
1102 | } |
||
1103 | } |
||
1104 | e0f00e26 | djkim | catch (Exception) |
1105 | 7ca218b3 | KangIngu | { |
1106 | throw; |
||
1107 | } |
||
1108 | return false; |
||
1109 | } |
||
1110 | |||
1111 | public void Dispose() |
||
1112 | { |
||
1113 | throw new NotImplementedException(); |
||
1114 | 8c3a888c | djkim | } |
1115 | 7f01e35f | ljiyeon | |
1116 | 7ca218b3 | KangIngu | #endregion |
1117 | } |
||
1118 | } |