ConverterDialogsModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System;
  2. using System.Collections.Generic;
  3. using ComPDFKit_Conversion.Converter;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using ComDocumentAIKit;
  8. using ComPDFKit_Conversion.Options;
  9. using Microsoft.Office.Interop.Word;
  10. using PDF_Office.Helper;
  11. namespace PDF_Office.Model.Dialog.ConverterDialogs
  12. {
  13. public class ConvertOptions
  14. {
  15. public COCRLanguage OCRLanguage = COCRLanguage.English;
  16. public bool IsAllowOCR = false;
  17. public bool IsContainOCRBgImage =false;
  18. public bool IsContainAnnotations = true;
  19. public bool IsContainImages = true;
  20. public ContentOptions ContentOpts = ContentOptions.AllContent;
  21. public WorksheetOptions WorksheetOpts = WorksheetOptions.ForEachPage;
  22. public PageAndNavigationPaneOptions PageAndNavigationPaneOpts = PageAndNavigationPaneOptions.SinglePageNavigationByBookmarks;
  23. public ImgType ImageType = ImgType.PNG;
  24. public uint ImageDpi = 150;
  25. public bool IsMergeCsv = false;
  26. }
  27. public class ConverterDialogsModel
  28. {
  29. /// <summary>
  30. /// 文档地址;
  31. /// </summary>
  32. public string InputPath="";
  33. /// <summary>
  34. /// 输出地址;
  35. /// </summary>
  36. public string OutputPath="";
  37. /// <summary>
  38. /// 进度;
  39. /// </summary>
  40. public OnProgress GetProgress=null;
  41. /// <summary>
  42. /// 页码 页码范围;
  43. /// </summary>
  44. public List<int> PageIndexLists= new List<int> { };
  45. /// <summary>
  46. /// 页面信息
  47. /// </summary>
  48. public string PageRange = "";
  49. /// <summary>
  50. /// 文档密码;
  51. /// </summary>
  52. public string Pawssword="";
  53. /// <summary>
  54. /// 文档密码;
  55. /// </summary>
  56. public bool IsCustomFileName=true;
  57. /// <summary>
  58. /// OCR,与部分功能;
  59. /// </summary>
  60. public ConvertOptions Options=new ConvertOptions();
  61. private void ConverterClear()
  62. {
  63. ConverterHelper.Clear();
  64. App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
  65. }
  66. private void SetProgress(int pageIndex)
  67. {
  68. App.mainWindowViewModel.Value = pageIndex;
  69. if (App.mainWindowViewModel.Value == App.mainWindowViewModel.MaxValue) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  70. }
  71. public async void OnOpened(Prism.Services.Dialogs.DialogResult e)
  72. {
  73. if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel|| e.Result== Prism.Services.Dialogs.ButtonResult.None) { return; }
  74. bool result = false;
  75. string convertType = "";
  76. OnProgress GetProgress = null;
  77. GetProgress += SetProgress;
  78. App.mainWindowViewModel.ProcessCloseAction = ConverterClear;
  79. convertType = e.Parameters.GetValue<string>(ParameterNames.ConverterType).ToString();
  80. App.mainWindowViewModel.ProgressTitle = "Converting";
  81. App.mainWindowViewModel.Value = 0;
  82. App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
  83. switch (convertType)
  84. {
  85. case "CSV":
  86. ConverterCSVDialogModel ConverterCSVModel = e.Parameters.GetValue<ConverterCSVDialogModel>(ParameterNames.ConverterTypeModel);
  87. if (ConverterCSVModel != null)
  88. {
  89. App.mainWindowViewModel.MaxValue = ConverterCSVModel.PageIndexLists.Count();
  90. for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++)
  91. {
  92. ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1;
  93. }
  94. result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword, ConverterCSVModel.csvOptions, ConverterCSVModel.IsCustomFileName);
  95. }
  96. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  97. break;
  98. case "Excel":
  99. ConverterExcelDialogModel ConverterExcelModel = e.Parameters.GetValue<ConverterExcelDialogModel>(ParameterNames.ConverterTypeModel);
  100. if (ConverterExcelModel != null)
  101. {
  102. App.mainWindowViewModel.MaxValue = ConverterExcelModel.PageIndexLists.Count();
  103. for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++)
  104. {
  105. ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1;
  106. }
  107. result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOptions);
  108. }
  109. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  110. break;
  111. case "HTML":
  112. ConverterHTMLDialogModel ConverterHTMLModel = e.Parameters.GetValue<ConverterHTMLDialogModel>(ParameterNames.ConverterTypeModel);
  113. if (ConverterHTMLModel != null)
  114. {
  115. App.mainWindowViewModel.MaxValue = ConverterHTMLModel.PageIndexLists.Count();
  116. for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++)
  117. {
  118. ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1;
  119. }
  120. result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOptions);
  121. }
  122. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  123. break;
  124. case "Img":
  125. ConverterImgDialogModel ConverterImgModel = e.Parameters.GetValue<ConverterImgDialogModel>(ParameterNames.ConverterTypeModel);
  126. if (ConverterImgModel != null)
  127. {
  128. App.mainWindowViewModel.MaxValue = ConverterImgModel.PageIndexLists.Count();
  129. for (int i = 0; ConverterImgModel.PageIndexLists.Count > i; i++)
  130. {
  131. ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1;
  132. }
  133. result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.imageType, ConverterImgModel.imgOptions);
  134. }
  135. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  136. break;
  137. case "PPT":
  138. ConverterPPTDialogModel ConverterPPTModel = e.Parameters.GetValue<ConverterPPTDialogModel>(ParameterNames.ConverterTypeModel);
  139. if (ConverterPPTModel != null)
  140. {
  141. App.mainWindowViewModel.MaxValue = ConverterPPTModel.PageIndexLists.Count();
  142. for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++)
  143. {
  144. ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1;
  145. }
  146. result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword, ConverterPPTModel.pPTOptions);
  147. }
  148. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  149. break;
  150. case "RTF":
  151. ConverterRTFDialogModel ConverterRTFModel = e.Parameters.GetValue<ConverterRTFDialogModel>(ParameterNames.ConverterTypeModel);
  152. if (ConverterRTFModel != null)
  153. {
  154. App.mainWindowViewModel.MaxValue = ConverterRTFModel.PageIndexLists.Count();
  155. for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++)
  156. {
  157. ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1;
  158. }
  159. result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword, ConverterRTFModel.rTFOptions);
  160. }
  161. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  162. break;
  163. case "Text":
  164. ConverterTextDialogModel ConverterTextModel = e.Parameters.GetValue<ConverterTextDialogModel>(ParameterNames.ConverterTypeModel);
  165. if (ConverterTextModel != null)
  166. {
  167. App.mainWindowViewModel.MaxValue = ConverterTextModel.PageIndexLists.Count();
  168. for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++)
  169. {
  170. ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1;
  171. }
  172. result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword, ConverterTextModel.txtOptions);
  173. }
  174. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  175. break;
  176. case "Word":
  177. ConverterWordDialogModel ConverterWordModel = e.Parameters.GetValue<ConverterWordDialogModel>(ParameterNames.ConverterTypeModel);
  178. if (ConverterWordModel != null)
  179. {
  180. App.mainWindowViewModel.MaxValue = ConverterWordModel.PageIndexLists.Count();
  181. for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++)
  182. {
  183. ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1;
  184. }
  185. result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword, ConverterWordModel.wordOptions);
  186. }
  187. else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
  188. break;
  189. default:
  190. break;
  191. }
  192. }
  193. }
  194. }