cpdf_configuration.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. const ModeConfig({this.initialViewMode = CPreviewMode.viewer});
  70. Map<String, dynamic> toJson() => {'initialViewMode': initialViewMode.name};
  71. }
  72. enum ToolbarAction { back, thumbnail, search, bota, menu }
  73. enum ToolbarMenuAction {
  74. viewSettings,
  75. documentEditor,
  76. security,
  77. watermark,
  78. documentInfo,
  79. save,
  80. share,
  81. openDocument
  82. }
  83. class ToolbarConfig {
  84. final List<ToolbarAction> androidAvailableActions;
  85. final List<ToolbarAction> iosLeftBarAvailableActions;
  86. final List<ToolbarAction> iosRightBarAvailableActions;
  87. final List<ToolbarMenuAction> availableMenus;
  88. const ToolbarConfig(
  89. {this.androidAvailableActions = const [],
  90. this.iosLeftBarAvailableActions = const [],
  91. this.iosRightBarAvailableActions = const [],
  92. this.availableMenus = const []});
  93. Map<String, dynamic> toJson() => {
  94. 'androidAvailableActions':
  95. androidAvailableActions.map((e) => e.name).toList(),
  96. 'iosLeftBarAvailableActions':
  97. iosLeftBarAvailableActions.map((e) => e.name).toList(),
  98. 'iosRightBarAvailableActions':
  99. iosRightBarAvailableActions.map((e) => e.name).toList(),
  100. 'availableMenus': availableMenus.map((e) => e.name).toList()
  101. };
  102. }
  103. /// pdf readerView configuration
  104. class ReaderViewConfig {
  105. // Highlight hyperlink annotations in pdf
  106. final bool linkHighlight;
  107. // Highlight hyperlink form field
  108. final bool formFieldHighlight;
  109. const ReaderViewConfig(
  110. {this.linkHighlight = true, this.formFieldHighlight = true});
  111. Map<String, dynamic> toJson() => {
  112. 'linkHighlight': linkHighlight,
  113. 'formFieldHighlight': formFieldHighlight
  114. };
  115. }