CPDFViewerTool.DataMethod.cs 49 KB

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