CPDFViewerTool.DataMethod.cs 50 KB

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