CPDFViewerTool.DataMethod.cs 50 KB

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