CPDFViewerTool.DataMethod.cs 50 KB

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