cpdf_configuration.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'dart:convert';
  2. /// Copyright © 2014-2023 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. /// modeConfig: Configuration of parameters that can be adjusted when opening a PDF interface.
  9. /// For example, setting the default display mode when opening, such as entering viewer or annotations mode.
  10. ///
  11. /// toolbarConfig: Configuration of top toolbar functionality and menu feature lists.
  12. /// This allows you to customize the buttons and menu options on the top toolbar for various operations.
  13. ///
  14. /// readerViewConfig: Configuration related to the PDF view,
  15. /// including functions like highlighting hyperlinks and form field highlighting.
  16. ///
  17. /// ```dart
  18. /// ComPDFKit.openDocument(
  19. /// tempDocumentPath,
  20. /// password: '',
  21. /// configuration: CPDFConfiguration());
  22. ///
  23. /// ```
  24. class CPDFConfiguration {
  25. ModeConfig modeConfig;
  26. ToolbarConfig toolbarConfig;
  27. ReaderViewConfig readerViewConfig;
  28. CPDFConfiguration(
  29. {this.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.viewer),
  30. this.toolbarConfig = const ToolbarConfig(androidAvailableActions: [
  31. ToolbarAction.thumbnail,
  32. ToolbarAction.search,
  33. ToolbarAction.bota,
  34. ToolbarAction.menu,
  35. ], iosLeftBarAvailableActions: [
  36. ToolbarAction.back,
  37. ToolbarAction.thumbnail,
  38. ], iosRightBarAvailableActions: [
  39. ToolbarAction.search,
  40. ToolbarAction.bota,
  41. ToolbarAction.menu,
  42. ], availableMenus: [
  43. ToolbarMenuAction.viewSettings,
  44. ToolbarMenuAction.documentEditor,
  45. ToolbarMenuAction.security,
  46. ToolbarMenuAction.watermark,
  47. ToolbarMenuAction.documentInfo,
  48. ToolbarMenuAction.save,
  49. ToolbarMenuAction.share,
  50. ToolbarMenuAction.openDocument,
  51. ]),
  52. this.readerViewConfig = const ReaderViewConfig(
  53. linkHighlight: true, formFieldHighlight: true)});
  54. String toJson() => jsonEncode({
  55. 'modeConfig': modeConfig.toJson(),
  56. 'toolbarConfig': toolbarConfig.toJson(),
  57. 'readerViewConfig': readerViewConfig.toJson()
  58. });
  59. }
  60. enum CPreviewMode {
  61. viewer,
  62. annotations,
  63. contentEditor,
  64. forms,
  65. digitalSignatures
  66. }
  67. class ModeConfig {
  68. final CPreviewMode initialViewMode;
  69. final List<CPreviewMode> availableViewModes;
  70. const ModeConfig(
  71. {this.initialViewMode = CPreviewMode.viewer,
  72. this.availableViewModes = const [
  73. CPreviewMode.viewer,
  74. CPreviewMode.annotations,
  75. CPreviewMode.contentEditor,
  76. CPreviewMode.forms,
  77. CPreviewMode.digitalSignatures
  78. ]});
  79. Map<String, dynamic> toJson() => {
  80. 'initialViewMode': initialViewMode.name,
  81. 'availableViewModes': availableViewModes.map((e) => e.name).toList()
  82. };
  83. }
  84. enum ToolbarAction { back, thumbnail, search, bota, menu }
  85. enum ToolbarMenuAction {
  86. viewSettings,
  87. documentEditor,
  88. security,
  89. watermark,
  90. documentInfo,
  91. save,
  92. share,
  93. openDocument
  94. }
  95. class ToolbarConfig {
  96. final List<ToolbarAction> androidAvailableActions;
  97. final List<ToolbarAction> iosLeftBarAvailableActions;
  98. final List<ToolbarAction> iosRightBarAvailableActions;
  99. final List<ToolbarMenuAction> availableMenus;
  100. const ToolbarConfig(
  101. {this.androidAvailableActions = const [],
  102. this.iosLeftBarAvailableActions = const [],
  103. this.iosRightBarAvailableActions = const [],
  104. this.availableMenus = const []});
  105. Map<String, dynamic> toJson() => {
  106. 'androidAvailableActions':
  107. androidAvailableActions.map((e) => e.name).toList(),
  108. 'iosLeftBarAvailableActions':
  109. iosLeftBarAvailableActions.map((e) => e.name).toList(),
  110. 'iosRightBarAvailableActions':
  111. iosRightBarAvailableActions.map((e) => e.name).toList(),
  112. 'availableMenus': availableMenus.map((e) => e.name).toList()
  113. };
  114. }
  115. /// pdf readerView configuration
  116. class ReaderViewConfig {
  117. // Highlight hyperlink annotations in pdf
  118. final bool linkHighlight;
  119. // Highlight hyperlink form field
  120. final bool formFieldHighlight;
  121. const ReaderViewConfig(
  122. {this.linkHighlight = true, this.formFieldHighlight = true});
  123. Map<String, dynamic> toJson() => {
  124. 'linkHighlight': linkHighlight,
  125. 'formFieldHighlight': formFieldHighlight
  126. };
  127. }