CPDFViewerTool.DataMethod.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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. //补充保存虚线样式
  251. freeTextAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, FreeTextParam.Dash);
  252. }
  253. CTextAttribute textAttr = new CTextAttribute();
  254. textAttr.FontColor = FreeTextParam.FontColor;
  255. textAttr.FontSize = (float)FreeTextParam.FontSize;
  256. textAttr.FontName = FreeTextParam.FontName;
  257. freeTextAnnotation.SetFreetextDa(textAttr);
  258. DefaultAnnot(cPDFAnnotation, FreeTextParam);
  259. }
  260. private void DefaultLineAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  261. {
  262. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  263. if (LineAnnotation == null)
  264. {
  265. return;
  266. }
  267. LineParam lineParam;
  268. if (annotParam == null)
  269. {
  270. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  271. lineParam = defaultSettingParam.LineParamDef;
  272. }
  273. else
  274. {
  275. lineParam = annotParam as LineParam;
  276. }
  277. if (lineParam.LineColor != null)
  278. {
  279. LineAnnotation.SetLineColor(lineParam.LineColor);
  280. }
  281. if (lineParam.HasBgColor)
  282. {
  283. if (lineParam.BgColor != null)
  284. {
  285. LineAnnotation.SetBgColor(lineParam.BgColor);
  286. }
  287. }
  288. else
  289. {
  290. LineAnnotation.ClearBgColor();
  291. }
  292. LineAnnotation.SetLineWidth((float)lineParam.LineWidth);
  293. LineAnnotation.SetTransparency(lineParam.Transparency);
  294. if (lineParam.LineDash != null)
  295. {
  296. LineAnnotation.SetBorderStyle(lineParam.BorderStyle, lineParam.LineDash);
  297. }
  298. LineAnnotation.SetLineType(lineParam.HeadLineType, lineParam.TailLineType);
  299. DefaultAnnot(cPDFAnnotation, lineParam);
  300. }
  301. private void DefaultSquareAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  302. {
  303. CPDFSquareAnnotation SquareAnnotation = (cPDFAnnotation as CPDFSquareAnnotation);
  304. if (SquareAnnotation == null)
  305. {
  306. return;
  307. }
  308. SquareParam squareParam;
  309. if (annotParam == null)
  310. {
  311. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  312. squareParam = defaultSettingParam.SquareParamDef;
  313. }
  314. else
  315. {
  316. squareParam = annotParam as SquareParam;
  317. }
  318. if (squareParam.LineColor != null)
  319. {
  320. SquareAnnotation.SetLineColor(squareParam.LineColor);
  321. }
  322. if (squareParam.HasBgColor)
  323. {
  324. if (squareParam.BgColor != null)
  325. {
  326. SquareAnnotation.SetBgColor(squareParam.BgColor);
  327. }
  328. }
  329. else
  330. {
  331. SquareAnnotation.ClearBgColor();
  332. }
  333. SquareAnnotation.SetLineWidth((float)squareParam.LineWidth);
  334. SquareAnnotation.SetTransparency(squareParam.Transparency);
  335. if (squareParam.LineDash != null)
  336. {
  337. SquareAnnotation.SetBorderStyle(squareParam.BorderStyle, squareParam.LineDash);
  338. }
  339. DefaultAnnot(cPDFAnnotation, squareParam);
  340. }
  341. private void DefaultCircleAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  342. {
  343. CPDFCircleAnnotation circleAnnotation = (cPDFAnnotation as CPDFCircleAnnotation);
  344. if (circleAnnotation == null)
  345. {
  346. return;
  347. }
  348. CircleParam circleParam;
  349. if (annotParam == null)
  350. {
  351. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  352. circleParam = defaultSettingParam.CircleParamDef;
  353. }
  354. else
  355. {
  356. circleParam = annotParam as CircleParam;
  357. }
  358. if (circleParam.LineColor != null)
  359. {
  360. circleAnnotation.SetLineColor(circleParam.LineColor);
  361. }
  362. if (circleParam.HasBgColor)
  363. {
  364. if (circleParam.BgColor != null)
  365. {
  366. circleAnnotation.SetBgColor(circleParam.BgColor);
  367. }
  368. }
  369. else
  370. {
  371. circleAnnotation.ClearBgColor();
  372. }
  373. circleAnnotation.SetLineWidth((float)circleParam.LineWidth);
  374. circleAnnotation.SetTransparency(circleParam.Transparency);
  375. if (circleParam.LineDash != null)
  376. {
  377. circleAnnotation.SetBorderStyle(circleParam.BorderStyle, circleParam.LineDash);
  378. }
  379. DefaultAnnot(cPDFAnnotation, circleParam);
  380. }
  381. private void DefaultHighlightAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  382. {
  383. CPDFHighlightAnnotation highlightAnnotation = (cPDFAnnotation as CPDFHighlightAnnotation);
  384. if (highlightAnnotation == null)
  385. {
  386. return;
  387. }
  388. HighlightParam highlightParam;
  389. if (annotParam == null)
  390. {
  391. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  392. highlightParam = defaultSettingParam.HighlightParamDef;
  393. }
  394. else
  395. {
  396. highlightParam = annotParam as HighlightParam;
  397. }
  398. if (highlightParam.HighlightColor != null)
  399. {
  400. highlightAnnotation.SetColor(highlightParam.HighlightColor);
  401. }
  402. DefaultAnnot(cPDFAnnotation, highlightParam);
  403. }
  404. private void DefaultUnderlineAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  405. {
  406. CPDFUnderlineAnnotation highlightAnnotation = (cPDFAnnotation as CPDFUnderlineAnnotation);
  407. if (highlightAnnotation == null)
  408. {
  409. return;
  410. }
  411. UnderlineParam underlineParam;
  412. if (annotParam == null)
  413. {
  414. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  415. underlineParam = defaultSettingParam.UnderlineParamDef;
  416. }
  417. else
  418. {
  419. underlineParam = annotParam as UnderlineParam;
  420. }
  421. if (underlineParam.UnderlineColor != null)
  422. {
  423. highlightAnnotation.SetColor(underlineParam.UnderlineColor);
  424. }
  425. DefaultAnnot(cPDFAnnotation, underlineParam);
  426. }
  427. private void DefaultSquigglyAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  428. {
  429. CPDFSquigglyAnnotation squigglyAnnotation = (cPDFAnnotation as CPDFSquigglyAnnotation);
  430. if (squigglyAnnotation == null)
  431. {
  432. return;
  433. }
  434. SquigglyParam squigglyParam;
  435. if (annotParam == null)
  436. {
  437. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  438. squigglyParam = defaultSettingParam.SquigglyParamDef;
  439. }
  440. else
  441. {
  442. squigglyParam = annotParam as SquigglyParam;
  443. }
  444. if (squigglyParam.SquigglyColor != null)
  445. {
  446. squigglyAnnotation.SetColor(squigglyParam.SquigglyColor);
  447. }
  448. DefaultAnnot(cPDFAnnotation, squigglyParam);
  449. }
  450. private void DefaultStrikeoutAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  451. {
  452. CPDFStrikeoutAnnotation strikeoutAnnotation = (cPDFAnnotation as CPDFStrikeoutAnnotation);
  453. if (strikeoutAnnotation == null)
  454. {
  455. return;
  456. }
  457. StrikeoutParam strikeoutParam;
  458. if (annotParam == null)
  459. {
  460. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  461. strikeoutParam = defaultSettingParam.StrikeoutParamDef;
  462. }
  463. else
  464. {
  465. strikeoutParam = annotParam as StrikeoutParam;
  466. }
  467. if (strikeoutParam.StrikeoutColor != null)
  468. {
  469. strikeoutAnnotation.SetColor(strikeoutParam.StrikeoutColor);
  470. }
  471. DefaultAnnot(cPDFAnnotation, strikeoutParam);
  472. }
  473. private void DefaultStampAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  474. {
  475. CPDFStampAnnotation stampAnnot = (cPDFAnnotation as CPDFStampAnnotation);
  476. if (stampAnnot == null)
  477. {
  478. return;
  479. }
  480. StampParam stampParam;
  481. if (annotParam == null)
  482. {
  483. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  484. stampParam = defaultSettingParam.StampParamDef;
  485. }
  486. else
  487. {
  488. stampParam = annotParam as StampParam;
  489. }
  490. switch (stampParam.StampType)
  491. {
  492. case C_STAMP_TYPE.STANDARD_STAMP:
  493. {
  494. string stampText = stampParam.StampText;
  495. if (stampText == null)
  496. {
  497. stampText = string.Empty;
  498. }
  499. stampAnnot.SetStandardStamp(stampText, stampParam.PageRotation);
  500. }
  501. break;
  502. case C_STAMP_TYPE.IMAGE_STAMP:
  503. {
  504. byte[] imageData = null;
  505. int imageWidth = 0;
  506. int imageHeight = 0;
  507. PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  508. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  509. {
  510. stampAnnot.SetRect(new CRect(0, imageHeight, imageWidth, 0));
  511. stampAnnot.SetImageStamp(
  512. imageData,
  513. imageWidth,
  514. imageHeight,
  515. stampParam.PageRotation);
  516. }
  517. }
  518. break;
  519. case C_STAMP_TYPE.TEXT_STAMP:
  520. {
  521. string dateText = stampParam.DateText;
  522. string stampText = stampParam.StampText;
  523. if (dateText == null)
  524. {
  525. dateText = string.Empty;
  526. }
  527. if (stampText == null)
  528. {
  529. stampText = string.Empty;
  530. }
  531. stampAnnot.SetTextStamp(
  532. stampText,
  533. dateText,
  534. stampParam.TextStampShape,
  535. stampParam.TextStampColor,
  536. stampParam.PageRotation);
  537. }
  538. break;
  539. default:
  540. break;
  541. }
  542. stampAnnot.AnnotationRotator.SetRotation(stampParam.Rotation);
  543. DefaultAnnot(cPDFAnnotation, stampParam);
  544. }
  545. private void DefaultInkAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  546. {
  547. CPDFInkAnnotation InkAnnotation = (cPDFAnnotation as CPDFInkAnnotation);
  548. if (InkAnnotation == null)
  549. {
  550. return;
  551. }
  552. InkParam inkParam;
  553. if (annotParam == null)
  554. {
  555. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  556. inkParam = defaultSettingParam.InkParamDef;
  557. }
  558. else
  559. {
  560. inkParam = annotParam as InkParam;
  561. }
  562. if (inkParam.InkColor != null)
  563. {
  564. InkAnnotation.SetInkColor(inkParam.InkColor);
  565. }
  566. InkAnnotation.SetThickness((float)inkParam.Thickness);
  567. CPDFInkAnnotation inkAnnot = cPDFAnnotation as CPDFInkAnnotation;
  568. inkAnnot.SetInkPath(inkParam.InkPath);
  569. if (inkParam.Dash != null && inkParam.Dash.Length > 0)
  570. {
  571. inkAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, inkParam.Dash);
  572. }
  573. else
  574. {
  575. inkAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  576. }
  577. DefaultAnnot(cPDFAnnotation, inkParam);
  578. }
  579. private void DefaultSoundAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  580. {
  581. CPDFSoundAnnotation SoundAnnotation = (cPDFAnnotation as CPDFSoundAnnotation);
  582. if (SoundAnnotation == null)
  583. {
  584. return;
  585. }
  586. SoundParam soundParam;
  587. if (annotParam == null)
  588. {
  589. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  590. soundParam = defaultSettingParam.SoundParamDef;
  591. }
  592. else
  593. {
  594. soundParam = annotParam as SoundParam;
  595. }
  596. byte[] imageData = null;
  597. int imageWidth = 0;
  598. int imageHeight = 0;
  599. PDFHelp.ImageStreamToByte(soundParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  600. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  601. {
  602. SoundAnnotation.SetRect(new Import.CRect(0, imageHeight, imageWidth, 0));
  603. SoundAnnotation.SetSoundPath(
  604. imageData,
  605. imageWidth,
  606. imageHeight,
  607. soundParam.SoundFilePath);
  608. }
  609. DefaultAnnot(cPDFAnnotation, soundParam);
  610. }
  611. private void DefaultRedactAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  612. {
  613. CPDFRedactAnnotation redactAnnotation = (cPDFAnnotation as CPDFRedactAnnotation);
  614. if (redactAnnotation == null)
  615. {
  616. return;
  617. }
  618. RedactParam redactParam;
  619. if (annotParam == null)
  620. {
  621. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  622. redactParam = defaultSettingParam.RedactParamDef;
  623. }
  624. else
  625. {
  626. redactParam = annotParam as RedactParam;
  627. }
  628. if (redactParam.LineColor != null)
  629. {
  630. redactAnnotation.SetOutlineColor(redactParam.LineColor);
  631. }
  632. if (redactParam.BgColor != null)
  633. {
  634. redactAnnotation.SetFillColor(redactParam.BgColor);
  635. }
  636. redactAnnotation.SetTextAlignment(redactParam.Alignment);
  637. if (!string.IsNullOrEmpty(redactParam.OverlayText))
  638. {
  639. redactAnnotation.SetOverlayText(redactParam.OverlayText);
  640. }
  641. CTextAttribute textAttr = new CTextAttribute();
  642. byte[] fontColor = new byte[3];
  643. if (redactParam.FontColor != null && redactParam.FontColor.Length == 3)
  644. {
  645. fontColor = redactParam.FontColor;
  646. }
  647. textAttr.FontColor = fontColor;
  648. textAttr.FontSize = (float)redactParam.FontSize;
  649. textAttr.FontName = redactParam.FontName;
  650. redactAnnotation.SetTextAttribute(textAttr);
  651. DefaultAnnot(cPDFAnnotation, redactParam);
  652. }
  653. private void DefaultLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  654. {
  655. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  656. if (LineAnnotation == null)
  657. {
  658. return;
  659. }
  660. if (!LineAnnotation.IsMeasured() && annotParam != null)
  661. {
  662. return;
  663. }
  664. LineMeasureParam lineMeasureParam;
  665. if (annotParam == null)
  666. {
  667. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  668. lineMeasureParam = defaultSettingParam.LineMeasureParamDef;
  669. }
  670. else
  671. {
  672. lineMeasureParam = annotParam as LineMeasureParam;
  673. }
  674. if (lineMeasureParam.LineColor != null)
  675. {
  676. LineAnnotation.SetLineColor(lineMeasureParam.LineColor);
  677. }
  678. LineAnnotation.SetLineWidth((float)lineMeasureParam.LineWidth);
  679. if (lineMeasureParam.LineDash != null)
  680. {
  681. if (lineMeasureParam.LineDash.Length == 0)
  682. {
  683. LineAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  684. }
  685. else
  686. {
  687. LineAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, lineMeasureParam.LineDash);
  688. }
  689. }
  690. LineAnnotation.SetLineType(lineMeasureParam.HeadLineType, lineMeasureParam.TailLineType);
  691. CTextAttribute textAttribute = new CTextAttribute();
  692. textAttribute.FontColor = lineMeasureParam.FontColor;
  693. textAttribute.FontSize = (float)lineMeasureParam.FontSize;
  694. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(lineMeasureParam.FontName),
  695. lineMeasureParam.IsBold,
  696. lineMeasureParam.IsItalic);
  697. LineAnnotation.SetTextAttribute(textAttribute);
  698. if (lineMeasureParam.measureInfo != null)
  699. {
  700. CPDFDistanceMeasure polygonMeasure = LineAnnotation.GetDistanceMeasure();
  701. if (polygonMeasure != null)
  702. {
  703. polygonMeasure.SetMeasureInfo(lineMeasureParam.measureInfo);
  704. polygonMeasure.SetMeasureScale(lineMeasureParam.measureInfo.RulerBase, lineMeasureParam.measureInfo.RulerBaseUnit,
  705. lineMeasureParam.measureInfo.RulerTranslate, lineMeasureParam.measureInfo.RulerTranslateUnit);
  706. var x = polygonMeasure.UpdateAnnotMeasure();
  707. }
  708. }
  709. DefaultAnnot(cPDFAnnotation, lineMeasureParam);
  710. }
  711. private void DefaultPolygonMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  712. {
  713. CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
  714. bool IsOpenMeasure = true;
  715. if (PolyAnnotation == null)
  716. {
  717. return;
  718. }
  719. if (annotParam != null)
  720. {
  721. return;
  722. }
  723. PolygonMeasureParam MeasureParam;
  724. if (annotParam == null)
  725. {
  726. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  727. MeasureParam = defaultSettingParam.PolygonMeasureParamDef;
  728. IsOpenMeasure = defaultSettingParam.IsOpenMeasure;
  729. }
  730. else
  731. {
  732. MeasureParam = annotParam as PolygonMeasureParam;
  733. IsOpenMeasure = defaultSettingParam.IsOpenMeasure;
  734. }
  735. if (MeasureParam.LineColor != null)
  736. {
  737. PolyAnnotation.SetLineColor(MeasureParam.LineColor);
  738. }
  739. PolyAnnotation.SetLineWidth((float)MeasureParam.LineWidth);
  740. if (MeasureParam.LineDash != null)
  741. {
  742. if (MeasureParam.LineDash.Length == 0)
  743. {
  744. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  745. }
  746. else
  747. {
  748. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, MeasureParam.LineDash);
  749. }
  750. }
  751. if (MeasureParam.HasFillColor && MeasureParam.FillColor != null && MeasureParam.FillColor.Length == 3)
  752. {
  753. PolyAnnotation.SetBgColor(MeasureParam.FillColor);
  754. }
  755. if(MeasureParam.BorderEffector != null)
  756. {
  757. PolyAnnotation.SetAnnotBorderEffector(MeasureParam.BorderEffector);
  758. }
  759. if (IsOpenMeasure)
  760. {
  761. CTextAttribute textAttribute = new CTextAttribute();
  762. textAttribute.FontColor = MeasureParam.FontColor;
  763. textAttribute.FontSize = (float)MeasureParam.FontSize;
  764. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(MeasureParam.FontName),
  765. MeasureParam.IsBold,
  766. MeasureParam.IsItalic);
  767. PolyAnnotation.SetTextAttribute(textAttribute);
  768. if (MeasureParam.measureInfo != null)
  769. {
  770. CPDFAreaMeasure polygonMeasure = PolyAnnotation.GetAreaMeasure();
  771. if (polygonMeasure != null)
  772. {
  773. polygonMeasure.SetMeasureInfo(MeasureParam.measureInfo);
  774. polygonMeasure.SetMeasureScale(MeasureParam.measureInfo.RulerBase, MeasureParam.measureInfo.RulerBaseUnit,
  775. MeasureParam.measureInfo.RulerTranslate, MeasureParam.measureInfo.RulerTranslateUnit);
  776. polygonMeasure.UpdateAnnotMeasure();
  777. }
  778. }
  779. cPDFAnnotation.UpdateAp();
  780. }
  781. DefaultAnnot(cPDFAnnotation, MeasureParam);
  782. }
  783. private void DefaultPolyLineMeasureAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  784. {
  785. CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
  786. if (PolyAnnotation == null)
  787. {
  788. return;
  789. }
  790. if (!PolyAnnotation.IsMeasured() && annotParam != null)
  791. {
  792. return;
  793. }
  794. PolyLineMeasureParam lineMeasureParam;
  795. if (annotParam == null)
  796. {
  797. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  798. lineMeasureParam = defaultSettingParam.PolyLineMeasureParamDef;
  799. }
  800. else
  801. {
  802. lineMeasureParam = annotParam as PolyLineMeasureParam;
  803. }
  804. if (lineMeasureParam.LineColor != null)
  805. {
  806. PolyAnnotation.SetLineColor(lineMeasureParam.LineColor);
  807. }
  808. PolyAnnotation.SetLineWidth((float)lineMeasureParam.LineWidth);
  809. if (lineMeasureParam.LineDash != null)
  810. {
  811. if (lineMeasureParam.LineDash.Length == 0)
  812. {
  813. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
  814. }
  815. else
  816. {
  817. PolyAnnotation.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, lineMeasureParam.LineDash);
  818. }
  819. }
  820. CTextAttribute textAttribute = new CTextAttribute();
  821. textAttribute.FontColor = lineMeasureParam.FontColor;
  822. textAttribute.FontSize = (float)lineMeasureParam.FontSize;
  823. textAttribute.FontName = CFontNameHelper.ObtainFontName(CFontNameHelper.GetFontType(lineMeasureParam.FontName),
  824. lineMeasureParam.IsBold,
  825. lineMeasureParam.IsItalic);
  826. PolyAnnotation.SetTextAttribute(textAttribute);
  827. if (lineMeasureParam.measureInfo != null)
  828. {
  829. CPDFPerimeterMeasure polygonMeasure = PolyAnnotation.GetPerimeterMeasure();
  830. if (polygonMeasure != null)
  831. {
  832. polygonMeasure.SetMeasureInfo(lineMeasureParam.measureInfo);
  833. polygonMeasure.SetMeasureScale(lineMeasureParam.measureInfo.RulerBase, lineMeasureParam.measureInfo.RulerBaseUnit,
  834. lineMeasureParam.measureInfo.RulerTranslate, lineMeasureParam.measureInfo.RulerTranslateUnit);
  835. polygonMeasure.UpdateAnnotMeasure();
  836. }
  837. }
  838. DefaultAnnot(cPDFAnnotation, lineMeasureParam);
  839. }
  840. #endregion
  841. #region DefaultWidget
  842. public void CreateDefaultWidget(CPDFAnnotation cPDFAnnotation, C_WIDGET_TYPE annotType, AnnotParam annotParam)
  843. {
  844. switch (annotType)
  845. {
  846. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  847. DefaultPushButton(cPDFAnnotation, annotParam);
  848. break;
  849. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  850. DefaultCheckBox(cPDFAnnotation, annotParam);
  851. break;
  852. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  853. DefaultRadioButton(cPDFAnnotation, annotParam);
  854. break;
  855. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  856. DefaultTextField(cPDFAnnotation, annotParam);
  857. break;
  858. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  859. DefaultComBoBox(cPDFAnnotation, annotParam);
  860. break;
  861. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  862. DefaultListBox(cPDFAnnotation, annotParam);
  863. break;
  864. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  865. DefaultSignatureFields(cPDFAnnotation, annotParam);
  866. break;
  867. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  868. break;
  869. default:
  870. break;
  871. }
  872. }
  873. private void DefaultWidget(CPDFWidget cPDFWidget, WidgetParm widgetParm)
  874. {
  875. if (cPDFWidget == null || widgetParm == null)
  876. {
  877. return;
  878. }
  879. cPDFWidget.SetWidgetBorderStyle(widgetParm.BorderStyle);
  880. if (widgetParm.HasLineColor)
  881. {
  882. if (widgetParm.LineColor != null)
  883. {
  884. cPDFWidget.SetWidgetBorderRGBColor(widgetParm.LineColor);
  885. }
  886. }
  887. else
  888. {
  889. cPDFWidget.ClearWidgetBorderRGBColor();
  890. }
  891. if (widgetParm.HasBgColor)
  892. {
  893. if (widgetParm.BgColor != null)
  894. {
  895. cPDFWidget.SetWidgetBgRGBColor(widgetParm.BgColor);
  896. }
  897. }
  898. else
  899. {
  900. cPDFWidget.ClearWidgetBgRGBColor();
  901. }
  902. cPDFWidget.SetBorderWidth((float)widgetParm.LineWidth);
  903. cPDFWidget.SetFlags(GetFormFlags(FormField.Visible, cPDFWidget));
  904. cPDFWidget.SetIsReadOnly(widgetParm.IsReadOnly);
  905. cPDFWidget.SetIsHidden(widgetParm.IsHidden);
  906. DefaultAnnot(cPDFWidget, widgetParm);
  907. }
  908. private void DefaultPushButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  909. {
  910. CPDFPushButtonWidget widget = (cPDFAnnotation as CPDFPushButtonWidget);
  911. if (widget == null)
  912. {
  913. return;
  914. }
  915. PushButtonParam pushButtonParam;
  916. if (annotParam == null)
  917. {
  918. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  919. pushButtonParam = defaultSettingParam.PushButtonParamDef;
  920. }
  921. else
  922. {
  923. pushButtonParam = annotParam as PushButtonParam;
  924. }
  925. CTextAttribute textAttr = new CTextAttribute();
  926. textAttr.FontColor = pushButtonParam.FontColor;
  927. textAttr.FontSize = (float)pushButtonParam.FontSize;
  928. textAttr.FontName = pushButtonParam.FontName;
  929. widget.SetTextAttribute(textAttr);
  930. if (!string.IsNullOrEmpty(pushButtonParam.FieldName))
  931. {
  932. widget.SetFieldName(pushButtonParam.FieldName);
  933. }
  934. else
  935. {
  936. widget.SetFieldName(string.Format("PushButton{0}", widget.Page.GetAnnotCount()));
  937. }
  938. if (!string.IsNullOrEmpty(pushButtonParam.Text))
  939. {
  940. widget.SetButtonTitle(pushButtonParam.Text);
  941. }
  942. switch (pushButtonParam.Action)
  943. {
  944. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  945. CPDFGoToAction gotoAction = new CPDFGoToAction();
  946. CPDFDestination destination = new CPDFDestination();
  947. destination.Position_X = pushButtonParam.DestinationPosition.x;
  948. destination.Position_Y = pushButtonParam.DestinationPosition.y;
  949. destination.PageIndex = pushButtonParam.DestinationPageIndex;
  950. gotoAction.SetDestination(PDFViewer.GetDocument(), destination);
  951. widget.SetButtonAction(gotoAction);
  952. break;
  953. case C_ACTION_TYPE.ACTION_TYPE_URI:
  954. CPDFUriAction uriAction = new CPDFUriAction();
  955. if (!string.IsNullOrEmpty(pushButtonParam.Uri))
  956. {
  957. uriAction.SetUri(pushButtonParam.Uri);
  958. }
  959. widget.SetButtonAction(uriAction);
  960. break;
  961. default:
  962. break;
  963. }
  964. DefaultWidget(widget, pushButtonParam);
  965. }
  966. private void DefaultCheckBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  967. {
  968. CPDFCheckBoxWidget widget = (cPDFAnnotation as CPDFCheckBoxWidget);
  969. if (widget == null)
  970. {
  971. return;
  972. }
  973. CheckBoxParam checkBoxParam;
  974. if (annotParam == null)
  975. {
  976. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  977. checkBoxParam = defaultSettingParam.CheckBoxParamDef;
  978. }
  979. else
  980. {
  981. checkBoxParam = annotParam as CheckBoxParam;
  982. }
  983. CTextAttribute textAttr = widget.GetTextAttribute();
  984. textAttr.FontColor = checkBoxParam.FontColor;
  985. textAttr.FontSize = (float)checkBoxParam.FontSize;
  986. bool isBold = IsBold(textAttr.FontName);
  987. bool isItalic = IsItalic(textAttr.FontName);
  988. FontType checkFontType = CFontNameHelper.GetFontType(checkBoxParam.FontName);
  989. textAttr.FontName = CFontNameHelper.ObtainFontName(
  990. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  991. isBold,
  992. isItalic);
  993. widget.SetTextAttribute(textAttr);
  994. if (!string.IsNullOrEmpty(checkBoxParam.FieldName))
  995. {
  996. widget.SetFieldName(checkBoxParam.FieldName);
  997. }
  998. else
  999. {
  1000. widget.SetFieldName(string.Format("CheckBox{0}", widget.Page.GetAnnotCount()));
  1001. }
  1002. widget.SetWidgetCheckStyle(checkBoxParam.CheckStyle);
  1003. widget.SetChecked(checkBoxParam.IsChecked);
  1004. DefaultWidget(widget, checkBoxParam);
  1005. }
  1006. private void DefaultRadioButton(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1007. {
  1008. CPDFRadioButtonWidget widget = (cPDFAnnotation as CPDFRadioButtonWidget);
  1009. if (widget == null)
  1010. {
  1011. return;
  1012. }
  1013. RadioButtonParam radioButtonParam;
  1014. if (annotParam == null)
  1015. {
  1016. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1017. radioButtonParam = defaultSettingParam.RadioButtonParamDef;
  1018. }
  1019. else
  1020. {
  1021. radioButtonParam = annotParam as RadioButtonParam;
  1022. }
  1023. CTextAttribute textAttr = widget.GetTextAttribute();
  1024. textAttr.FontColor = radioButtonParam.FontColor;
  1025. textAttr.FontSize = (float)radioButtonParam.FontSize;
  1026. bool isBold = IsBold(textAttr.FontName);
  1027. bool isItalic = IsItalic(textAttr.FontName);
  1028. FontType checkFontType = CFontNameHelper.GetFontType(radioButtonParam.FontName);
  1029. textAttr.FontName = CFontNameHelper.ObtainFontName(
  1030. checkFontType == FontType.Unknown ? FontType.Helvetica : checkFontType,
  1031. isBold,
  1032. isItalic);
  1033. widget.SetTextAttribute(textAttr);
  1034. if (!string.IsNullOrEmpty(radioButtonParam.FieldName))
  1035. {
  1036. widget.SetFieldName(radioButtonParam.FieldName);
  1037. }
  1038. else
  1039. {
  1040. widget.SetFieldName("RadioGroup1");
  1041. }
  1042. widget.SetWidgetCheckStyle(radioButtonParam.CheckStyle);
  1043. widget.SetChecked(radioButtonParam.IsChecked);
  1044. DefaultWidget(widget, radioButtonParam);
  1045. }
  1046. private void DefaultTextField(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1047. {
  1048. CPDFTextWidget widget = (cPDFAnnotation as CPDFTextWidget);
  1049. if (widget == null)
  1050. {
  1051. return;
  1052. }
  1053. TextBoxParam textBoxParam;
  1054. if (annotParam == null)
  1055. {
  1056. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1057. textBoxParam = defaultSettingParam.TextBoxParamDef;
  1058. }
  1059. else
  1060. {
  1061. textBoxParam = annotParam as TextBoxParam;
  1062. }
  1063. CTextAttribute textAttr = new CTextAttribute();
  1064. textAttr.FontColor = textBoxParam.FontColor;
  1065. textAttr.FontSize = (float)textBoxParam.FontSize;
  1066. textAttr.FontName = textBoxParam.FontName;
  1067. widget.SetTextAttribute(textAttr);
  1068. if (!string.IsNullOrEmpty(textBoxParam.FieldName))
  1069. {
  1070. widget.SetFieldName(textBoxParam.FieldName);
  1071. }
  1072. else
  1073. {
  1074. widget.SetFieldName(string.Format("TextField{0}", widget.Page.GetAnnotCount()));
  1075. }
  1076. widget.SetMultiLine(textBoxParam.IsMultiLine);
  1077. widget.SetJustification(textBoxParam.Alignment);
  1078. if (string.IsNullOrEmpty(textBoxParam.Text) == false)
  1079. {
  1080. widget.SetText(textBoxParam.Text);
  1081. }
  1082. DefaultWidget(widget, textBoxParam);
  1083. }
  1084. private void DefaultComBoBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1085. {
  1086. CPDFComboBoxWidget widget = (cPDFAnnotation as CPDFComboBoxWidget);
  1087. if (widget == null)
  1088. {
  1089. return;
  1090. }
  1091. ComboBoxParam comboBoxParam;
  1092. if (annotParam == null)
  1093. {
  1094. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1095. comboBoxParam = defaultSettingParam.ComboBoxParamDef;
  1096. }
  1097. else
  1098. {
  1099. comboBoxParam = annotParam as ComboBoxParam;
  1100. }
  1101. CTextAttribute textAttr = new CTextAttribute();
  1102. textAttr.FontColor = comboBoxParam.FontColor;
  1103. textAttr.FontSize = (float)comboBoxParam.FontSize;
  1104. textAttr.FontName = comboBoxParam.FontName;
  1105. widget.SetTextAttribute(textAttr);
  1106. if (!string.IsNullOrEmpty(comboBoxParam.FieldName))
  1107. {
  1108. widget.SetFieldName(comboBoxParam.FieldName);
  1109. }
  1110. else
  1111. {
  1112. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1113. }
  1114. if (comboBoxParam.OptionItems != null && comboBoxParam.OptionItems.Count > 0)
  1115. {
  1116. int addIndex = 0;
  1117. foreach (string key in comboBoxParam.OptionItems.Keys)
  1118. {
  1119. widget.AddOptionItem(addIndex, comboBoxParam.OptionItems[key], key);
  1120. addIndex++;
  1121. }
  1122. }
  1123. if (comboBoxParam.SelectItemsIndex != null && comboBoxParam.SelectItemsIndex.Count > 0)
  1124. {
  1125. widget.SelectItem(comboBoxParam.SelectItemsIndex[0]);
  1126. }
  1127. DefaultWidget(widget, comboBoxParam);
  1128. }
  1129. private void DefaultListBox(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1130. {
  1131. CPDFListBoxWidget widget = (cPDFAnnotation as CPDFListBoxWidget);
  1132. if (widget == null)
  1133. {
  1134. return;
  1135. }
  1136. ListBoxParam listBoxParam;
  1137. if (annotParam == null)
  1138. {
  1139. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1140. listBoxParam = defaultSettingParam.ListBoxParamDef;
  1141. }
  1142. else
  1143. {
  1144. listBoxParam = annotParam as ListBoxParam;
  1145. }
  1146. CTextAttribute textAttr = new CTextAttribute();
  1147. textAttr.FontColor = listBoxParam.FontColor;
  1148. textAttr.FontSize = (float)listBoxParam.FontSize;
  1149. textAttr.FontName = listBoxParam.FontName;
  1150. widget.SetTextAttribute(textAttr);
  1151. if (!string.IsNullOrEmpty(listBoxParam.FieldName))
  1152. {
  1153. widget.SetFieldName(listBoxParam.FieldName);
  1154. }
  1155. else
  1156. {
  1157. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1158. }
  1159. if (listBoxParam.OptionItems != null && listBoxParam.OptionItems.Count > 0)
  1160. {
  1161. int addIndex = 0;
  1162. foreach (string key in listBoxParam.OptionItems.Keys)
  1163. {
  1164. widget.AddOptionItem(addIndex, listBoxParam.OptionItems[key], key);
  1165. addIndex++;
  1166. }
  1167. }
  1168. if (listBoxParam.SelectItemsIndex != null && listBoxParam.SelectItemsIndex.Count > 0)
  1169. {
  1170. widget.SelectItem(listBoxParam.SelectItemsIndex[0]);
  1171. }
  1172. DefaultWidget(widget, listBoxParam);
  1173. }
  1174. private void DefaultSignatureFields(CPDFAnnotation cPDFAnnotation, AnnotParam annotParam)
  1175. {
  1176. CPDFSignatureWidget widget = (cPDFAnnotation as CPDFSignatureWidget);
  1177. if (widget == null)
  1178. {
  1179. return;
  1180. }
  1181. SignatureParam signatureParam;
  1182. if (annotParam == null)
  1183. {
  1184. DefaultSettingParam defaultSettingParam = GetDefaultSettingParam();
  1185. signatureParam = defaultSettingParam.SignatureParamDef;
  1186. }
  1187. else
  1188. {
  1189. signatureParam = annotParam as SignatureParam;
  1190. }
  1191. CTextAttribute textAttr = widget.GetTextAttribute();
  1192. textAttr.FontColor = signatureParam.FontColor;
  1193. textAttr.FontSize = (float)signatureParam.FontSize;
  1194. bool isBold = IsBold(textAttr.FontName);
  1195. bool isItalic = IsItalic(textAttr.FontName);
  1196. textAttr.FontName = signatureParam.FontName;
  1197. widget.SetTextAttribute(textAttr);
  1198. if (!string.IsNullOrEmpty(signatureParam.FieldName))
  1199. {
  1200. widget.SetFieldName(signatureParam.FieldName);
  1201. }
  1202. else
  1203. {
  1204. widget.SetFieldName(string.Format("ComBoBox{0}", widget.Page.GetAnnotCount()));
  1205. }
  1206. DefaultWidget(widget, signatureParam);
  1207. }
  1208. #endregion
  1209. }
  1210. }