convert_options_provider.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /// convert_options_provider.dart
  2. ///
  3. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  4. ///
  5. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  6. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  7. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  8. /// This notice may not be removed from this file.
  9. import 'package:flutter/material.dart';
  10. import 'package:kmpdfkit_conversion_flutter/models/convert_type.dart';
  11. import 'package:kmpdfkit_conversion_flutter/models/options/convert_csv_options.dart';
  12. import 'package:kmpdfkit_conversion_flutter/models/options/convert_excel_options.dart';
  13. import 'package:kmpdfkit_conversion_flutter/models/options/convert_html_options.dart';
  14. import 'package:kmpdfkit_conversion_flutter/models/options/convert_image_options.dart';
  15. import 'package:kmpdfkit_conversion_flutter/models/options/convert_ppt_options.dart';
  16. import 'package:kmpdfkit_conversion_flutter/models/options/convert_rtf_options.dart';
  17. import 'package:kmpdfkit_conversion_flutter/models/options/convert_txt_options.dart';
  18. import 'package:kmpdfkit_conversion_flutter/models/options/convert_word_options.dart';
  19. import 'package:kmpdfkit_conversion_flutter/models/options/options.dart';
  20. ///record convert format options
  21. class ConvertOptionsProvider extends ChangeNotifier {
  22. ConvertType convertType = ConvertType.none;
  23. ConvertPPTOptions pptOptions =
  24. ConvertPPTOptions(containImages: true, containAnnotations: true);
  25. ConvertWordOptions wordOptions =
  26. ConvertWordOptions(containImages: true, containAnnotations: true);
  27. ConvertExcelOptions excelOptions = ConvertExcelOptions(
  28. containImages: true,
  29. containAnnotations: false,
  30. workSheetOptions: ExcelWorkSheetOptions.forEachPage,
  31. contentOptions: ExcelContentOptions.allContent);
  32. ConvertImageOptions imageOptions = ConvertImageOptions(
  33. containAnnotations: true,
  34. imageDpi: 300,
  35. imagePageOptions: ImagePageOptions.png);
  36. ConvertCSVOptions csvOptions = ConvertCSVOptions(mergeCSV: false);
  37. ConvertRTFOptions rtfOptions =
  38. ConvertRTFOptions(containImages: true, containAnnotations: true);
  39. ConvertHTMLOptions htmlOptions = ConvertHTMLOptions(
  40. containImages: true,
  41. containAnnotations: false,
  42. htmlPageOptions: HtmlPageOptions.singlePage);
  43. Options getOptions() {
  44. switch (convertType) {
  45. case ConvertType.ppt:
  46. return pptOptions;
  47. case ConvertType.word:
  48. return wordOptions;
  49. case ConvertType.excel:
  50. return excelOptions;
  51. case ConvertType.image:
  52. return imageOptions;
  53. case ConvertType.csv:
  54. return csvOptions;
  55. case ConvertType.rtf:
  56. return rtfOptions;
  57. case ConvertType.html:
  58. return htmlOptions;
  59. default:
  60. return ConvertTXTOptions();
  61. }
  62. }
  63. void changeConvertType(ConvertType convertType) {
  64. this.convertType = convertType;
  65. notifyListeners();
  66. }
  67. void changePPTOptions({bool? containImages, bool? containAnnotations}) {
  68. if (containImages != null) {
  69. pptOptions.containImages = containImages;
  70. }
  71. if (containAnnotations != null) {
  72. pptOptions.containAnnotations = containAnnotations;
  73. }
  74. notifyListeners();
  75. }
  76. void changeWordOptions({bool? containImages, bool? containAnnotations}) {
  77. if (containImages != null) {
  78. wordOptions.containImages = containImages;
  79. }
  80. if (containAnnotations != null) {
  81. wordOptions.containAnnotations = containAnnotations;
  82. }
  83. notifyListeners();
  84. }
  85. void changeExcelOptions(
  86. {bool? containImages,
  87. bool? containAnnotations,
  88. ExcelWorkSheetOptions? workSheetOptions,
  89. ExcelContentOptions? contentOptions}) {
  90. if (containImages != null) {
  91. excelOptions.containImages = containImages;
  92. }
  93. if (containAnnotations != null) {
  94. excelOptions.containAnnotations = containAnnotations;
  95. }
  96. if (workSheetOptions != null) {
  97. excelOptions.workSheetOptions = workSheetOptions;
  98. }
  99. if (contentOptions != null) {
  100. excelOptions.contentOptions = contentOptions;
  101. }
  102. notifyListeners();
  103. }
  104. void changeImageOptions(
  105. {bool? containAnnotations,
  106. int? imageDpi,
  107. ImagePageOptions? imagePageOptions}) {
  108. if (containAnnotations != null) {
  109. imageOptions.containAnnotations = containAnnotations;
  110. }
  111. if (imageDpi != null) {
  112. imageOptions.imageDpi = imageDpi;
  113. }
  114. if (imagePageOptions != null) {
  115. imageOptions.imagePageOptions = imagePageOptions;
  116. }
  117. notifyListeners();
  118. }
  119. void changeCSVOptions(bool mergeCSV) {
  120. csvOptions.mergeCSV = mergeCSV;
  121. notifyListeners();
  122. }
  123. void changeRTFOptions({bool? containImages, bool? containAnnotations}) {
  124. if (containImages != null) {
  125. rtfOptions.containImages = containImages;
  126. }
  127. if (containAnnotations != null) {
  128. rtfOptions.containAnnotations = containAnnotations;
  129. }
  130. notifyListeners();
  131. }
  132. void changeHtmlOptions(
  133. {bool? containImages,
  134. bool? containAnnotations,
  135. HtmlPageOptions? htmlPageOptions}) {
  136. if (containImages != null) {
  137. htmlOptions.containImages = containImages;
  138. }
  139. if (containAnnotations != null) {
  140. htmlOptions.containAnnotations = containAnnotations;
  141. }
  142. if (htmlPageOptions != null) {
  143. htmlOptions.htmlPageOptions = htmlPageOptions;
  144. }
  145. notifyListeners();
  146. }
  147. }