markus / FinalService / KCOM_FinalService / MarkupToPDF / MarkupToPDF.cs @ d7e20d2d
이력 | 보기 | 이력해설 | 다운로드 (70.6 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 | 7aa36857 | humkyung | /// media box와 crop box가 다를 경우 media box를 crop box와 일치시킨다 |
477 | if (cropBox != null && |
||
478 | (cropBox.Left != mediaBox.Left || cropBox.Top != mediaBox.Top || cropBox.Right != mediaBox.Right || cropBox.Bottom != mediaBox.Bottom)) |
||
479 | 2e1d6c99 | djkim | { |
480 | 7aa36857 | humkyung | PdfDictionary dict = pdfReader.GetPageN(markupItem.PAGENUMBER); |
481 | |||
482 | PdfArray oNewMediaBox = new PdfArray(); |
||
483 | oNewMediaBox.Add(new PdfNumber(cropBox.Left)); |
||
484 | oNewMediaBox.Add(new PdfNumber(cropBox.Top)); |
||
485 | oNewMediaBox.Add(new PdfNumber(cropBox.Right)); |
||
486 | oNewMediaBox.Add(new PdfNumber(cropBox.Bottom)); |
||
487 | dict.Put(PdfName.MEDIABOX, oNewMediaBox); |
||
488 | |||
489 | 2e1d6c99 | djkim | pdfSize = cropBox; |
490 | } |
||
491 | e0f00e26 | djkim | scaleWidth = float.Parse(currentPage.PAGE_WIDTH) / pdfSize.Width; |
492 | scaleHeight = float.Parse(currentPage.PAGE_HEIGHT) / pdfSize.Height; |
||
493 | 7ca218b3 | KangIngu | |
494 | e0f00e26 | djkim | pdfLink.CURRENT_PAGE = markupItem.PAGENUMBER; |
495 | _entity.SaveChanges(); |
||
496 | 8c3a888c | djkim | |
497 | e0f00e26 | djkim | string[] markedData = markupItem.DATA.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
498 | |||
499 | PdfContentByte contentByte = pdfStamper.GetOverContent(markupItem.PAGENUMBER); |
||
500 | |||
501 | |||
502 | foreach (var data in markedData) |
||
503 | 7ca218b3 | KangIngu | { |
504 | e0f00e26 | djkim | var item = JsonSerializerHelper.UnCompressString(data); |
505 | var ControlT = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); |
||
506 | |||
507 | try |
||
508 | 8c3a888c | djkim | { |
509 | e0f00e26 | djkim | switch (ControlT.Name) |
510 | { |
||
511 | #region LINE |
||
512 | case "LineControl": |
||
513 | 7ca218b3 | KangIngu | { |
514 | e0f00e26 | djkim | using (S_LineControl control = JsonSerializerHelper.JsonDeserialize<S_LineControl>(item)) |
515 | 8c3a888c | djkim | { |
516 | e0f00e26 | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
517 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
518 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
519 | DoubleCollection DashSize = control.DashSize; |
||
520 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
521 | |||
522 | var Opacity = control.Opac; |
||
523 | string UserID = control.UserID; |
||
524 | double Interval = control.Interval; |
||
525 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
526 | 16fe076c | humkyung | Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, control.DashSize, _SetColor, Opacity); |
527 | e0f00e26 | djkim | switch (control.LineStyleSet) |
528 | { |
||
529 | case LineStyleSet.ArrowLine: |
||
530 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
531 | e0f00e26 | djkim | break; |
532 | case LineStyleSet.CancelLine: |
||
533 | 8c3a888c | djkim | { |
534 | e0f00e26 | djkim | var x = Math.Abs((Math.Abs(StartPoint.X) - Math.Abs(EndPoint.X))); |
535 | var y = Math.Abs((Math.Abs(StartPoint.Y) - Math.Abs(EndPoint.Y))); |
||
536 | |||
537 | if (x > y) |
||
538 | { |
||
539 | StartPoint = new Point(StartPoint.X, StartPoint.Y - (float)(control.Interval / 3.0)); |
||
540 | EndPoint = new Point(EndPoint.X, EndPoint.Y - (float)(control.Interval / 3.0)); |
||
541 | 16fe076c | humkyung | Controls_PDF.DrawSet_Line.DrawLine(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, Opacity); |
542 | e0f00e26 | djkim | } |
543 | 8c3a888c | djkim | } |
544 | e0f00e26 | djkim | break; |
545 | case LineStyleSet.TwinLine: |
||
546 | { |
||
547 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
548 | Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
||
549 | e0f00e26 | djkim | } |
550 | break; |
||
551 | case LineStyleSet.DimLine: |
||
552 | { |
||
553 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.DimAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
554 | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
||
555 | Controls_PDF.DrawSet_Arrow.SingleAllow(StartPoint, EndPoint, LineSize, contentByte, _SetColor, Opacity); |
||
556 | e0f00e26 | djkim | } |
557 | break; |
||
558 | default: |
||
559 | break; |
||
560 | } |
||
561 | 7ca218b3 | KangIngu | |
562 | |||
563 | e0f00e26 | djkim | } |
564 | 8c3a888c | djkim | } |
565 | e0f00e26 | djkim | break; |
566 | #endregion |
||
567 | #region ArrowControlMulti |
||
568 | case "ArrowControl_Multi": |
||
569 | 8c3a888c | djkim | { |
570 | e0f00e26 | djkim | using (S_ArrowControl_Multi control = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(item)) |
571 | { |
||
572 | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
573 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
574 | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
||
575 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
576 | DoubleCollection DashSize = control.DashSize; |
||
577 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
578 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
579 | abaa85b4 | djkim | |
580 | e0f00e26 | djkim | double Opacity = control.Opac; |
581 | abaa85b4 | djkim | |
582 | e0f00e26 | djkim | if (EndPoint == MidPoint) |
583 | { |
||
584 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, LineSize, contentByte, _SetColor, Opacity); |
585 | e0f00e26 | djkim | } |
586 | else |
||
587 | { |
||
588 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.SingleAllow(EndPoint, MidPoint, LineSize, contentByte, _SetColor, Opacity); |
589 | e0f00e26 | djkim | } |
590 | 7ca218b3 | KangIngu | |
591 | 16fe076c | humkyung | Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
592 | abaa85b4 | djkim | |
593 | e0f00e26 | djkim | } |
594 | 8c3a888c | djkim | } |
595 | e0f00e26 | djkim | break; |
596 | #endregion |
||
597 | #region PolyControl |
||
598 | case "PolygonControl": |
||
599 | using (S_PolyControl control = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(item)) |
||
600 | 7ca218b3 | KangIngu | { |
601 | 8c3a888c | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
602 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
603 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
604 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
605 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
606 | e0f00e26 | djkim | double Opacity = control.Opac; |
607 | DoubleCollection DashSize = control.DashSize; |
||
608 | 8c3a888c | djkim | |
609 | 16fe076c | humkyung | Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
610 | 8c3a888c | djkim | } |
611 | e0f00e26 | djkim | break; |
612 | #endregion |
||
613 | #region ArcControl |
||
614 | case "ArcControl": |
||
615 | 8c3a888c | djkim | { |
616 | e0f00e26 | djkim | using (S_ArcControl control = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(item)) |
617 | abaa85b4 | djkim | { |
618 | e0f00e26 | djkim | string[] InnerData = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
619 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
620 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
621 | Point MidPoint = GetPdfPointSystem(control.MidPoint); |
||
622 | DoubleCollection DashSize = control.DashSize; |
||
623 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
624 | |||
625 | var Opacity = control.Opac; |
||
626 | string UserID = control.UserID; |
||
627 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(InnerData.First())); |
||
628 | bool IsTransOn = control.IsTransOn; |
||
629 | |||
630 | if (control.IsTransOn) |
||
631 | 8c3a888c | djkim | { |
632 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, StartPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
633 | Controls_PDF.DrawSet_Arrow.SingleAllow(MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity, true); |
||
634 | 8c3a888c | djkim | } |
635 | else |
||
636 | { |
||
637 | 16fe076c | humkyung | Controls_PDF.DrawSet_Arc.DrawArc(StartPoint, MidPoint, EndPoint, (int)LineSize, contentByte, _SetColor, Opacity); |
638 | 8c3a888c | djkim | } |
639 | e0f00e26 | djkim | |
640 | abaa85b4 | djkim | } |
641 | 8c3a888c | djkim | } |
642 | e0f00e26 | djkim | break; |
643 | #endregion |
||
644 | #region RectangleControl |
||
645 | case "RectangleControl": |
||
646 | using (S_RectControl control = JsonSerializerHelper.JsonDeserialize<S_RectControl>(item)) |
||
647 | 7ca218b3 | KangIngu | { |
648 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
649 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
650 | var PaintStyle = control.PaintState; |
||
651 | double Angle = control.Angle; |
||
652 | DoubleCollection DashSize = control.DashSize; |
||
653 | double Opacity = control.Opac; |
||
654 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
655 | |||
656 | 16fe076c | humkyung | Controls_PDF.DrawSet_Shape.DrawRectangle(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
657 | 7ca218b3 | KangIngu | } |
658 | e0f00e26 | djkim | break; |
659 | #endregion |
||
660 | #region TriControl |
||
661 | case "TriControl": |
||
662 | using (S_TriControl control = JsonSerializerHelper.JsonDeserialize<S_TriControl>(item)) |
||
663 | 7ca218b3 | KangIngu | { |
664 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
665 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
666 | var PaintStyle = control.Paint; |
||
667 | double Angle = control.Angle; |
||
668 | //StrokeColor = _SetColor, //색상은 레드 |
||
669 | DoubleCollection DashSize = control.DashSize; |
||
670 | double Opacity = control.Opac; |
||
671 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
672 | 7ca218b3 | KangIngu | |
673 | 16fe076c | humkyung | Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity); |
674 | 7ca218b3 | KangIngu | } |
675 | e0f00e26 | djkim | break; |
676 | #endregion |
||
677 | #region CircleControl |
||
678 | case "CircleControl": |
||
679 | using (S_CircleControl control = JsonSerializerHelper.JsonDeserialize<S_CircleControl>(item)) |
||
680 | 7ca218b3 | KangIngu | { |
681 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
682 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
683 | var StartPoint = GetPdfPointSystem(control.StartPoint); |
||
684 | var EndPoint = GetPdfPointSystem(control.EndPoint); |
||
685 | var PaintStyle = control.PaintState; |
||
686 | double Angle = control.Angle; |
||
687 | DoubleCollection DashSize = control.DashSize; |
||
688 | double Opacity = control.Opac; |
||
689 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
690 | 16fe076c | humkyung | Controls_PDF.DrawSet_Shape.DrawCircle(StartPoint, EndPoint, LineSize, contentByte, DashSize, _SetColor, PaintStyle, Opacity, Angle, PointSet); |
691 | e0f00e26 | djkim | |
692 | 7ca218b3 | KangIngu | } |
693 | e0f00e26 | djkim | break; |
694 | #endregion |
||
695 | #region RectCloudControl |
||
696 | case "RectCloudControl": |
||
697 | using (S_RectCloudControl control = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(item)) |
||
698 | { |
||
699 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
700 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
701 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
702 | double size = MathSet.DistanceTo(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
703 | |||
704 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
705 | |||
706 | var PaintStyle = control.PaintState; |
||
707 | double Opacity = control.Opac; |
||
708 | DoubleCollection DashSize = control.DashSize; |
||
709 | 7ca218b3 | KangIngu | |
710 | e0f00e26 | djkim | //드로잉 방식이 표현되지 않음 |
711 | var rrrr = returnAngle(GetPdfPointSystem(control.StartPoint), GetPdfPointSystem(control.EndPoint)); |
||
712 | |||
713 | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
||
714 | bool reverse = (area < 0); |
||
715 | if (PaintStyle == PaintSet.None) |
||
716 | { |
||
717 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
718 | } |
||
719 | else |
||
720 | { |
||
721 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
722 | } |
||
723 | } |
||
724 | break; |
||
725 | #endregion |
||
726 | #region CloudControl |
||
727 | case "CloudControl": |
||
728 | using (S_CloudControl control = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(item)) |
||
729 | 7ca218b3 | KangIngu | { |
730 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
731 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
732 | double Toler = control.Toler; |
||
733 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
734 | double ArcLength = (control.ArcLength == 0 ? 10 : control.ArcLength) / (scaleWidth > scaleHeight ? scaleWidth : scaleHeight); |
||
735 | var PaintStyle = control.PaintState; |
||
736 | double Opacity = control.Opac; |
||
737 | bool isTransOn = control.IsTrans; |
||
738 | bool isChain = control.IsChain; |
||
739 | |||
740 | DoubleCollection DashSize = control.DashSize; |
||
741 | |||
742 | if (isChain) |
||
743 | { |
||
744 | 16fe076c | humkyung | Controls_PDF.DrawSet_Line.DrawLine(PointSet, LineSize, contentByte, DashSize, _SetColor, Opacity); |
745 | e0f00e26 | djkim | } |
746 | else |
||
747 | { |
||
748 | if (isTransOn) |
||
749 | 8c3a888c | djkim | { |
750 | e0f00e26 | djkim | double area = MathSet.AreaOf(GetPdfPointSystem(control.PointSet)); |
751 | bool reverse = (area < 0); |
||
752 | |||
753 | if (PaintStyle == PaintSet.None) |
||
754 | { |
||
755 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
756 | } |
||
757 | else |
||
758 | { |
||
759 | Controls_PDF.DrawSet_Cloud.DrawCloud(PointSet, LineSize, ArcLength, contentByte, control.DashSize, _SetColor, _SetColor, PaintStyle, Opacity); |
||
760 | } |
||
761 | 8c3a888c | djkim | } |
762 | e0f00e26 | djkim | else |
763 | 8c3a888c | djkim | { |
764 | 16fe076c | humkyung | Controls_PDF.DrawSet_Shape.DrawPolygon(PointSet, LineSize, contentByte, control.DashSize, _SetColor, PaintStyle, Opacity); |
765 | 8c3a888c | djkim | } |
766 | e0f00e26 | djkim | } |
767 | 7ca218b3 | KangIngu | } |
768 | e0f00e26 | djkim | break; |
769 | #endregion |
||
770 | #region TEXT |
||
771 | case "TextControl": |
||
772 | using (S_TextControl control = JsonSerializerHelper.JsonDeserialize<S_TextControl>(item)) |
||
773 | 7ca218b3 | KangIngu | { |
774 | e0f00e26 | djkim | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
775 | string Text = control.Text; |
||
776 | 8c3a888c | djkim | |
777 | e0f00e26 | djkim | bool isUnderline = false; |
778 | control.BoxW -= scaleWidth; |
||
779 | control.BoxH -= scaleHeight; |
||
780 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxW, (float)control.BoxH); |
||
781 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
782 | Point EndPoint = GetPdfPointSystem(new Point(control.StartPoint.X + control.BoxW, control.StartPoint.Y + control.BoxH)); |
||
783 | |||
784 | List<Point> pointSet = new List<Point>(); |
||
785 | pointSet.Add(StartPoint); |
||
786 | pointSet.Add(EndPoint); |
||
787 | |||
788 | PaintSet paint = PaintSet.None; |
||
789 | switch (control.paintMethod) |
||
790 | 7ca218b3 | KangIngu | { |
791 | e0f00e26 | djkim | case 1: |
792 | { |
||
793 | paint = PaintSet.Fill; |
||
794 | } |
||
795 | break; |
||
796 | case 2: |
||
797 | { |
||
798 | paint = PaintSet.Hatch; |
||
799 | } |
||
800 | break; |
||
801 | default: |
||
802 | break; |
||
803 | 7ca218b3 | KangIngu | } |
804 | e0f00e26 | djkim | if (control.isHighLight) paint |= PaintSet.Highlight; |
805 | 8c3a888c | djkim | |
806 | e0f00e26 | djkim | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
807 | double TextSize = Convert.ToDouble(data2[1]); |
||
808 | SolidColorBrush FontColor = _SetColor; |
||
809 | double Angle = control.Angle; |
||
810 | double Opacity = control.Opac; |
||
811 | FontFamily fontfamilly = new FontFamily(control.fontConfig[0]); |
||
812 | 8c3a888c | djkim | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
813 | |||
814 | FontStyle fontStyle = FontStyles.Normal; |
||
815 | if (FontStyles.Italic == TextStyle) |
||
816 | { |
||
817 | fontStyle = FontStyles.Italic; |
||
818 | } |
||
819 | |||
820 | FontWeight fontWeight = FontWeights.Black; |
||
821 | |||
822 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
823 | e0f00e26 | djkim | //강인구 수정(2018.04.17) |
824 | 8c3a888c | djkim | if (FontWeights.Bold == TextWeight) |
825 | e0f00e26 | djkim | //if (FontWeights.ExtraBold == TextWeight) |
826 | 8c3a888c | djkim | { |
827 | fontWeight = FontWeights.Bold; |
||
828 | } |
||
829 | |||
830 | TextDecorationCollection decoration = TextDecorations.Baseline; |
||
831 | e0f00e26 | djkim | if (control.fontConfig.Count() == 4) |
832 | 8c3a888c | djkim | { |
833 | decoration = TextDecorations.Underline; |
||
834 | } |
||
835 | |||
836 | 16fe076c | humkyung | Controls_PDF.DrawSet_Text.DrawString(StartPoint, EndPoint, LineSize, contentByte, _SetColor, paint, TextSize, fontfamilly, fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
837 | e0f00e26 | djkim | } |
838 | break; |
||
839 | #endregion |
||
840 | #region ArrowTextControl |
||
841 | case "ArrowTextControl": |
||
842 | using (S_ArrowTextControl control = JsonSerializerHelper.JsonDeserialize<S_ArrowTextControl>(item)) |
||
843 | { |
||
844 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
845 | Point tempStartPoint = GetPdfPointSystem(control.StartPoint); |
||
846 | Point tempMidPoint = GetPdfPointSystem(control.MidPoint); |
||
847 | Point tempEndPoint = GetPdfPointSystem(control.EndPoint); |
||
848 | bool isUnderLine = false; |
||
849 | string Text = ""; |
||
850 | double fontsize = 30; |
||
851 | |||
852 | System.Drawing.SizeF sizeF = new System.Drawing.SizeF((float)control.BoxWidth, (float)control.BoxHeight); |
||
853 | Rect rect = new Rect(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight)); |
||
854 | List<Point> tempPoint = new List<Point>(); |
||
855 | |||
856 | var tempRectMidPoint = MathSet.getRectMiddlePoint(rect); |
||
857 | |||
858 | tempPoint.Add(new Point(rect.Left, tempRectMidPoint.Y)); |
||
859 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Top)); |
||
860 | tempPoint.Add(new Point(rect.Right, tempRectMidPoint.Y)); |
||
861 | tempPoint.Add(new Point(tempRectMidPoint.X, rect.Bottom)); |
||
862 | double Angle = control.Angle; |
||
863 | var newStartPoint = tempStartPoint; |
||
864 | var newEndPoint = MathSet.getNearPoint(tempPoint, tempMidPoint); |
||
865 | var newMidPoint = MathSet.getMiddlePoint(newStartPoint, newEndPoint); |
||
866 | |||
867 | double LineSize = Common.ConverterLineSize.Convert(Convert.ToInt32(data2.First())); |
||
868 | SolidColorBrush FontColor = _SetColor; |
||
869 | bool isHighlight = control.isHighLight; |
||
870 | double Opacity = control.Opac; |
||
871 | PaintSet Paint = PaintSet.None; |
||
872 | |||
873 | switch (control.ArrowStyle) |
||
874 | 7ca218b3 | KangIngu | { |
875 | e0f00e26 | djkim | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Normal: |
876 | { |
||
877 | Paint = PaintSet.None; |
||
878 | } |
||
879 | break; |
||
880 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Cloud: |
||
881 | { |
||
882 | Paint = PaintSet.Hatch; |
||
883 | } |
||
884 | break; |
||
885 | case Controls.Text.ArrowTextControl.ArrowTextStyleSet.Rect: |
||
886 | { |
||
887 | Paint = PaintSet.Fill; |
||
888 | } |
||
889 | break; |
||
890 | default: |
||
891 | break; |
||
892 | } |
||
893 | if (control.isHighLight) Paint |= PaintSet.Highlight; |
||
894 | |||
895 | if (Paint == PaintSet.Hatch) |
||
896 | { |
||
897 | Text = control.ArrowText; |
||
898 | 4804a4fb | humkyung | } |
899 | 8c3a888c | djkim | else |
900 | { |
||
901 | e0f00e26 | djkim | Text = control.ArrowText; |
902 | } |
||
903 | |||
904 | try |
||
905 | { |
||
906 | if (control.fontConfig.Count == 4) |
||
907 | 8c3a888c | djkim | { |
908 | e0f00e26 | djkim | fontsize = Convert.ToDouble(control.fontConfig[3]); |
909 | 8c3a888c | djkim | } |
910 | e0f00e26 | djkim | |
911 | //강인구 수정(2018.04.17) |
||
912 | var TextStyle = Common.StringToFont.ConFontStyle(control.fontConfig[1]); |
||
913 | |||
914 | FontStyle fontStyle = FontStyles.Normal; |
||
915 | if (FontStyles.Italic == TextStyle) |
||
916 | { |
||
917 | fontStyle = FontStyles.Italic; |
||
918 | } |
||
919 | |||
920 | FontWeight fontWeight = FontWeights.Black; |
||
921 | |||
922 | var TextWeight = Common.StringToFont.ConFontWeight(control.fontConfig[2]); |
||
923 | if (FontWeights.Bold == TextWeight) |
||
924 | { |
||
925 | fontWeight = FontWeights.Bold; |
||
926 | } |
||
927 | |||
928 | TextDecorationCollection decoration = TextDecorations.Baseline; |
||
929 | if (control.fontConfig.Count() == 5) |
||
930 | { |
||
931 | decoration = TextDecorations.Underline; |
||
932 | } |
||
933 | |||
934 | if (control.isTrans) |
||
935 | 8c3a888c | djkim | { |
936 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
937 | 16fe076c | humkyung | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
938 | newStartPoint, tempMidPoint, control.isFixed, |
||
939 | 6282063e | humkyung | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, new FontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
940 | 8c3a888c | djkim | } |
941 | e0f00e26 | djkim | else |
942 | { |
||
943 | if (control.isFixed) |
||
944 | { |
||
945 | var testP = new Point(0, 0); |
||
946 | if (control.isFixed) |
||
947 | { |
||
948 | if (tempPoint[1] == newEndPoint) |
||
949 | { |
||
950 | testP = new Point(newEndPoint.X, newEndPoint.Y - 10); |
||
951 | } |
||
952 | else if (tempPoint[3] == newEndPoint) |
||
953 | { |
||
954 | testP = new Point(newEndPoint.X, newEndPoint.Y + 10); |
||
955 | } |
||
956 | else if (tempPoint[0] == newEndPoint) |
||
957 | { |
||
958 | testP = new Point(newEndPoint.X - 10, newEndPoint.Y); |
||
959 | } |
||
960 | else if (tempPoint[2] == newEndPoint) |
||
961 | { |
||
962 | testP = new Point(newEndPoint.X + 10, newEndPoint.Y); |
||
963 | } |
||
964 | } |
||
965 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
966 | 16fe076c | humkyung | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
967 | tempStartPoint, testP, control.isFixed , |
||
968 | e0f00e26 | djkim | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, |
969 | 6282063e | humkyung | new FontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
970 | e0f00e26 | djkim | } |
971 | else |
||
972 | { |
||
973 | //인구 수정 Arrow Text Style적용 되도록 변경 |
||
974 | 16fe076c | humkyung | Controls_PDF.DrawSet_Text.DrawString_ArrowText(tempEndPoint, new Point(tempEndPoint.X + control.BoxWidth / scaleWidth, tempEndPoint.Y - control.BoxHeight / scaleHeight), |
975 | newStartPoint, tempMidPoint, control.isFixed, |
||
976 | 6282063e | humkyung | LineSize, contentByte, _SetColor, Paint, fontsize, isHighlight, new FontFamily(control.fontConfig[0]), fontStyle, fontWeight, decoration, Text, sizeF, Opacity, Angle); |
977 | e0f00e26 | djkim | } |
978 | } |
||
979 | 8c3a888c | djkim | } |
980 | e0f00e26 | djkim | catch (Exception ex) |
981 | { |
||
982 | 16fe076c | humkyung | throw ex; |
983 | e0f00e26 | djkim | } |
984 | } |
||
985 | break; |
||
986 | #endregion |
||
987 | #region SignControl |
||
988 | case "SignControl": |
||
989 | using (S_SignControl control = JsonSerializerHelper.JsonDeserialize<S_SignControl>(item)) |
||
990 | { |
||
991 | |||
992 | double Angle = control.Angle; |
||
993 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
994 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
995 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
996 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
997 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
998 | double Opacity = control.Opac; |
||
999 | string UserNumber = control.UserNumber; |
||
1000 | 16fe076c | humkyung | Controls_PDF.DrawSet_Image.DrawSign(StartPoint, EndPoint, PointSet, contentByte, UserNumber, Angle, Opacity, finaldata.PROJECT_NO); |
1001 | e0f00e26 | djkim | } |
1002 | break; |
||
1003 | #endregion |
||
1004 | #region MyRegion |
||
1005 | case "DateControl": |
||
1006 | using (S_DateControl control = JsonSerializerHelper.JsonDeserialize<S_DateControl>(item)) |
||
1007 | { |
||
1008 | string[] data2 = control.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
1009 | string Text = control.Text; |
||
1010 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1011 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1012 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1013 | SolidColorBrush FontColor = _SetColor; |
||
1014 | double Angle = control.Angle; |
||
1015 | double Opacity = control.Opac; |
||
1016 | Controls_PDF.HoneyPDFLib_DrawSet_Text.DrawDate(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Text, Angle, Opacity); |
||
1017 | f633b10b | KangIngu | } |
1018 | e0f00e26 | djkim | break; |
1019 | #endregion |
||
1020 | #region SymControlN (APPROVED) |
||
1021 | case "SymControlN": |
||
1022 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1023 | 8c3a888c | djkim | { |
1024 | e0f00e26 | djkim | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
1025 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1026 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1027 | SolidColorBrush FontColor = _SetColor; |
||
1028 | double Angle = control.Angle; |
||
1029 | double Opacity = control.Opac; |
||
1030 | |||
1031 | string imgpath = CommonLib.Common.GetConfigString("ApprovedImgPath", "URL", ""); |
||
1032 | Controls_PDF.HoneyPDFLib_DrawSet_Symbol.DrawApproval(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
||
1033 | } |
||
1034 | break; |
||
1035 | case "SymControl": |
||
1036 | using (S_SymControl control = JsonSerializerHelper.JsonDeserialize<S_SymControl>(item)) |
||
1037 | { |
||
1038 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1039 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1040 | List<Point> pointSet = GetPdfPointSystem(control.PointSet); |
||
1041 | SolidColorBrush FontColor = _SetColor; |
||
1042 | double Angle = control.Angle; |
||
1043 | double Opacity = control.Opac; |
||
1044 | 8c3a888c | djkim | |
1045 | e0f00e26 | djkim | string imgpath = CommonLib.Common.GetConfigString("CheckmarkImgPath", "URL", ""); |
1046 | Controls_PDF.HoneyPDFLib_DrawSet_Symbol.DrawCheckMark(StartPoint, EndPoint, pointSet, contentByte, _SetColor, Angle, Opacity, imgpath); |
||
1047 | 8c3a888c | djkim | } |
1048 | e0f00e26 | djkim | break; |
1049 | #endregion |
||
1050 | #region Image |
||
1051 | case "ImgControl": |
||
1052 | using (S_ImgControl control = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(item)) |
||
1053 | { |
||
1054 | double Angle = control.Angle; |
||
1055 | Point StartPoint = GetPdfPointSystem(control.StartPoint); |
||
1056 | Point TopRightPoint = GetPdfPointSystem(control.TR); |
||
1057 | Point EndPoint = GetPdfPointSystem(control.EndPoint); |
||
1058 | Point LeftBottomPoint = GetPdfPointSystem(control.LB); |
||
1059 | List<Point> PointSet = GetPdfPointSystem(control.PointSet); |
||
1060 | double Opacity = control.Opac; |
||
1061 | string FilePath = control.ImagePath; |
||
1062 | //Uri uri = new Uri(s.ImagePath); |
||
1063 | |||
1064 | 16fe076c | humkyung | Controls_PDF.DrawSet_Image.DrawImage(StartPoint, EndPoint, PointSet, contentByte, FilePath, Angle, Opacity); |
1065 | e0f00e26 | djkim | } |
1066 | break; |
||
1067 | #endregion |
||
1068 | default: |
||
1069 | break; |
||
1070 | } |
||
1071 | 8c3a888c | djkim | } |
1072 | e0f00e26 | djkim | catch (Exception ex) |
1073 | { |
||
1074 | abaa85b4 | djkim | |
1075 | e0f00e26 | djkim | } |
1076 | 8c3a888c | djkim | } |
1077 | abaa85b4 | djkim | } |
1078 | e0f00e26 | djkim | pdfStamper.Outlines = root; |
1079 | pdfStamper.Close(); |
||
1080 | pdfReader.Close(); |
||
1081 | 7ca218b3 | KangIngu | } |
1082 | abaa85b4 | djkim | } |
1083 | e0f00e26 | djkim | #endregion |
1084 | 7ca218b3 | KangIngu | } |
1085 | if (tempFileInfo.Exists) |
||
1086 | { |
||
1087 | tempFileInfo.Delete(); |
||
1088 | } |
||
1089 | |||
1090 | if (File.Exists(pdfFilePath)) |
||
1091 | { |
||
1092 | try |
||
1093 | { |
||
1094 | 6e5f7eaf | djkim | FinalPDFPath = new FileInfo(pdfFilePath); |
1095 | |||
1096 | string pdfmovepath = CommonLib.Common.GetConfigString("PDFMovePath", "URL", ""); |
||
1097 | string destfilepath = Path.Combine(pdfmovepath,FinalPDFPath.Name.Replace(".tmp", ".pdf")); |
||
1098 | if (File.Exists(destfilepath)) |
||
1099 | File.Delete(destfilepath); |
||
1100 | File.Move(FinalPDFPath.FullName, destfilepath); |
||
1101 | FinalPDFPath = new FileInfo(destfilepath); |
||
1102 | 7ca218b3 | KangIngu | File.Delete(pdfFilePath); |
1103 | } |
||
1104 | catch (Exception ex) |
||
1105 | { |
||
1106 | 6e5f7eaf | djkim | SetNotice(finaldata.ID, "File move error: " + ex.ToString()); |
1107 | 7ca218b3 | KangIngu | } |
1108 | |||
1109 | return true; |
||
1110 | } |
||
1111 | } |
||
1112 | 7aa36857 | humkyung | catch (Exception ex) |
1113 | 7ca218b3 | KangIngu | { |
1114 | 7aa36857 | humkyung | throw ex; |
1115 | 7ca218b3 | KangIngu | } |
1116 | return false; |
||
1117 | } |
||
1118 | |||
1119 | 40cf5bf7 | humkyung | ~MarkupToPDF() |
1120 | { |
||
1121 | this.Dispose(false); |
||
1122 | } |
||
1123 | |||
1124 | private bool disposed; |
||
1125 | |||
1126 | 7ca218b3 | KangIngu | public void Dispose() |
1127 | { |
||
1128 | 40cf5bf7 | humkyung | this.Dispose(true); |
1129 | GC.SuppressFinalize(this); |
||
1130 | } |
||
1131 | |||
1132 | protected virtual void Dispose(bool disposing) |
||
1133 | { |
||
1134 | if (this.disposed) return; |
||
1135 | if (disposing) |
||
1136 | { |
||
1137 | // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다. |
||
1138 | } |
||
1139 | // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다. |
||
1140 | this.disposed = true; |
||
1141 | 8c3a888c | djkim | } |
1142 | 7f01e35f | ljiyeon | |
1143 | 7ca218b3 | KangIngu | #endregion |
1144 | } |
||
1145 | } |