cpdf_configuration.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. ///
  2. /// Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  3. ///
  4. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. /// This notice may not be removed from this file.
  8. ///
  9. import 'dart:convert';
  10. import 'package:compdfkit_flutter/util/extension/cpdf_color_extension.dart';
  11. import 'package:flutter/material.dart';
  12. import 'cpdf_options.dart';
  13. /// modeConfig: Configuration of parameters that can be adjusted when opening a PDF interface.
  14. /// For example, setting the default display mode when opening, such as entering viewer or annotations mode.
  15. ///
  16. /// toolbarConfig: Configuration of top toolbar functionality and menu feature lists.
  17. /// This allows you to customize the buttons and menu options on the top toolbar for various operations.
  18. ///
  19. /// readerViewConfig: Configuration related to the PDF view,
  20. /// including functions like highlighting hyperlinks and form field highlighting.
  21. ///
  22. /// ```dart
  23. /// ComPDFKit.openDocument(
  24. /// tempDocumentPath,
  25. /// password: '',
  26. /// configuration: CPDFConfiguration());
  27. ///
  28. /// ```
  29. class CPDFConfiguration {
  30. ModeConfig modeConfig;
  31. ToolbarConfig toolbarConfig;
  32. ReaderViewConfig readerViewConfig;
  33. CPDFAnnotationsConfig annotationsConfig;
  34. CPDFContentEditorConfig contentEditorConfig;
  35. CPDFFormsConfig formsConfig;
  36. CPDFGlobalConfig globalConfig;
  37. CPDFConfiguration(
  38. {this.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.viewer),
  39. this.toolbarConfig = const ToolbarConfig(),
  40. this.readerViewConfig = const ReaderViewConfig(),
  41. this.annotationsConfig = const CPDFAnnotationsConfig(),
  42. this.contentEditorConfig = const CPDFContentEditorConfig(),
  43. this.formsConfig = const CPDFFormsConfig(),
  44. this.globalConfig = const CPDFGlobalConfig()});
  45. String toJson() => jsonEncode({
  46. 'modeConfig': modeConfig.toJson(),
  47. 'toolbarConfig': toolbarConfig.toJson(),
  48. 'readerViewConfig': readerViewConfig.toJson(),
  49. 'annotationsConfig': annotationsConfig.toJson(),
  50. 'contentEditorConfig': contentEditorConfig.toJson(),
  51. 'formsConfig': formsConfig.toJson(),
  52. 'global': globalConfig.toJson()
  53. });
  54. }
  55. class ModeConfig {
  56. final CPreviewMode initialViewMode;
  57. final List<CPreviewMode> availableViewModes;
  58. final bool readerOnly;
  59. const ModeConfig(
  60. {this.initialViewMode = CPreviewMode.viewer,
  61. this.readerOnly = false,
  62. this.availableViewModes = CPreviewMode.values});
  63. Map<String, dynamic> toJson() => {
  64. 'initialViewMode': initialViewMode.name,
  65. 'readerOnly': readerOnly,
  66. 'availableViewModes': availableViewModes.map((e) => e.name).toList()
  67. };
  68. }
  69. class ToolbarConfig {
  70. final List<ToolbarAction> androidAvailableActions;
  71. final List<ToolbarAction> iosLeftBarAvailableActions;
  72. final List<ToolbarAction> iosRightBarAvailableActions;
  73. final List<ToolbarMenuAction> availableMenus;
  74. const ToolbarConfig(
  75. {this.androidAvailableActions = const [
  76. ToolbarAction.thumbnail,
  77. ToolbarAction.search,
  78. ToolbarAction.bota,
  79. ToolbarAction.menu,
  80. ],
  81. this.iosLeftBarAvailableActions = const [
  82. ToolbarAction.back,
  83. ToolbarAction.thumbnail,
  84. ],
  85. this.iosRightBarAvailableActions = const [
  86. ToolbarAction.search,
  87. ToolbarAction.bota,
  88. ToolbarAction.menu
  89. ],
  90. this.availableMenus = const [
  91. ToolbarMenuAction.viewSettings,
  92. ToolbarMenuAction.documentEditor,
  93. ToolbarMenuAction.security,
  94. ToolbarMenuAction.watermark,
  95. ToolbarMenuAction.flattened,
  96. ToolbarMenuAction.documentInfo,
  97. ToolbarMenuAction.save,
  98. ToolbarMenuAction.share,
  99. ToolbarMenuAction.openDocument,
  100. ]});
  101. Map<String, dynamic> toJson() => {
  102. 'androidAvailableActions':
  103. androidAvailableActions.map((e) => e.name).toList(),
  104. 'iosLeftBarAvailableActions':
  105. iosLeftBarAvailableActions.map((e) => e.name).toList(),
  106. 'iosRightBarAvailableActions':
  107. iosRightBarAvailableActions.map((e) => e.name).toList(),
  108. 'availableMenus': availableMenus.map((e) => e.name).toList()
  109. };
  110. }
  111. /// pdf readerView configuration
  112. class ReaderViewConfig {
  113. // Highlight hyperlink annotations in pdf
  114. final bool linkHighlight;
  115. // Highlight hyperlink form field
  116. final bool formFieldHighlight;
  117. final CPDFDisplayMode displayMode;
  118. final bool continueMode;
  119. final bool verticalMode;
  120. final bool cropMode;
  121. final CPDFThemes themes;
  122. final bool enableSliderBar;
  123. final bool enablePageIndicator;
  124. final int pageSpacing;
  125. final double pageScale;
  126. /// only android platform
  127. final bool pageSameWidth;
  128. const ReaderViewConfig(
  129. {this.linkHighlight = true,
  130. this.formFieldHighlight = true,
  131. this.displayMode = CPDFDisplayMode.singlePage,
  132. this.continueMode = true,
  133. this.verticalMode = true,
  134. this.cropMode = false,
  135. this.themes = CPDFThemes.light,
  136. this.enableSliderBar = true,
  137. this.enablePageIndicator = true,
  138. this.pageSpacing = 10,
  139. this.pageScale = 1.0,
  140. this.pageSameWidth = true});
  141. Map<String, dynamic> toJson() => {
  142. 'linkHighlight': linkHighlight,
  143. 'formFieldHighlight': formFieldHighlight,
  144. 'displayMode': displayMode.name,
  145. 'continueMode': continueMode,
  146. 'verticalMode': verticalMode,
  147. 'cropMode': cropMode,
  148. 'themes': themes.name,
  149. 'enableSliderBar': enableSliderBar,
  150. 'enablePageIndicator': enablePageIndicator,
  151. 'pageSpacing': pageSpacing,
  152. 'pageScale': pageScale,
  153. 'pageSameWidth': pageSameWidth
  154. };
  155. }
  156. class CPDFAnnotationsConfig {
  157. final List<CPDFAnnotationType> availableTypes;
  158. final List<CPDFConfigTool> availableTools;
  159. final CPDFAnnotationAttribute initAttribute;
  160. const CPDFAnnotationsConfig(
  161. {this.availableTypes = CPDFAnnotationType.values,
  162. this.availableTools = CPDFConfigTool.values,
  163. this.initAttribute = const CPDFAnnotationAttribute()});
  164. Map<String, dynamic> toJson() => {
  165. 'availableTypes': availableTypes.map((e) => e.name).toList(),
  166. 'availableTools': availableTools.map((e) => e.name).toList(),
  167. 'initAttribute': initAttribute.toJson()
  168. };
  169. }
  170. class CPDFAnnotationAttribute {
  171. final CPDFAnnotAttr note;
  172. final CPDFAnnotAttr highlight;
  173. final CPDFAnnotAttr underline;
  174. final CPDFAnnotAttr squiggly;
  175. final CPDFAnnotAttr strikeout;
  176. final CPDFAnnotAttr ink;
  177. final CPDFAnnotAttr square;
  178. final CPDFAnnotAttr circle;
  179. final CPDFAnnotAttr line;
  180. final CPDFAnnotAttr arrow;
  181. final CPDFAnnotAttr freeText;
  182. const CPDFAnnotationAttribute({
  183. this.note = const CPDFAnnotAttr.note(),
  184. this.highlight = const CPDFAnnotAttr.highlight(),
  185. this.underline = const CPDFAnnotAttr.underline(),
  186. this.squiggly = const CPDFAnnotAttr.squiggly(),
  187. this.strikeout = const CPDFAnnotAttr.strikeout(),
  188. this.ink = const CPDFAnnotAttr.ink(),
  189. this.square = const CPDFAnnotAttr.square(),
  190. this.circle = const CPDFAnnotAttr.circle(),
  191. this.line = const CPDFAnnotAttr.line(),
  192. this.arrow = const CPDFAnnotAttr.arrow(),
  193. this.freeText = const CPDFAnnotAttr.freeText(),
  194. });
  195. Map<String, dynamic> toJson() => {
  196. 'note': note.toJson(),
  197. 'highlight': highlight.toJson(),
  198. 'underline': underline.toJson(),
  199. 'squiggly': squiggly.toJson(),
  200. 'strikeout': strikeout.toJson(),
  201. 'ink': ink.toJson(),
  202. 'square': square.toJson(),
  203. 'circle': circle.toJson(),
  204. 'line': line.toJson(),
  205. 'arrow': arrow.toJson(),
  206. 'freeText': freeText.toJson()
  207. };
  208. }
  209. class CPDFAnnotAttr {
  210. final CPDFAnnotationType? annotationType;
  211. final Color? color;
  212. final int? alpha;
  213. final int? borderWidth;
  214. final Color? fillColor;
  215. final Color? borderColor;
  216. final int? borderAlpha;
  217. final int? colorAlpha;
  218. final CPDFBorderStyle? borderStyle;
  219. final CPDFLineType? startLineType;
  220. final CPDFLineType? tailLineType;
  221. final Color? fontColor;
  222. final int? fontColorAlpha;
  223. final int? fontSize;
  224. final bool? isBold;
  225. final bool? isItalic;
  226. final CPDFAlignment? alignment;
  227. final CPDFTypeface? typeface;
  228. const CPDFAnnotAttr(
  229. {required this.annotationType,
  230. this.color,
  231. this.alpha,
  232. this.borderWidth,
  233. this.fillColor,
  234. this.borderColor,
  235. this.borderAlpha,
  236. this.colorAlpha,
  237. this.borderStyle,
  238. this.startLineType,
  239. this.tailLineType,
  240. this.fontColor,
  241. this.fontColorAlpha,
  242. this.fontSize,
  243. this.isBold,
  244. this.isItalic,
  245. this.alignment,
  246. this.typeface});
  247. const CPDFAnnotAttr.note(
  248. {Color color = const Color(0xFF1460F3), int alpha = 255})
  249. : this(
  250. annotationType: CPDFAnnotationType.note,
  251. color: color,
  252. alpha: alpha);
  253. const CPDFAnnotAttr.highlight(
  254. {Color color = const Color(0xFF1460F3), int alpha = 77})
  255. : this(
  256. annotationType: CPDFAnnotationType.highlight,
  257. color: color,
  258. alpha: alpha);
  259. const CPDFAnnotAttr.underline(
  260. {Color color = const Color(0xFF1460F3), int alpha = 77})
  261. : this(
  262. annotationType: CPDFAnnotationType.underline,
  263. color: color,
  264. alpha: alpha);
  265. const CPDFAnnotAttr.squiggly(
  266. {Color color = const Color(0xFF1460F3), int alpha = 77})
  267. : this(
  268. annotationType: CPDFAnnotationType.squiggly,
  269. color: color,
  270. alpha: alpha);
  271. const CPDFAnnotAttr.strikeout(
  272. {Color color = const Color(0xFF1460F3), int alpha = 77})
  273. : this(
  274. annotationType: CPDFAnnotationType.highlight,
  275. color: color,
  276. alpha: alpha);
  277. const CPDFAnnotAttr.ink(
  278. {Color color = const Color(0xFF1460F3),
  279. int alpha = 100,
  280. int borderWidth = 10})
  281. : this(
  282. annotationType: CPDFAnnotationType.ink,
  283. color: color,
  284. alpha: alpha,
  285. borderWidth: borderWidth);
  286. const CPDFAnnotAttr.square({
  287. Color fillColor = const Color(0xFF1460F3),
  288. Color borderColor = Colors.black,
  289. int colorAlpha = 128,
  290. int borderWidth = 2,
  291. CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
  292. }) : this(
  293. annotationType: CPDFAnnotationType.square,
  294. fillColor: fillColor,
  295. borderColor: borderColor,
  296. colorAlpha: colorAlpha,
  297. borderWidth: borderWidth,
  298. borderStyle: borderStyle);
  299. const CPDFAnnotAttr.circle({
  300. Color fillColor = const Color(0xFF1460F3),
  301. Color borderColor = Colors.black,
  302. int colorAlpha = 128,
  303. int borderWidth = 2,
  304. CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
  305. }) : this(
  306. annotationType: CPDFAnnotationType.circle,
  307. fillColor: fillColor,
  308. borderColor: borderColor,
  309. colorAlpha: colorAlpha,
  310. borderWidth: borderWidth,
  311. borderStyle: borderStyle);
  312. const CPDFAnnotAttr.line({
  313. Color borderColor = const Color(0xFF1460F3),
  314. int borderAlpha = 100,
  315. int borderWidth = 5,
  316. CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
  317. }) : this(
  318. annotationType: CPDFAnnotationType.line,
  319. borderColor: borderColor,
  320. borderAlpha: borderAlpha,
  321. borderWidth: borderWidth,
  322. borderStyle: borderStyle,
  323. startLineType: CPDFLineType.none,
  324. tailLineType: CPDFLineType.none);
  325. const CPDFAnnotAttr.arrow(
  326. {Color borderColor = const Color(0xFF1460F3),
  327. int borderAlpha = 100,
  328. int borderWidth = 5,
  329. CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
  330. CPDFLineType startLineType = CPDFLineType.none,
  331. CPDFLineType tailLineType = CPDFLineType.openArrow})
  332. : this(
  333. annotationType: CPDFAnnotationType.arrow,
  334. borderColor: borderColor,
  335. borderAlpha: borderAlpha,
  336. borderWidth: borderWidth,
  337. borderStyle: borderStyle,
  338. startLineType: startLineType,
  339. tailLineType: tailLineType);
  340. const CPDFAnnotAttr.freeText(
  341. {Color fontColor = Colors.black,
  342. int fontColorAlpha = 255,
  343. int fontSize = 30,
  344. bool isBold = false,
  345. bool isItalic = false,
  346. CPDFAlignment alignment = CPDFAlignment.left,
  347. CPDFTypeface typeface = CPDFTypeface.helvetica})
  348. : this(
  349. annotationType: CPDFAnnotationType.freetext,
  350. fontColor: fontColor,
  351. fontColorAlpha: fontColorAlpha,
  352. fontSize: fontSize,
  353. isBold: isBold,
  354. isItalic: isItalic,
  355. alignment: alignment,
  356. typeface: typeface);
  357. Map<String, dynamic> toJson() {
  358. switch (annotationType) {
  359. case CPDFAnnotationType.note:
  360. case CPDFAnnotationType.highlight:
  361. case CPDFAnnotationType.underline:
  362. case CPDFAnnotationType.squiggly:
  363. case CPDFAnnotationType.strikeout:
  364. return {'color': color?.toHex(), 'alpha': alpha};
  365. case CPDFAnnotationType.ink:
  366. return {
  367. 'color': color?.toHex(),
  368. 'alpha': alpha,
  369. 'borderWidth': borderWidth
  370. };
  371. case CPDFAnnotationType.square:
  372. case CPDFAnnotationType.circle:
  373. return {
  374. 'fillColor': fillColor?.toHex(),
  375. 'borderColor': borderColor?.toHex(),
  376. 'colorAlpha': colorAlpha,
  377. 'borderWidth': borderWidth,
  378. 'borderStyle': borderStyle?.toJson(),
  379. };
  380. case CPDFAnnotationType.line:
  381. case CPDFAnnotationType.arrow:
  382. return {
  383. 'borderColor': borderColor?.toHex(),
  384. 'borderAlpha': borderAlpha,
  385. 'borderWidth': borderWidth,
  386. 'borderStyle': borderStyle?.toJson(),
  387. 'startLineType': startLineType?.name,
  388. 'tailLineType': tailLineType?.name
  389. };
  390. case CPDFAnnotationType.freetext:
  391. return {
  392. 'fontColor': fontColor?.toHex(),
  393. 'fontColorAlpha': fontColorAlpha,
  394. 'fontSize': fontSize,
  395. 'isBold': isBold,
  396. 'isItalic': isItalic,
  397. 'alignment': alignment?.name,
  398. 'typeface': typeface?.getFontName(),
  399. };
  400. default:
  401. return {};
  402. }
  403. }
  404. }
  405. class CPDFBorderStyle {
  406. final CPDFAnnotBorderStyle style;
  407. final double dashGap;
  408. const CPDFBorderStyle(
  409. {this.style = CPDFAnnotBorderStyle.solid, this.dashGap = 8.0});
  410. const CPDFBorderStyle.solid()
  411. : style = CPDFAnnotBorderStyle.solid,
  412. dashGap = 0;
  413. const CPDFBorderStyle.dashed({this.dashGap = 9.0})
  414. : style = CPDFAnnotBorderStyle.dashed;
  415. Map<String, dynamic> toJson() => {'style': style.name, 'dashGap': dashGap};
  416. }
  417. class CPDFContentEditorConfig {
  418. final List<CPDFContentEditorType> availableTypes;
  419. final List<CPDFConfigTool> availableTools;
  420. final CPDFContentEditorAttribute initAttribute;
  421. const CPDFContentEditorConfig(
  422. {this.availableTypes = CPDFContentEditorType.values,
  423. this.availableTools = CPDFConfigTool.values,
  424. this.initAttribute = const CPDFContentEditorAttribute()});
  425. Map<String, dynamic> toJson() => {
  426. 'availableTypes': availableTypes.map((e) => e.name).toList(),
  427. 'availableTools': availableTools.map((e) => e.name).toList(),
  428. 'initAttribute': initAttribute.toJson()
  429. };
  430. }
  431. class CPDFContentEditorAttribute {
  432. final CPDFContentEditorAttr text;
  433. const CPDFContentEditorAttribute({this.text = const CPDFContentEditorAttr()});
  434. Map<String, dynamic> toJson() => {'text': text.toJson()};
  435. }
  436. class CPDFContentEditorAttr {
  437. final Color fontColor;
  438. final int fontColorAlpha;
  439. final int fontSize;
  440. final bool isBold;
  441. final bool isItalic;
  442. final CPDFTypeface typeface;
  443. final CPDFAlignment alignment;
  444. const CPDFContentEditorAttr(
  445. {this.fontColor = Colors.black,
  446. this.fontColorAlpha = 255,
  447. this.fontSize = 30,
  448. this.isBold = false,
  449. this.isItalic = false,
  450. this.typeface = CPDFTypeface.helvetica,
  451. this.alignment = CPDFAlignment.left});
  452. Map<String, dynamic> toJson() => {
  453. 'fontColor': fontColor.toHex(),
  454. 'fontColorAlpha': fontColorAlpha,
  455. 'fontSize': fontSize,
  456. 'isBold': isBold,
  457. 'isItalic': isItalic,
  458. 'typeface': typeface.getFontName(),
  459. 'alignment': alignment.name
  460. };
  461. }
  462. class CPDFFormsConfig {
  463. final List<CPDFFormType> availableTypes;
  464. final List<CPDFFormConfigTool> availableTools;
  465. final CPDFFormAttribute initAttribute;
  466. const CPDFFormsConfig(
  467. {this.availableTypes = CPDFFormType.values,
  468. this.availableTools = CPDFFormConfigTool.values,
  469. this.initAttribute = const CPDFFormAttribute()});
  470. Map<String, dynamic> toJson() => {
  471. 'availableTypes': availableTypes.map((e) => e.name).toList(),
  472. 'availableTools': availableTools.map((e) => e.name).toList(),
  473. 'initAttribute': initAttribute.toJson()
  474. };
  475. }
  476. class CPDFFormAttribute {
  477. final CPDFFormAttr textField;
  478. final CPDFFormAttr checkBox;
  479. final CPDFFormAttr radioButton;
  480. final CPDFFormAttr listBox;
  481. final CPDFFormAttr comboBox;
  482. final CPDFFormAttr pushButton;
  483. final CPDFFormAttr signaturesFields;
  484. const CPDFFormAttribute({
  485. this.textField = const CPDFFormAttr.textField(),
  486. this.checkBox = const CPDFFormAttr.checkBox(),
  487. this.radioButton = const CPDFFormAttr.radioButton(),
  488. this.listBox = const CPDFFormAttr.listBox(),
  489. this.comboBox = const CPDFFormAttr.comboBox(),
  490. this.pushButton = const CPDFFormAttr.pushButton(),
  491. this.signaturesFields = const CPDFFormAttr.signaturesFields(),
  492. });
  493. Map<String, dynamic> toJson() => {
  494. 'textField': textField.toJson(),
  495. 'checkBox': checkBox.toJson(),
  496. 'radioButton': radioButton.toJson(),
  497. 'listBox': listBox.toJson(),
  498. 'comboBox': comboBox.toJson(),
  499. 'pushButton': pushButton.toJson(),
  500. 'signaturesFields': signaturesFields.toJson()
  501. };
  502. }
  503. class CPDFFormAttr {
  504. final CPDFFormType formType;
  505. final Color fillColor;
  506. final Color borderColor;
  507. final int borderWidth;
  508. final Color fontColor;
  509. final int fontSize;
  510. final bool isBold;
  511. final bool isItalic;
  512. final CPDFAlignment alignment;
  513. final bool multiline;
  514. final CPDFTypeface typeface;
  515. final Color checkedColor;
  516. final bool isChecked;
  517. final CPDFCheckStyle checkedStyle;
  518. final String title;
  519. const CPDFFormAttr(
  520. {required this.formType,
  521. this.fillColor = const Color(0xFFDDE9FF),
  522. this.borderColor = const Color(0xFF1460F3),
  523. this.borderWidth = 2,
  524. this.fontColor = Colors.black,
  525. this.fontSize = 20,
  526. this.isBold = false,
  527. this.isItalic = false,
  528. this.alignment = CPDFAlignment.left,
  529. this.multiline = true,
  530. this.typeface = CPDFTypeface.helvetica,
  531. this.checkedColor = const Color(0xFF43474D),
  532. this.isChecked = false,
  533. this.checkedStyle = CPDFCheckStyle.check,
  534. this.title = 'Button'});
  535. const CPDFFormAttr.textField(
  536. {Color fillColor = const Color(0xFFDDE9FF),
  537. Color borderColor = const Color(0xFF1460F3),
  538. int borderWidth = 2,
  539. Color fontColor = Colors.black,
  540. int fontSize = 20,
  541. bool isBold = false,
  542. bool isItalic = false,
  543. CPDFAlignment alignment = CPDFAlignment.left,
  544. bool multiline = true,
  545. CPDFTypeface typeface = CPDFTypeface.helvetica})
  546. : this(
  547. formType: CPDFFormType.textField,
  548. fillColor: fillColor,
  549. borderColor: borderColor,
  550. borderWidth: borderWidth,
  551. fontColor: fontColor,
  552. fontSize: fontSize,
  553. isBold: isBold,
  554. isItalic: isItalic,
  555. alignment: alignment,
  556. multiline: multiline,
  557. typeface: typeface);
  558. const CPDFFormAttr.checkBox(
  559. {Color fillColor = const Color(0xFFDDE9FF),
  560. Color borderColor = const Color(0xFF1460F3),
  561. int borderWidth = 2,
  562. Color checkedColor = const Color(0xFF43474D),
  563. bool isChecked = false,
  564. CPDFCheckStyle checkStyle = CPDFCheckStyle.check})
  565. : this(
  566. formType: CPDFFormType.checkBox,
  567. fillColor: fillColor,
  568. borderColor: borderColor,
  569. borderWidth: borderWidth,
  570. checkedColor: checkedColor,
  571. isChecked: isChecked,
  572. checkedStyle: checkStyle);
  573. const CPDFFormAttr.radioButton(
  574. {Color fillColor = const Color(0xFFDDE9FF),
  575. Color borderColor = const Color(0xFF1460F3),
  576. int borderWidth = 2,
  577. Color checkedColor = const Color(0xFF43474D),
  578. bool isChecked = false,
  579. CPDFCheckStyle checkStyle = CPDFCheckStyle.circle})
  580. : this(
  581. formType: CPDFFormType.radioButton,
  582. fillColor: fillColor,
  583. borderColor: borderColor,
  584. borderWidth: borderWidth,
  585. checkedColor: checkedColor,
  586. isChecked: isChecked,
  587. checkedStyle: checkStyle);
  588. const CPDFFormAttr.listBox({
  589. Color fillColor = const Color(0xFFDDE9FF),
  590. Color borderColor = const Color(0xFF1460F3),
  591. int borderWidth = 2,
  592. Color fontColor = Colors.black,
  593. int fontSize = 20,
  594. CPDFTypeface typeface = CPDFTypeface.helvetica,
  595. bool isBold = false,
  596. bool isItalic = false,
  597. }) : this(
  598. formType: CPDFFormType.listBox,
  599. fillColor: fillColor,
  600. borderColor: borderColor,
  601. borderWidth: borderWidth,
  602. fontColor: fontColor,
  603. fontSize: fontSize,
  604. typeface: typeface,
  605. isBold: isBold,
  606. isItalic: isItalic);
  607. const CPDFFormAttr.comboBox({
  608. Color fillColor = const Color(0xFFDDE9FF),
  609. Color borderColor = const Color(0xFF1460F3),
  610. int borderWidth = 2,
  611. Color fontColor = Colors.black,
  612. int fontSize = 20,
  613. CPDFTypeface typeface = CPDFTypeface.helvetica,
  614. bool isBold = false,
  615. bool isItalic = false,
  616. }) : this(
  617. formType: CPDFFormType.comboBox,
  618. fillColor: fillColor,
  619. borderColor: borderColor,
  620. borderWidth: borderWidth,
  621. fontColor: fontColor,
  622. fontSize: fontSize,
  623. typeface: typeface,
  624. isBold: isBold,
  625. isItalic: isItalic);
  626. const CPDFFormAttr.pushButton({
  627. String title = 'Button',
  628. Color fillColor = const Color(0xFFDDE9FF),
  629. Color borderColor = const Color(0xFF1460F3),
  630. int borderWidth = 2,
  631. Color fontColor = Colors.black,
  632. int fontSize = 20,
  633. CPDFTypeface typeface = CPDFTypeface.helvetica,
  634. bool isBold = false,
  635. bool isItalic = false,
  636. }) : this(
  637. formType: CPDFFormType.pushButton,
  638. title: title,
  639. fillColor: fillColor,
  640. borderColor: borderColor,
  641. borderWidth: borderWidth,
  642. fontColor: fontColor,
  643. fontSize: fontSize,
  644. typeface: typeface,
  645. isBold: isBold,
  646. isItalic: isItalic);
  647. const CPDFFormAttr.signaturesFields(
  648. {Color fillColor = const Color(0xFFDDE9FF),
  649. Color borderColor = const Color(0xFF1460F3),
  650. int borderWidth = 2})
  651. : this(
  652. formType: CPDFFormType.signaturesFields,
  653. fillColor: fillColor,
  654. borderColor: borderColor,
  655. borderWidth: borderWidth);
  656. Map<String, dynamic> toJson() {
  657. switch (formType) {
  658. case CPDFFormType.textField:
  659. return {
  660. 'fillColor': fillColor.toHex(),
  661. 'borderColor': borderColor.toHex(),
  662. 'borderWidth': borderWidth,
  663. 'fontColor': fontColor.toHex(),
  664. 'fontSize': fontSize,
  665. 'isBold': isBold,
  666. 'isItalic': isItalic,
  667. 'alignment': alignment.name,
  668. 'multiline': multiline,
  669. 'typeface': typeface.getFontName()
  670. };
  671. case CPDFFormType.checkBox:
  672. case CPDFFormType.radioButton:
  673. return {
  674. 'fillColor': fillColor.toHex(),
  675. 'borderColor': borderColor.toHex(),
  676. 'borderWidth': borderWidth,
  677. 'checkedColor': checkedColor.toHex(),
  678. 'isChecked': false,
  679. 'checkedStyle': checkedStyle.name
  680. };
  681. case CPDFFormType.listBox:
  682. case CPDFFormType.comboBox:
  683. return {
  684. 'fillColor': fillColor.toHex(),
  685. 'borderColor': borderColor.toHex(),
  686. 'borderWidth': borderWidth,
  687. 'fontColor': fontColor.toHex(),
  688. 'fontSize': fontSize,
  689. 'typeface': typeface.getFontName(),
  690. 'isBold': isBold,
  691. 'isItalic': isItalic,
  692. };
  693. case CPDFFormType.pushButton:
  694. return {
  695. 'fillColor': fillColor.toHex(),
  696. 'borderColor': borderColor.toHex(),
  697. 'borderWidth': borderWidth,
  698. 'fontColor': fontColor.toHex(),
  699. 'fontSize': fontSize,
  700. 'typeface': typeface.getFontName(),
  701. 'isBold': isBold,
  702. 'isItalic': isItalic,
  703. 'title': title
  704. };
  705. case CPDFFormType.signaturesFields:
  706. return {
  707. 'fillColor': fillColor.toHex(),
  708. 'borderColor': borderColor.toHex(),
  709. 'borderWidth': borderWidth,
  710. };
  711. default:
  712. return {};
  713. }
  714. }
  715. }
  716. class CPDFGlobalConfig {
  717. /// Only supports Android platform in version 2.0.2
  718. // Set the view theme mode except the PDF area, the default value is [CPDFThemeMode.system]
  719. final CPDFThemeMode themeMode;
  720. const CPDFGlobalConfig({this.themeMode = CPDFThemeMode.system});
  721. Map<String, dynamic> toJson() => {"themeMode": themeMode.name};
  722. }