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