CPDFViewerTool.DataMethod.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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. PolygonMeasureParam polyonMeasureParam;
  718. if (annotParam == null)
  719. {
  720. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  721. polyonMeasureParam = defaultSettingParam.PolygonMeasureParamDef;
  722. IsOpenMeasure = defaultSettingParam.IsOpenMeasure;
  723. }
  724. else
  725. {
  726. polyonMeasureParam = annotParam as PolygonMeasureParam;
  727. IsOpenMeasure = defaultSettingParam.IsOpenMeasure;
  728. }
  729. if (polyonMeasureParam.LineColor != null)
  730. {
  731. PolyAnnotation.SetLineColor(polyonMeasureParam.LineColor);
  732. }
  733. PolyAnnotation.SetLineWidth((float)polyonMeasureParam.LineWidth);
  734. if (polyonMeasureParam.LineDash != null)
  735. {
  736. if (polyonMeasureParam.LineDash.Length == 0)
  737. {
  738. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  739. }
  740. else
  741. {
  742. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, polyonMeasureParam.LineDash);
  743. }
  744. }
  745. if (polyonMeasureParam.HasFillColor && polyonMeasureParam.FillColor != null && polyonMeasureParam.FillColor.Length == 3)
  746. {
  747. PolyAnnotation.SetBgColor(polyonMeasureParam.FillColor);
  748. }
  749. if(polyonMeasureParam.BorderEffector != null)
  750. {
  751. PolyAnnotation.SetAnnotBorderEffector(polyonMeasureParam.BorderEffector);
  752. }
  753. if (polyonMeasureParam.SavePoints != null && polyonMeasureParam.SavePoints.Count>0)
  754. {
  755. PolyAnnotation.SetPoints(polyonMeasureParam.SavePoints);
  756. }
  757. if (IsOpenMeasure)
  758. {
  759. CTextAttribute textAttribute = new CTextAttribute();
  760. textAttribute.FontColor = polyonMeasureParam.FontColor;
  761. textAttribute.FontSize = (float)polyonMeasureParam.FontSize;
  762. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(polyonMeasureParam.FontName),
  763. polyonMeasureParam.IsBold,
  764. polyonMeasureParam.IsItalic);
  765. PolyAnnotation.SetTextAttribute(textAttribute);
  766. if (polyonMeasureParam.measureInfo != null)
  767. {
  768. CPDFAreaMeasure polygonMeasure = PolyAnnotation.GetAreaMeasure();
  769. if (polygonMeasure != null)
  770. {
  771. polygonMeasure.SetMeasureInfo(polyonMeasureParam.measureInfo);
  772. polygonMeasure.SetMeasureScale(polyonMeasureParam.measureInfo.RulerBase, polyonMeasureParam.measureInfo.RulerBaseUnit,
  773. polyonMeasureParam.measureInfo.RulerTranslate, polyonMeasureParam.measureInfo.RulerTranslateUnit);
  774. polygonMeasure.UpdateAnnotMeasure();
  775. }
  776. }
  777. }
  778. DefaultAnnot(cPDFAnnotation, polyonMeasureParam);
  779. }
  780. private void DefaultPolyLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  781. {
  782. CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
  783. if (PolyAnnotation == null)
  784. {
  785. return;
  786. }
  787. if (!PolyAnnotation.IsMeasured() && annotParam != null)
  788. {
  789. return;
  790. }
  791. PolyLineMeasureParam lineMeasureParam;
  792. if (annotParam == null)
  793. {
  794. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  795. lineMeasureParam = defaultSettingParam.PolyLineMeasureParamDef;
  796. }
  797. else
  798. {
  799. lineMeasureParam = annotParam as PolyLineMeasureParam;
  800. }
  801. if (lineMeasureParam.LineColor != null)
  802. {
  803. PolyAnnotation.SetLineColor(lineMeasureParam.LineColor);
  804. }
  805. PolyAnnotation.SetLineWidth((float)lineMeasureParam.LineWidth);
  806. if (lineMeasureParam.LineDash != null)
  807. {
  808. if (lineMeasureParam.LineDash.Length == 0)
  809. {
  810. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  811. }
  812. else
  813. {
  814. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, lineMeasureParam.LineDash);
  815. }
  816. }
  817. CTextAttribute textAttribute = new CTextAttribute();
  818. textAttribute.FontColor = lineMeasureParam.FontColor;
  819. textAttribute.FontSize = (float)lineMeasureParam.FontSize;
  820. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(lineMeasureParam.FontName),
  821. lineMeasureParam.IsBold,
  822. lineMeasureParam.IsItalic);
  823. PolyAnnotation.SetTextAttribute(textAttribute);
  824. if (lineMeasureParam.measureInfo != null)
  825. {
  826. CPDFPerimeterMeasure polygonMeasure = PolyAnnotation.GetPerimeterMeasure();
  827. if (polygonMeasure != null)
  828. {
  829. polygonMeasure.SetMeasureInfo(lineMeasureParam.measureInfo);
  830. polygonMeasure.SetMeasureScale(lineMeasureParam.measureInfo.RulerBase, lineMeasureParam.measureInfo.RulerBaseUnit,
  831. lineMeasureParam.measureInfo.RulerTranslate, lineMeasureParam.measureInfo.RulerTranslateUnit);
  832. polygonMeasure.UpdateAnnotMeasure();
  833. }
  834. }
  835. DefaultAnnot(cPDFAnnotation, lineMeasureParam);
  836. }
  837. #endregion
  838. #region DefaultWidget
  839. public void CreateDefaultWidget(CPDFAnnotation cPDFAnnotation, C_WIDGET_TYPE annotType, AnnotParam annotParam)
  840. {
  841. switch (annotType)
  842. {
  843. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  844. DefaultPushButton(cPDFAnnotation, annotParam);
  845. break;
  846. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  847. DefaultCheckBox(cPDFAnnotation, annotParam);
  848. break;
  849. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  850. DefaultRadioButton(cPDFAnnotation, annotParam);
  851. break;
  852. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  853. DefaultTextField(cPDFAnnotation, annotParam);
  854. break;
  855. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  856. DefaultComBoBox(cPDFAnnotation, annotParam);
  857. break;
  858. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  859. DefaultListBox(cPDFAnnotation, annotParam);
  860. break;
  861. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  862. DefaultSignatureFields(cPDFAnnotation, annotParam);
  863. break;
  864. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. private void DefaultWidget(CPDFWidget cPDFWidget, WidgetParm widgetParm)
  871. {
  872. if (cPDFWidget == null || widgetParm == null)
  873. {
  874. return;
  875. }
  876. cPDFWidget.SetWidgetBorderStyle(widgetParm.BorderStyle);
  877. if (widgetParm.HasLineColor)
  878. {
  879. if (widgetParm.LineColor != null)
  880. {
  881. cPDFWidget.SetWidgetBorderRGBColor(widgetParm.LineColor);
  882. }
  883. }
  884. else
  885. {
  886. cPDFWidget.ClearWidgetBorderRGBColor();
  887. }
  888. if (widgetParm.HasBgColor)
  889. {
  890. if (widgetParm.BgColor != null)
  891. {
  892. cPDFWidget.SetWidgetBgRGBColor(widgetParm.BgColor);
  893. }
  894. }
  895. else
  896. {
  897. cPDFWidget.ClearWidgetBgRGBColor();
  898. }
  899. cPDFWidget.SetBorderWidth((float)widgetParm.LineWidth);
  900. cPDFWidget.SetFlags(GetFormFlags(FormField.Visible, cPDFWidget));
  901. cPDFWidget.SetIsReadOnly(widgetParm.IsReadOnly);
  902. cPDFWidget.SetIsHidden(widgetParm.IsHidden);
  903. DefaultAnnot(cPDFWidget, widgetParm);
  904. }
  905. private void DefaultPushButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  906. {
  907. CPDFPushButtonWidget widget = (cPDFAnnotation as CPDFPushButtonWidget);
  908. if (widget == null)
  909. {
  910. return;
  911. }
  912. PushButtonParam pushButtonParam;
  913. if (annotParam == null)
  914. {
  915. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  916. pushButtonParam = defaultSettingParam.PushButtonParamDef;
  917. }
  918. else
  919. {
  920. pushButtonParam = annotParam as PushButtonParam;
  921. }
  922. CTextAttribute textAttr = new CTextAttribute();
  923. textAttr.FontColor = pushButtonParam.FontColor;
  924. textAttr.FontSize = (float)pushButtonParam.FontSize;
  925. textAttr.FontName = pushButtonParam.FontName;
  926. widget.SetTextAttribute(textAttr);
  927. if (!string.IsNullOrEmpty(pushButtonParam.FieldName))
  928. {
  929. widget.SetFieldName(pushButtonParam.FieldName);
  930. }
  931. else
  932. {
  933. widget.SetFieldName(string.Format("PushButton{0}", widget.Page.GetAnnotCount()));
  934. }
  935. if (!string.IsNullOrEmpty(pushButtonParam.Text))
  936. {
  937. widget.SetButtonTitle(pushButtonParam.Text);
  938. }
  939. switch (pushButtonParam.Action)
  940. {
  941. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  942. CPDFGoToAction gotoAction = new CPDFGoToAction();
  943. CPDFDestination destination = new CPDFDestination();
  944. destination.Position_X = pushButtonParam.DestinationPosition.x;
  945. destination.Position_Y = pushButtonParam.DestinationPosition.y;
  946. destination.PageIndex = pushButtonParam.DestinationPageIndex;
  947. gotoAction.SetDestination(PDFViewer.GetDocument(), destination);
  948. widget.SetButtonAction(gotoAction);
  949. break;
  950. case C_ACTION_TYPE.ACTION_TYPE_URI:
  951. CPDFUriAction uriAction = new CPDFUriAction();
  952. if (!string.IsNullOrEmpty(pushButtonParam.Uri))
  953. {
  954. uriAction.SetUri(pushButtonParam.Uri);
  955. }
  956. widget.SetButtonAction(uriAction);
  957. break;
  958. default:
  959. break;
  960. }
  961. DefaultWidget(widget, pushButtonParam);
  962. }
  963. private void DefaultCheckBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  964. {
  965. CPDFCheckBoxWidget widget = (cPDFAnnotation as CPDFCheckBoxWidget);
  966. if (widget == null)
  967. {
  968. return;
  969. }
  970. CheckBoxParam checkBoxParam;
  971. if (annotParam == null)
  972. {
  973. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  974. checkBoxParam = defaultSettingParam.CheckBoxParamDef;
  975. }
  976. else
  977. {
  978. checkBoxParam = annotParam as CheckBoxParam;
  979. }
  980. CTextAttribute textAttr = widget.GetTextAttribute();
  981. textAttr.FontColor = checkBoxParam.FontColor;
  982. textAttr.FontSize = (float)checkBoxParam.FontSize;
  983. bool isBold = IsBold(textAttr.FontName);
  984. bool isItalic = IsItalic(textAttr.FontName);
  985. FontType checkFontType = CFontNameHelper.GetFontType(checkBoxParam.FontName);
  986. textAttr.FontName = CFontNameHelper.ObtainFontName(
  987. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  988. isBold,
  989. isItalic);
  990. widget.SetTextAttribute(textAttr);
  991. if (!string.IsNullOrEmpty(checkBoxParam.FieldName))
  992. {
  993. widget.SetFieldName(checkBoxParam.FieldName);
  994. }
  995. else
  996. {
  997. widget.SetFieldName(string.Format("CheckBox{0}", widget.Page.GetAnnotCount()));
  998. }
  999. widget.SetWidgetCheckStyle(checkBoxParam.CheckStyle);
  1000. widget.SetChecked(checkBoxParam.IsChecked);
  1001. DefaultWidget(widget, checkBoxParam);
  1002. }
  1003. private void DefaultRadioButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1004. {
  1005. CPDFRadioButtonWidget widget = (cPDFAnnotation as CPDFRadioButtonWidget);
  1006. if (widget == null)
  1007. {
  1008. return;
  1009. }
  1010. RadioButtonParam radioButtonParam;
  1011. if (annotParam == null)
  1012. {
  1013. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1014. radioButtonParam = defaultSettingParam.RadioButtonParamDef;
  1015. }
  1016. else
  1017. {
  1018. radioButtonParam = annotParam as RadioButtonParam;
  1019. }
  1020. CTextAttribute textAttr = widget.GetTextAttribute();
  1021. textAttr.FontColor = radioButtonParam.FontColor;
  1022. textAttr.FontSize = (float)radioButtonParam.FontSize;
  1023. bool isBold = IsBold(textAttr.FontName);
  1024. bool isItalic = IsItalic(textAttr.FontName);
  1025. FontType checkFontType = CFontNameHelper.GetFontType(radioButtonParam.FontName);
  1026. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1027. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1028. isBold,
  1029. isItalic);
  1030. widget.SetTextAttribute(textAttr);
  1031. if (!string.IsNullOrEmpty(radioButtonParam.FieldName))
  1032. {
  1033. widget.SetFieldName(radioButtonParam.FieldName);
  1034. }
  1035. else
  1036. {
  1037. widget.SetFieldName("RadioGroup1");
  1038. }
  1039. widget.SetWidgetCheckStyle(radioButtonParam.CheckStyle);
  1040. widget.SetChecked(radioButtonParam.IsChecked);
  1041. DefaultWidget(widget, radioButtonParam);
  1042. }
  1043. private void DefaultTextField(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1044. {
  1045. CPDFTextWidget widget = (cPDFAnnotation as CPDFTextWidget);
  1046. if (widget == null)
  1047. {
  1048. return;
  1049. }
  1050. TextBoxParam textBoxParam;
  1051. if (annotParam == null)
  1052. {
  1053. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1054. textBoxParam = defaultSettingParam.TextBoxParamDef;
  1055. }
  1056. else
  1057. {
  1058. textBoxParam = annotParam as TextBoxParam;
  1059. }
  1060. CTextAttribute textAttr = new CTextAttribute();
  1061. textAttr.FontColor = textBoxParam.FontColor;
  1062. textAttr.FontSize = (float)textBoxParam.FontSize;
  1063. textAttr.FontName = textBoxParam.FontName;
  1064. widget.SetTextAttribute(textAttr);
  1065. if (!string.IsNullOrEmpty(textBoxParam.FieldName))
  1066. {
  1067. widget.SetFieldName(textBoxParam.FieldName);
  1068. }
  1069. else
  1070. {
  1071. widget.SetFieldName(string.Format("TextField{0}", widget.Page.GetAnnotCount()));
  1072. }
  1073. widget.SetMultiLine(textBoxParam.IsMultiLine);
  1074. widget.SetJustification(textBoxParam.Alignment);
  1075. if (string.IsNullOrEmpty(textBoxParam.Text) == false)
  1076. {
  1077. widget.SetText(textBoxParam.Text);
  1078. }
  1079. DefaultWidget(widget, textBoxParam);
  1080. }
  1081. private void DefaultComBoBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1082. {
  1083. CPDFComboBoxWidget widget = (cPDFAnnotation as CPDFComboBoxWidget);
  1084. if (widget == null)
  1085. {
  1086. return;
  1087. }
  1088. ComboBoxParam comboBoxParam;
  1089. if (annotParam == null)
  1090. {
  1091. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1092. comboBoxParam = defaultSettingParam.ComboBoxParamDef;
  1093. }
  1094. else
  1095. {
  1096. comboBoxParam = annotParam as ComboBoxParam;
  1097. }
  1098. CTextAttribute textAttr = new CTextAttribute();
  1099. textAttr.FontColor = comboBoxParam.FontColor;
  1100. textAttr.FontSize = (float)comboBoxParam.FontSize;
  1101. textAttr.FontName = comboBoxParam.FontName;
  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. textAttr.FontName = listBoxParam.FontName;
  1147. widget.SetTextAttribute(textAttr);
  1148. if (!string.IsNullOrEmpty(listBoxParam.FieldName))
  1149. {
  1150. widget.SetFieldName(listBoxParam.FieldName);
  1151. }
  1152. else
  1153. {
  1154. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1155. }
  1156. if (listBoxParam.OptionItems != null && listBoxParam.OptionItems.Count > 0)
  1157. {
  1158. int addIndex = 0;
  1159. foreach (string key in listBoxParam.OptionItems.Keys)
  1160. {
  1161. widget.AddOptionItem(addIndex, listBoxParam.OptionItems[key], key);
  1162. addIndex++;
  1163. }
  1164. }
  1165. if (listBoxParam.SelectItemsIndex != null && listBoxParam.SelectItemsIndex.Count > 0)
  1166. {
  1167. widget.SelectItem(listBoxParam.SelectItemsIndex[0]);
  1168. }
  1169. DefaultWidget(widget, listBoxParam);
  1170. }
  1171. private void DefaultSignatureFields(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1172. {
  1173. CPDFSignatureWidget widget = (cPDFAnnotation as CPDFSignatureWidget);
  1174. if (widget == null)
  1175. {
  1176. return;
  1177. }
  1178. SignatureParam signatureParam;
  1179. if (annotParam == null)
  1180. {
  1181. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1182. signatureParam = defaultSettingParam.SignatureParamDef;
  1183. }
  1184. else
  1185. {
  1186. signatureParam = annotParam as SignatureParam;
  1187. }
  1188. CTextAttribute textAttr = widget.GetTextAttribute();
  1189. textAttr.FontColor = signatureParam.FontColor;
  1190. textAttr.FontSize = (float)signatureParam.FontSize;
  1191. bool isBold = IsBold(textAttr.FontName);
  1192. bool isItalic = IsItalic(textAttr.FontName);
  1193. textAttr.FontName = signatureParam.FontName;
  1194. widget.SetTextAttribute(textAttr);
  1195. if (!string.IsNullOrEmpty(signatureParam.FieldName))
  1196. {
  1197. widget.SetFieldName(signatureParam.FieldName);
  1198. }
  1199. else
  1200. {
  1201. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1202. }
  1203. DefaultWidget(widget, signatureParam);
  1204. }
  1205. #endregion
  1206. }
  1207. }