CPDFViewerTool.DataMethod.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. using ComPDFKit.PDFAnnotation.Form;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument.Action;
  4. using ComPDFKit.PDFDocument;
  5. using ComPDFKit.Tool.SettingParam;
  6. using ComPDFKitViewer;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
  11. using static ComPDFKit.PDFAnnotation.CTextAttribute;
  12. using ComPDFKit.Tool.Help;
  13. using static ComPDFKit.Tool.Help.ParamConverter;
  14. using ComPDFKit.Import;
  15. using ComPDFKit.Measure;
  16. namespace ComPDFKit.Tool
  17. {
  18. public partial class CPDFViewerTool
  19. {
  20. public CPDFViewer GetCPDFViewer()
  21. {
  22. return PDFViewer;
  23. }
  24. #region DefaultAnnot
  25. public void CreateDefaultAnnot(CPDFAnnotation cPDFAnnotation, C_ANNOTATION_TYPE annotType, AnnotParam annotParam)
  26. {
  27. switch (annotType)
  28. {
  29. case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
  30. break;
  31. case C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN:
  32. break;
  33. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  34. DefaultTextAnnot(cPDFAnnotation, annotParam);
  35. break;
  36. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  37. DefaultLinkAnnot(cPDFAnnotation, annotParam);
  38. break;
  39. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  40. DefaultFreeTextAnnot(cPDFAnnotation, annotParam);
  41. break;
  42. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  43. if (annotParam != null)
  44. {
  45. if (annotParam is LineMeasureParam)
  46. {
  47. DefaultLineMeasureAnnot(cPDFAnnotation, annotParam);
  48. }
  49. else
  50. {
  51. DefaultLineAnnot(cPDFAnnotation, annotParam);
  52. }
  53. }
  54. else
  55. {
  56. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  57. if (defaultSettingParam.IsOpenMeasure)
  58. {
  59. DefaultLineMeasureAnnot(cPDFAnnotation, annotParam);
  60. }
  61. else
  62. {
  63. DefaultLineAnnot(cPDFAnnotation, annotParam);
  64. }
  65. }
  66. break;
  67. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  68. DefaultSquareAnnot(cPDFAnnotation, annotParam);
  69. break;
  70. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  71. DefaultCircleAnnot(cPDFAnnotation, annotParam);
  72. break;
  73. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  74. DefaultPolygonMeasureAnnot(cPDFAnnotation, annotParam);
  75. break;
  76. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  77. DefaultPolyLineMeasureAnnot(cPDFAnnotation, annotParam);
  78. break;
  79. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  80. DefaultHighlightAnnot(cPDFAnnotation, annotParam);
  81. break;
  82. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  83. DefaultUnderlineAnnot(cPDFAnnotation, annotParam);
  84. break;
  85. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  86. DefaultSquigglyAnnot(cPDFAnnotation, annotParam);
  87. break;
  88. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  89. DefaultStrikeoutAnnot(cPDFAnnotation, annotParam);
  90. break;
  91. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  92. DefaultStampAnnot(cPDFAnnotation, annotParam);
  93. break;
  94. case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
  95. break;
  96. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  97. DefaultInkAnnot(cPDFAnnotation, annotParam);
  98. break;
  99. case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
  100. break;
  101. case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
  102. break;
  103. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  104. DefaultSoundAnnot(cPDFAnnotation, annotParam);
  105. break;
  106. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  107. break;
  108. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  109. break;
  110. case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
  111. break;
  112. case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
  113. break;
  114. case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
  115. break;
  116. case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
  117. break;
  118. case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
  119. break;
  120. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  121. break;
  122. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  123. DefaultRedactAnnot(cPDFAnnotation, annotParam);
  124. break;
  125. case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
  126. break;
  127. default:
  128. break;
  129. }
  130. }
  131. private void DefaultAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  132. {
  133. if (cPDFAnnotation == null || annotParam == null)
  134. {
  135. return;
  136. }
  137. if (!string.IsNullOrEmpty(annotParam.Content))
  138. {
  139. cPDFAnnotation.SetContent(annotParam.Content);
  140. }
  141. if (!string.IsNullOrEmpty(annotParam.Author))
  142. {
  143. cPDFAnnotation.SetAuthor(annotParam.Author);
  144. }
  145. if (!string.IsNullOrEmpty(annotParam.CreateTime))
  146. {
  147. cPDFAnnotation.SetCreationDate(annotParam.CreateTime);
  148. }
  149. if (!string.IsNullOrEmpty(annotParam.UpdateTime))
  150. {
  151. cPDFAnnotation.SetModifyDate(annotParam.UpdateTime);
  152. }
  153. cPDFAnnotation.SetIsLocked(annotParam.Locked);
  154. cPDFAnnotation.SetTransparency(annotParam.Transparency);
  155. }
  156. private void DefaultTextAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  157. {
  158. CPDFTextAnnotation TextAnnotation = (cPDFAnnotation as CPDFTextAnnotation);
  159. if (TextAnnotation == null)
  160. {
  161. return;
  162. }
  163. StickyNoteParam StickyNoteParamDef;
  164. if (annotParam == null)
  165. {
  166. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  167. StickyNoteParamDef = defaultSettingParam.StickyNoteParamDef;
  168. }
  169. else
  170. {
  171. StickyNoteParamDef = annotParam as StickyNoteParam;
  172. }
  173. TextAnnotation.SetColor(StickyNoteParamDef.StickyNoteColor);
  174. if(string.IsNullOrEmpty(StickyNoteParamDef.IconName)==false)
  175. {
  176. TextAnnotation.SetIconName(StickyNoteParamDef.IconName);
  177. }
  178. DefaultAnnot(cPDFAnnotation, StickyNoteParamDef);
  179. }
  180. private void DefaultLinkAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  181. {
  182. CPDFLinkAnnotation linkAnnotation = (cPDFAnnotation as CPDFLinkAnnotation);
  183. if (linkAnnotation == null)
  184. {
  185. return;
  186. }
  187. LinkParam linkParam;
  188. if (annotParam == null)
  189. {
  190. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  191. linkParam = defaultSettingParam.LinkParamDef;
  192. }
  193. else
  194. {
  195. linkParam = annotParam as LinkParam;
  196. }
  197. switch (linkParam.Action)
  198. {
  199. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  200. CPDFGoToAction gotoAction = new CPDFGoToAction();
  201. CPDFDestination destination = new CPDFDestination();
  202. destination.Position_X = linkParam.DestinationPosition.x;
  203. destination.Position_Y = linkParam.DestinationPosition.y;
  204. destination.PageIndex = linkParam.DestinationPageIndex;
  205. gotoAction.SetDestination(PDFViewer.GetDocument(), destination);
  206. linkAnnotation.SetLinkAction(gotoAction);
  207. break;
  208. case C_ACTION_TYPE.ACTION_TYPE_URI:
  209. CPDFUriAction uriAction = new CPDFUriAction();
  210. if (!string.IsNullOrEmpty(linkParam.Uri))
  211. {
  212. uriAction.SetUri(linkParam.Uri);
  213. }
  214. linkAnnotation.SetLinkAction(uriAction);
  215. break;
  216. default:
  217. break;
  218. }
  219. DefaultAnnot(cPDFAnnotation, linkParam);
  220. }
  221. private void DefaultFreeTextAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  222. {
  223. CPDFFreeTextAnnotation freeTextAnnotation = (cPDFAnnotation as CPDFFreeTextAnnotation);
  224. if (freeTextAnnotation == null)
  225. {
  226. return;
  227. }
  228. FreeTextParam FreeTextParam;
  229. if (annotParam == null)
  230. {
  231. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  232. FreeTextParam = defaultSettingParam.FreeTextParamDef;
  233. }
  234. else
  235. {
  236. FreeTextParam = annotParam as FreeTextParam;
  237. }
  238. freeTextAnnotation.SetFreetextAlignment((C_TEXT_ALIGNMENT)(int)FreeTextParam.Alignment);
  239. if (FreeTextParam.LineColor != null)
  240. {
  241. freeTextAnnotation.SetLineColor(FreeTextParam.LineColor);
  242. }
  243. freeTextAnnotation.SetBorderWidth(1);
  244. freeTextAnnotation.SetTransparency(FreeTextParam.Transparency);
  245. freeTextAnnotation.SetLineWidth((float)FreeTextParam.LineWidth);
  246. if (FreeTextParam.HasBgColor && freeTextAnnotation.BgColor.Length == 3)
  247. {
  248. freeTextAnnotation.SetBgColor(FreeTextParam.BgColor);
  249. }
  250. CTextAttribute textAttr = new CTextAttribute();
  251. textAttr.FontColor = FreeTextParam.FontColor;
  252. textAttr.FontSize = (float)FreeTextParam.FontSize;
  253. textAttr.FontName = FreeTextParam.FontName;
  254. freeTextAnnotation.SetFreetextDa(textAttr);
  255. DefaultAnnot(cPDFAnnotation, FreeTextParam);
  256. }
  257. private void DefaultLineAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  258. {
  259. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  260. if (LineAnnotation == null)
  261. {
  262. return;
  263. }
  264. LineParam lineParam;
  265. if (annotParam == null)
  266. {
  267. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  268. lineParam = defaultSettingParam.LineParamDef;
  269. }
  270. else
  271. {
  272. lineParam = annotParam as LineParam;
  273. }
  274. if (lineParam.LineColor != null)
  275. {
  276. LineAnnotation.SetLineColor(lineParam.LineColor);
  277. }
  278. if (lineParam.HasBgColor)
  279. {
  280. if (lineParam.BgColor != null)
  281. {
  282. LineAnnotation.SetBgColor(lineParam.BgColor);
  283. }
  284. }
  285. else
  286. {
  287. LineAnnotation.ClearBgColor();
  288. }
  289. LineAnnotation.SetLineWidth((float)lineParam.LineWidth);
  290. LineAnnotation.SetTransparency(lineParam.Transparency);
  291. if (lineParam.LineDash != null)
  292. {
  293. LineAnnotation.SetBorderStyle(lineParam.BorderStyle, lineParam.LineDash);
  294. }
  295. LineAnnotation.SetLineType(lineParam.HeadLineType, lineParam.TailLineType);
  296. DefaultAnnot(cPDFAnnotation, lineParam);
  297. }
  298. private void DefaultSquareAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  299. {
  300. CPDFSquareAnnotation SquareAnnotation = (cPDFAnnotation as CPDFSquareAnnotation);
  301. if (SquareAnnotation == null)
  302. {
  303. return;
  304. }
  305. SquareParam squareParam;
  306. if (annotParam == null)
  307. {
  308. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  309. squareParam = defaultSettingParam.SquareParamDef;
  310. }
  311. else
  312. {
  313. squareParam = annotParam as SquareParam;
  314. }
  315. if (squareParam.LineColor != null)
  316. {
  317. SquareAnnotation.SetLineColor(squareParam.LineColor);
  318. }
  319. if (squareParam.HasBgColor)
  320. {
  321. if (squareParam.BgColor != null)
  322. {
  323. SquareAnnotation.SetBgColor(squareParam.BgColor);
  324. }
  325. }
  326. else
  327. {
  328. SquareAnnotation.ClearBgColor();
  329. }
  330. SquareAnnotation.SetLineWidth((float)squareParam.LineWidth);
  331. SquareAnnotation.SetTransparency(squareParam.Transparency);
  332. if (squareParam.LineDash != null)
  333. {
  334. SquareAnnotation.SetBorderStyle(squareParam.BorderStyle, squareParam.LineDash);
  335. }
  336. DefaultAnnot(cPDFAnnotation, squareParam);
  337. }
  338. private void DefaultCircleAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  339. {
  340. CPDFCircleAnnotation circleAnnotation = (cPDFAnnotation as CPDFCircleAnnotation);
  341. if (circleAnnotation == null)
  342. {
  343. return;
  344. }
  345. CircleParam circleParam;
  346. if (annotParam == null)
  347. {
  348. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  349. circleParam = defaultSettingParam.CircleParamDef;
  350. }
  351. else
  352. {
  353. circleParam = annotParam as CircleParam;
  354. }
  355. if (circleParam.LineColor != null)
  356. {
  357. circleAnnotation.SetLineColor(circleParam.LineColor);
  358. }
  359. if (circleParam.HasBgColor)
  360. {
  361. if (circleParam.BgColor != null)
  362. {
  363. circleAnnotation.SetBgColor(circleParam.BgColor);
  364. }
  365. }
  366. else
  367. {
  368. circleAnnotation.ClearBgColor();
  369. }
  370. circleAnnotation.SetLineWidth((float)circleParam.LineWidth);
  371. circleAnnotation.SetTransparency(circleParam.Transparency);
  372. if (circleParam.LineDash != null)
  373. {
  374. circleAnnotation.SetBorderStyle(circleParam.BorderStyle, circleParam.LineDash);
  375. }
  376. DefaultAnnot(cPDFAnnotation, circleParam);
  377. }
  378. private void DefaultHighlightAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  379. {
  380. CPDFHighlightAnnotation highlightAnnotation = (cPDFAnnotation as CPDFHighlightAnnotation);
  381. if (highlightAnnotation == null)
  382. {
  383. return;
  384. }
  385. HighlightParam highlightParam;
  386. if (annotParam == null)
  387. {
  388. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  389. highlightParam = defaultSettingParam.HighlightParamDef;
  390. }
  391. else
  392. {
  393. highlightParam = annotParam as HighlightParam;
  394. }
  395. if (highlightParam.HighlightColor != null)
  396. {
  397. highlightAnnotation.SetColor(highlightParam.HighlightColor);
  398. }
  399. DefaultAnnot(cPDFAnnotation, highlightParam);
  400. }
  401. private void DefaultUnderlineAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  402. {
  403. CPDFUnderlineAnnotation highlightAnnotation = (cPDFAnnotation as CPDFUnderlineAnnotation);
  404. if (highlightAnnotation == null)
  405. {
  406. return;
  407. }
  408. UnderlineParam underlineParam;
  409. if (annotParam == null)
  410. {
  411. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  412. underlineParam = defaultSettingParam.UnderlineParamDef;
  413. }
  414. else
  415. {
  416. underlineParam = annotParam as UnderlineParam;
  417. }
  418. if (underlineParam.UnderlineColor != null)
  419. {
  420. highlightAnnotation.SetColor(underlineParam.UnderlineColor);
  421. }
  422. DefaultAnnot(cPDFAnnotation, underlineParam);
  423. }
  424. private void DefaultSquigglyAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  425. {
  426. CPDFSquigglyAnnotation squigglyAnnotation = (cPDFAnnotation as CPDFSquigglyAnnotation);
  427. if (squigglyAnnotation == null)
  428. {
  429. return;
  430. }
  431. SquigglyParam squigglyParam;
  432. if (annotParam == null)
  433. {
  434. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  435. squigglyParam = defaultSettingParam.SquigglyParamDef;
  436. }
  437. else
  438. {
  439. squigglyParam = annotParam as SquigglyParam;
  440. }
  441. if (squigglyParam.SquigglyColor != null)
  442. {
  443. squigglyAnnotation.SetColor(squigglyParam.SquigglyColor);
  444. }
  445. DefaultAnnot(cPDFAnnotation, squigglyParam);
  446. }
  447. private void DefaultStrikeoutAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  448. {
  449. CPDFStrikeoutAnnotation strikeoutAnnotation = (cPDFAnnotation as CPDFStrikeoutAnnotation);
  450. if (strikeoutAnnotation == null)
  451. {
  452. return;
  453. }
  454. StrikeoutParam strikeoutParam;
  455. if (annotParam == null)
  456. {
  457. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  458. strikeoutParam = defaultSettingParam.StrikeoutParamDef;
  459. }
  460. else
  461. {
  462. strikeoutParam = annotParam as StrikeoutParam;
  463. }
  464. if (strikeoutParam.StrikeoutColor != null)
  465. {
  466. strikeoutAnnotation.SetColor(strikeoutParam.StrikeoutColor);
  467. }
  468. DefaultAnnot(cPDFAnnotation, strikeoutParam);
  469. }
  470. private void DefaultStampAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  471. {
  472. CPDFStampAnnotation strikeoutAnnotation = (cPDFAnnotation as CPDFStampAnnotation);
  473. if (strikeoutAnnotation == null)
  474. {
  475. return;
  476. }
  477. StampParam stampParam;
  478. if (annotParam == null)
  479. {
  480. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  481. stampParam = defaultSettingParam.StampParamDef;
  482. }
  483. else
  484. {
  485. stampParam = annotParam as StampParam;
  486. }
  487. switch (stampParam.StampType)
  488. {
  489. case C_STAMP_TYPE.STANDARD_STAMP:
  490. {
  491. string stampText = stampParam.StampText;
  492. if (stampText == null)
  493. {
  494. stampText = string.Empty;
  495. }
  496. strikeoutAnnotation.SetStandardStamp(stampText, stampParam.Rotation);
  497. }
  498. break;
  499. case C_STAMP_TYPE.IMAGE_STAMP:
  500. {
  501. byte[] imageData = null;
  502. int imageWidth = 0;
  503. int imageHeight = 0;
  504. PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  505. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  506. {
  507. strikeoutAnnotation.SetRect(new CRect(0, imageHeight, imageWidth, 0));
  508. strikeoutAnnotation.SetImageStamp(
  509. imageData,
  510. imageWidth,
  511. imageHeight,
  512. stampParam.Rotation);
  513. }
  514. }
  515. break;
  516. case C_STAMP_TYPE.TEXT_STAMP:
  517. {
  518. string dateText = stampParam.DateText;
  519. string stampText = stampParam.StampText;
  520. if (dateText == null)
  521. {
  522. dateText = string.Empty;
  523. }
  524. if (stampText == null)
  525. {
  526. stampText = string.Empty;
  527. }
  528. strikeoutAnnotation.SetTextStamp(
  529. stampText,
  530. dateText,
  531. stampParam.TextStampShape,
  532. stampParam.TextStampColor,
  533. stampParam.Rotation);
  534. }
  535. break;
  536. default:
  537. break;
  538. }
  539. DefaultAnnot(cPDFAnnotation, stampParam);
  540. }
  541. private void DefaultInkAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  542. {
  543. CPDFInkAnnotation InkAnnotation = (cPDFAnnotation as CPDFInkAnnotation);
  544. if (InkAnnotation == null)
  545. {
  546. return;
  547. }
  548. InkParam inkParam;
  549. if (annotParam == null)
  550. {
  551. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  552. inkParam = defaultSettingParam.InkParamDef;
  553. }
  554. else
  555. {
  556. inkParam = annotParam as InkParam;
  557. }
  558. if (inkParam.InkColor != null)
  559. {
  560. InkAnnotation.SetInkColor(inkParam.InkColor);
  561. }
  562. InkAnnotation.SetThickness((float)inkParam.Thickness);
  563. CPDFInkAnnotation inkAnnot = cPDFAnnotation as CPDFInkAnnotation;
  564. inkAnnot.SetInkPath(inkParam.InkPath);
  565. if(inkParam.Dash!=null && inkParam.Dash.Length>0)
  566. {
  567. inkAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED,inkParam.Dash);
  568. }
  569. else
  570. {
  571. inkAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  572. }
  573. DefaultAnnot(cPDFAnnotation, inkParam);
  574. }
  575. private void DefaultSoundAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  576. {
  577. CPDFSoundAnnotation SoundAnnotation = (cPDFAnnotation as CPDFSoundAnnotation);
  578. if (SoundAnnotation == null)
  579. {
  580. return;
  581. }
  582. SoundParam soundParam;
  583. if (annotParam == null)
  584. {
  585. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  586. soundParam = defaultSettingParam.SoundParamDef;
  587. }
  588. else
  589. {
  590. soundParam = annotParam as SoundParam;
  591. }
  592. byte[] imageData = null;
  593. int imageWidth = 0;
  594. int imageHeight = 0;
  595. PDFHelp.ImageStreamToByte(soundParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  596. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  597. {
  598. SoundAnnotation.SetRect(new Import.CRect(0, imageHeight, imageWidth, 0));
  599. SoundAnnotation.SetSoundPath(
  600. imageData,
  601. imageWidth,
  602. imageHeight,
  603. soundParam.SoundFilePath);
  604. }
  605. DefaultAnnot(cPDFAnnotation, soundParam);
  606. }
  607. private void DefaultRedactAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  608. {
  609. CPDFRedactAnnotation redactAnnotation = (cPDFAnnotation as CPDFRedactAnnotation);
  610. if (redactAnnotation == null)
  611. {
  612. return;
  613. }
  614. RedactParam redactParam;
  615. if (annotParam == null)
  616. {
  617. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  618. redactParam = defaultSettingParam.RedactParamDef;
  619. }
  620. else
  621. {
  622. redactParam = annotParam as RedactParam;
  623. }
  624. if (redactParam.LineColor != null)
  625. {
  626. redactAnnotation.SetOutlineColor(redactParam.LineColor);
  627. }
  628. if (redactParam.BgColor != null)
  629. {
  630. redactAnnotation.SetFillColor(redactParam.BgColor);
  631. }
  632. redactAnnotation.SetTextAlignment(redactParam.Alignment);
  633. if (!string.IsNullOrEmpty(redactParam.OverlayText))
  634. {
  635. redactAnnotation.SetOverlayText(redactParam.OverlayText);
  636. }
  637. CTextAttribute textAttr = new CTextAttribute();
  638. byte[] fontColor = new byte[3];
  639. if (redactParam.FontColor != null && redactParam.FontColor.Length == 3)
  640. {
  641. fontColor = redactParam.FontColor;
  642. }
  643. textAttr.FontColor = fontColor;
  644. textAttr.FontSize = (float)redactParam.FontSize;
  645. textAttr.FontName = redactParam.FontName;
  646. redactAnnotation.SetTextAttribute(textAttr);
  647. DefaultAnnot(cPDFAnnotation, redactParam);
  648. }
  649. private void DefaultLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  650. {
  651. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  652. if (LineAnnotation == null)
  653. {
  654. return;
  655. }
  656. if (!LineAnnotation.IsMeasured() && annotParam != null)
  657. {
  658. return;
  659. }
  660. LineMeasureParam lineMeasureParam;
  661. if (annotParam == null)
  662. {
  663. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  664. lineMeasureParam = defaultSettingParam.LineMeasureParamDef;
  665. }
  666. else
  667. {
  668. lineMeasureParam = annotParam as LineMeasureParam;
  669. }
  670. if (lineMeasureParam.LineColor != null)
  671. {
  672. LineAnnotation.SetLineColor(lineMeasureParam.LineColor);
  673. }
  674. LineAnnotation.SetLineWidth((float)lineMeasureParam.LineWidth);
  675. if (lineMeasureParam.LineDash != null)
  676. {
  677. if (lineMeasureParam.LineDash.Length == 0)
  678. {
  679. LineAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  680. }
  681. else
  682. {
  683. LineAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, lineMeasureParam.LineDash);
  684. }
  685. }
  686. LineAnnotation.SetLineType(lineMeasureParam.HeadLineType, lineMeasureParam.TailLineType);
  687. CTextAttribute textAttribute = new CTextAttribute();
  688. textAttribute.FontColor = lineMeasureParam.FontColor;
  689. textAttribute.FontSize = (float)lineMeasureParam.FontSize;
  690. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(lineMeasureParam.FontName),
  691. lineMeasureParam.IsBold,
  692. lineMeasureParam.IsItalic);
  693. LineAnnotation.SetTextAttribute(textAttribute);
  694. if (lineMeasureParam.measureInfo != null)
  695. {
  696. CPDFDistanceMeasure polygonMeasure = LineAnnotation.GetDistanceMeasure();
  697. if (polygonMeasure != null)
  698. {
  699. polygonMeasure.SetMeasureInfo(lineMeasureParam.measureInfo);
  700. polygonMeasure.SetMeasureScale(lineMeasureParam.measureInfo.RulerBase, lineMeasureParam.measureInfo.RulerBaseUnit,
  701. lineMeasureParam.measureInfo.RulerTranslate, lineMeasureParam.measureInfo.RulerTranslateUnit);
  702. var x = polygonMeasure.UpdateAnnotMeasure();
  703. }
  704. }
  705. DefaultAnnot(cPDFAnnotation, lineMeasureParam);
  706. }
  707. private void DefaultPolygonMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  708. {
  709. CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
  710. if (PolyAnnotation == null)
  711. {
  712. return;
  713. }
  714. if (!PolyAnnotation.IsMeasured() && annotParam != null)
  715. {
  716. return;
  717. }
  718. PolygonMeasureParam MeasureParam;
  719. if (annotParam == null)
  720. {
  721. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  722. MeasureParam = defaultSettingParam.PolygonMeasureParamDef;
  723. }
  724. else
  725. {
  726. MeasureParam = annotParam as PolygonMeasureParam;
  727. }
  728. if (MeasureParam.LineColor != null)
  729. {
  730. PolyAnnotation.SetLineColor(MeasureParam.LineColor);
  731. }
  732. PolyAnnotation.SetLineWidth((float)MeasureParam.LineWidth);
  733. if (MeasureParam.LineDash != null)
  734. {
  735. if (MeasureParam.LineDash.Length == 0)
  736. {
  737. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  738. }
  739. else
  740. {
  741. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, MeasureParam.LineDash);
  742. }
  743. }
  744. if (MeasureParam.HasFillColor && MeasureParam.FillColor != null && MeasureParam.FillColor.Length == 3)
  745. {
  746. PolyAnnotation.SetBgColor(MeasureParam.FillColor);
  747. }
  748. CTextAttribute textAttribute = new CTextAttribute();
  749. textAttribute.FontColor = MeasureParam.FontColor;
  750. textAttribute.FontSize = (float)MeasureParam.FontSize;
  751. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(MeasureParam.FontName),
  752. MeasureParam.IsBold,
  753. MeasureParam.IsItalic);
  754. PolyAnnotation.SetTextAttribute(textAttribute);
  755. if (MeasureParam.measureInfo != null)
  756. {
  757. CPDFAreaMeasure polygonMeasure = PolyAnnotation.GetAreaMeasure();
  758. if (polygonMeasure != null)
  759. {
  760. polygonMeasure.SetMeasureInfo(MeasureParam.measureInfo);
  761. polygonMeasure.SetMeasureScale(MeasureParam.measureInfo.RulerBase, MeasureParam.measureInfo.RulerBaseUnit,
  762. MeasureParam.measureInfo.RulerTranslate, MeasureParam.measureInfo.RulerTranslateUnit);
  763. polygonMeasure.UpdateAnnotMeasure();
  764. }
  765. }
  766. DefaultAnnot(cPDFAnnotation, MeasureParam);
  767. }
  768. private void DefaultPolyLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  769. {
  770. CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
  771. if (PolyAnnotation == null)
  772. {
  773. return;
  774. }
  775. if (!PolyAnnotation.IsMeasured() && annotParam != null)
  776. {
  777. return;
  778. }
  779. PolyLineMeasureParam lineMeasureParam;
  780. if (annotParam == null)
  781. {
  782. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  783. lineMeasureParam = defaultSettingParam.PolyLineMeasureParamDef;
  784. }
  785. else
  786. {
  787. lineMeasureParam = annotParam as PolyLineMeasureParam;
  788. }
  789. if (lineMeasureParam.LineColor != null)
  790. {
  791. PolyAnnotation.SetLineColor(lineMeasureParam.LineColor);
  792. }
  793. PolyAnnotation.SetLineWidth((float)lineMeasureParam.LineWidth);
  794. if (lineMeasureParam.LineDash != null)
  795. {
  796. if (lineMeasureParam.LineDash.Length == 0)
  797. {
  798. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  799. }
  800. else
  801. {
  802. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, lineMeasureParam.LineDash);
  803. }
  804. }
  805. CTextAttribute textAttribute = new CTextAttribute();
  806. textAttribute.FontColor = lineMeasureParam.FontColor;
  807. textAttribute.FontSize = (float)lineMeasureParam.FontSize;
  808. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(lineMeasureParam.FontName),
  809. lineMeasureParam.IsBold,
  810. lineMeasureParam.IsItalic);
  811. PolyAnnotation.SetTextAttribute(textAttribute);
  812. if (lineMeasureParam.measureInfo != null)
  813. {
  814. CPDFPerimeterMeasure polygonMeasure = PolyAnnotation.GetPerimeterMeasure();
  815. if (polygonMeasure != null)
  816. {
  817. polygonMeasure.SetMeasureInfo(lineMeasureParam.measureInfo);
  818. polygonMeasure.SetMeasureScale(lineMeasureParam.measureInfo.RulerBase, lineMeasureParam.measureInfo.RulerBaseUnit,
  819. lineMeasureParam.measureInfo.RulerTranslate, lineMeasureParam.measureInfo.RulerTranslateUnit);
  820. polygonMeasure.UpdateAnnotMeasure();
  821. }
  822. }
  823. DefaultAnnot(cPDFAnnotation, lineMeasureParam);
  824. }
  825. #endregion
  826. #region DefaultWidget
  827. public void CreateDefaultWidget(CPDFAnnotation cPDFAnnotation, C_WIDGET_TYPE annotType, AnnotParam annotParam)
  828. {
  829. switch (annotType)
  830. {
  831. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  832. DefaultPushButton(cPDFAnnotation, annotParam);
  833. break;
  834. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  835. DefaultCheckBox(cPDFAnnotation, annotParam);
  836. break;
  837. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  838. DefaultRadioButton(cPDFAnnotation, annotParam);
  839. break;
  840. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  841. DefaultTextField(cPDFAnnotation, annotParam);
  842. break;
  843. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  844. DefaultComBoBox(cPDFAnnotation, annotParam);
  845. break;
  846. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  847. DefaultListBox(cPDFAnnotation, annotParam);
  848. break;
  849. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  850. DefaultSignatureFields(cPDFAnnotation, annotParam);
  851. break;
  852. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  853. break;
  854. default:
  855. break;
  856. }
  857. }
  858. private void DefaultWidget(CPDFWidget cPDFWidget, WidgetParm widgetParm)
  859. {
  860. if (cPDFWidget == null || widgetParm == null)
  861. {
  862. return;
  863. }
  864. cPDFWidget.SetWidgetBorderStyle(widgetParm.BorderStyle);
  865. if (widgetParm.HasLineColor)
  866. {
  867. if (widgetParm.LineColor != null)
  868. {
  869. cPDFWidget.SetWidgetBorderRGBColor(widgetParm.LineColor);
  870. }
  871. }
  872. else
  873. {
  874. cPDFWidget.ClearWidgetBorderRGBColor();
  875. }
  876. if (widgetParm.HasBgColor)
  877. {
  878. if (widgetParm.BgColor != null)
  879. {
  880. cPDFWidget.SetWidgetBgRGBColor(widgetParm.BgColor);
  881. }
  882. }
  883. else
  884. {
  885. cPDFWidget.ClearWidgetBgRGBColor();
  886. }
  887. cPDFWidget.SetBorderWidth((float)widgetParm.LineWidth);
  888. cPDFWidget.SetFlags(GetFormFlags(FormField.Visible, cPDFWidget));
  889. cPDFWidget.SetIsReadOnly(widgetParm.IsReadOnly);
  890. cPDFWidget.SetIsHidden(widgetParm.IsHidden);
  891. DefaultAnnot(cPDFWidget, widgetParm);
  892. }
  893. private void DefaultPushButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  894. {
  895. CPDFPushButtonWidget widget = (cPDFAnnotation as CPDFPushButtonWidget);
  896. if (widget == null)
  897. {
  898. return;
  899. }
  900. PushButtonParam pushButtonParam;
  901. if (annotParam == null)
  902. {
  903. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  904. pushButtonParam = defaultSettingParam.PushButtonParamDef;
  905. }
  906. else
  907. {
  908. pushButtonParam = annotParam as PushButtonParam;
  909. }
  910. CTextAttribute textAttr = new CTextAttribute();
  911. textAttr.FontColor = pushButtonParam.FontColor;
  912. textAttr.FontSize = (float)pushButtonParam.FontSize;
  913. FontType checkFontType = CFontNameHelper.GetFontType(pushButtonParam.FontName);
  914. textAttr.FontName = CFontNameHelper.ObtainFontName(
  915. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  916. pushButtonParam.IsBold,
  917. pushButtonParam.IsItalic);
  918. widget.SetTextAttribute(textAttr);
  919. if (!string.IsNullOrEmpty(pushButtonParam.FieldName))
  920. {
  921. widget.SetFieldName(pushButtonParam.FieldName);
  922. }
  923. else
  924. {
  925. widget.SetFieldName(string.Format("PushButton{0}", widget.Page.GetAnnotCount()));
  926. }
  927. if (!string.IsNullOrEmpty(pushButtonParam.Text))
  928. {
  929. widget.SetButtonTitle(pushButtonParam.Text);
  930. }
  931. switch (pushButtonParam.Action)
  932. {
  933. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  934. CPDFGoToAction gotoAction = new CPDFGoToAction();
  935. CPDFDestination destination = new CPDFDestination();
  936. destination.Position_X = pushButtonParam.DestinationPosition.x;
  937. destination.Position_Y = pushButtonParam.DestinationPosition.y;
  938. destination.PageIndex = pushButtonParam.DestinationPageIndex;
  939. gotoAction.SetDestination(PDFViewer.GetDocument(), destination);
  940. widget.SetButtonAction(gotoAction);
  941. break;
  942. case C_ACTION_TYPE.ACTION_TYPE_URI:
  943. CPDFUriAction uriAction = new CPDFUriAction();
  944. if (!string.IsNullOrEmpty(pushButtonParam.Uri))
  945. {
  946. uriAction.SetUri(pushButtonParam.Uri);
  947. }
  948. widget.SetButtonAction(uriAction);
  949. break;
  950. default:
  951. break;
  952. }
  953. DefaultWidget(widget, pushButtonParam);
  954. }
  955. private void DefaultCheckBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  956. {
  957. CPDFCheckBoxWidget widget = (cPDFAnnotation as CPDFCheckBoxWidget);
  958. if (widget == null)
  959. {
  960. return;
  961. }
  962. CheckBoxParam checkBoxParam;
  963. if (annotParam == null)
  964. {
  965. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  966. checkBoxParam = defaultSettingParam.CheckBoxParamDef;
  967. }
  968. else
  969. {
  970. checkBoxParam = annotParam as CheckBoxParam;
  971. }
  972. CTextAttribute textAttr = widget.GetTextAttribute();
  973. textAttr.FontColor = checkBoxParam.FontColor;
  974. textAttr.FontSize = (float)checkBoxParam.FontSize;
  975. bool isBold = IsBold(textAttr.FontName);
  976. bool isItalic = IsItalic(textAttr.FontName);
  977. FontType checkFontType = CFontNameHelper.GetFontType(checkBoxParam.FontName);
  978. textAttr.FontName = CFontNameHelper.ObtainFontName(
  979. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  980. isBold,
  981. isItalic);
  982. widget.SetTextAttribute(textAttr);
  983. if (!string.IsNullOrEmpty(checkBoxParam.FieldName))
  984. {
  985. widget.SetFieldName(checkBoxParam.FieldName);
  986. }
  987. else
  988. {
  989. widget.SetFieldName(string.Format("CheckBox{0}", widget.Page.GetAnnotCount()));
  990. }
  991. widget.SetWidgetCheckStyle(checkBoxParam.CheckStyle);
  992. widget.SetChecked(checkBoxParam.IsChecked);
  993. DefaultWidget(widget, checkBoxParam);
  994. }
  995. private void DefaultRadioButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  996. {
  997. CPDFRadioButtonWidget widget = (cPDFAnnotation as CPDFRadioButtonWidget);
  998. if (widget == null)
  999. {
  1000. return;
  1001. }
  1002. RadioButtonParam radioButtonParam;
  1003. if (annotParam == null)
  1004. {
  1005. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1006. radioButtonParam = defaultSettingParam.RadioButtonParamDef;
  1007. }
  1008. else
  1009. {
  1010. radioButtonParam = annotParam as RadioButtonParam;
  1011. }
  1012. CTextAttribute textAttr = widget.GetTextAttribute();
  1013. textAttr.FontColor = radioButtonParam.FontColor;
  1014. textAttr.FontSize = (float)radioButtonParam.FontSize;
  1015. bool isBold = IsBold(textAttr.FontName);
  1016. bool isItalic = IsItalic(textAttr.FontName);
  1017. FontType checkFontType = CFontNameHelper.GetFontType(radioButtonParam.FontName);
  1018. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1019. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1020. isBold,
  1021. isItalic);
  1022. widget.SetTextAttribute(textAttr);
  1023. if (!string.IsNullOrEmpty(radioButtonParam.FieldName))
  1024. {
  1025. widget.SetFieldName(radioButtonParam.FieldName);
  1026. }
  1027. else
  1028. {
  1029. widget.SetFieldName("RadioGroup1");
  1030. }
  1031. widget.SetWidgetCheckStyle(radioButtonParam.CheckStyle);
  1032. widget.SetChecked(radioButtonParam.IsChecked);
  1033. DefaultWidget(widget, radioButtonParam);
  1034. }
  1035. private void DefaultTextField(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1036. {
  1037. CPDFTextWidget widget = (cPDFAnnotation as CPDFTextWidget);
  1038. if (widget == null)
  1039. {
  1040. return;
  1041. }
  1042. TextBoxParam textBoxParam;
  1043. if (annotParam == null)
  1044. {
  1045. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1046. textBoxParam = defaultSettingParam.TextBoxParamDef;
  1047. }
  1048. else
  1049. {
  1050. textBoxParam = annotParam as TextBoxParam;
  1051. }
  1052. CTextAttribute textAttr = new CTextAttribute();
  1053. textAttr.FontColor = textBoxParam.FontColor;
  1054. textAttr.FontSize = (float)textBoxParam.FontSize;
  1055. FontType checkFontType = CFontNameHelper.GetFontType(textBoxParam.FontName);
  1056. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1057. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1058. textBoxParam.IsBold,
  1059. textBoxParam.IsItalic);
  1060. widget.SetTextAttribute(textAttr);
  1061. if (!string.IsNullOrEmpty(textBoxParam.FieldName))
  1062. {
  1063. widget.SetFieldName(textBoxParam.FieldName);
  1064. }
  1065. else
  1066. {
  1067. widget.SetFieldName(string.Format("TextField{0}", widget.Page.GetAnnotCount()));
  1068. }
  1069. widget.SetMultiLine(textBoxParam.IsMultiLine);
  1070. widget.SetJustification(textBoxParam.Alignment);
  1071. if (string.IsNullOrEmpty(textBoxParam.Text) == false)
  1072. {
  1073. widget.SetText(textBoxParam.Text);
  1074. }
  1075. DefaultWidget(widget, textBoxParam);
  1076. }
  1077. private void DefaultComBoBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1078. {
  1079. CPDFComboBoxWidget widget = (cPDFAnnotation as CPDFComboBoxWidget);
  1080. if (widget == null)
  1081. {
  1082. return;
  1083. }
  1084. ComboBoxParam comboBoxParam;
  1085. if (annotParam == null)
  1086. {
  1087. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1088. comboBoxParam = defaultSettingParam.ComboBoxParamDef;
  1089. }
  1090. else
  1091. {
  1092. comboBoxParam = annotParam as ComboBoxParam;
  1093. }
  1094. CTextAttribute textAttr = new CTextAttribute();
  1095. textAttr.FontColor = comboBoxParam.FontColor;
  1096. textAttr.FontSize = (float)comboBoxParam.FontSize;
  1097. FontType checkFontType = CFontNameHelper.GetFontType(comboBoxParam.FontName);
  1098. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1099. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1100. comboBoxParam.IsBold,
  1101. comboBoxParam.IsItalic);
  1102. widget.SetTextAttribute(textAttr);
  1103. if (!string.IsNullOrEmpty(comboBoxParam.FieldName))
  1104. {
  1105. widget.SetFieldName(comboBoxParam.FieldName);
  1106. }
  1107. else
  1108. {
  1109. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1110. }
  1111. if (comboBoxParam.OptionItems != null && comboBoxParam.OptionItems.Count > 0)
  1112. {
  1113. int addIndex = 0;
  1114. foreach (string key in comboBoxParam.OptionItems.Keys)
  1115. {
  1116. widget.AddOptionItem(addIndex, comboBoxParam.OptionItems[key], key);
  1117. addIndex++;
  1118. }
  1119. }
  1120. if (comboBoxParam.SelectItemsIndex != null && comboBoxParam.SelectItemsIndex.Count > 0)
  1121. {
  1122. widget.SelectItem(comboBoxParam.SelectItemsIndex[0]);
  1123. }
  1124. DefaultWidget(widget, comboBoxParam);
  1125. }
  1126. private void DefaultListBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1127. {
  1128. CPDFListBoxWidget widget = (cPDFAnnotation as CPDFListBoxWidget);
  1129. if (widget == null)
  1130. {
  1131. return;
  1132. }
  1133. ListBoxParam listBoxParam;
  1134. if (annotParam == null)
  1135. {
  1136. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1137. listBoxParam = defaultSettingParam.ListBoxParamDef;
  1138. }
  1139. else
  1140. {
  1141. listBoxParam = annotParam as ListBoxParam;
  1142. }
  1143. CTextAttribute textAttr = new CTextAttribute();
  1144. textAttr.FontColor = listBoxParam.FontColor;
  1145. textAttr.FontSize = (float)listBoxParam.FontSize;
  1146. FontType checkFontType = CFontNameHelper.GetFontType(listBoxParam.FontName);
  1147. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1148. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1149. listBoxParam.IsBold,
  1150. listBoxParam.IsItalic);
  1151. widget.SetTextAttribute(textAttr);
  1152. if (!string.IsNullOrEmpty(listBoxParam.FieldName))
  1153. {
  1154. widget.SetFieldName(listBoxParam.FieldName);
  1155. }
  1156. else
  1157. {
  1158. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1159. }
  1160. if (listBoxParam.OptionItems != null && listBoxParam.OptionItems.Count > 0)
  1161. {
  1162. int addIndex = 0;
  1163. foreach (string key in listBoxParam.OptionItems.Keys)
  1164. {
  1165. widget.AddOptionItem(addIndex, listBoxParam.OptionItems[key], key);
  1166. addIndex++;
  1167. }
  1168. }
  1169. if (listBoxParam.SelectItemsIndex != null && listBoxParam.SelectItemsIndex.Count > 0)
  1170. {
  1171. widget.SelectItem(listBoxParam.SelectItemsIndex[0]);
  1172. }
  1173. DefaultWidget(widget, listBoxParam);
  1174. }
  1175. private void DefaultSignatureFields(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1176. {
  1177. CPDFSignatureWidget widget = (cPDFAnnotation as CPDFSignatureWidget);
  1178. if (widget == null)
  1179. {
  1180. return;
  1181. }
  1182. SignatureParam signatureParam;
  1183. if (annotParam == null)
  1184. {
  1185. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1186. signatureParam = defaultSettingParam.SignatureParamDef;
  1187. }
  1188. else
  1189. {
  1190. signatureParam = annotParam as SignatureParam;
  1191. }
  1192. CTextAttribute textAttr = widget.GetTextAttribute();
  1193. textAttr.FontColor = signatureParam.FontColor;
  1194. textAttr.FontSize = (float)signatureParam.FontSize;
  1195. bool isBold = IsBold(textAttr.FontName);
  1196. bool isItalic = IsItalic(textAttr.FontName);
  1197. FontType checkFontType = CFontNameHelper.GetFontType(signatureParam.FontName);
  1198. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1199. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1200. isBold,
  1201. isItalic);
  1202. widget.SetTextAttribute(textAttr);
  1203. if (!string.IsNullOrEmpty(signatureParam.FieldName))
  1204. {
  1205. widget.SetFieldName(signatureParam.FieldName);
  1206. }
  1207. else
  1208. {
  1209. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1210. }
  1211. DefaultWidget(widget, signatureParam);
  1212. }
  1213. #endregion
  1214. }
  1215. }