using System; using System.Collections.Generic; using ComPDFKit_Conversion.Converter; using System.Linq; using System.Text; using System.Threading.Tasks; using ComDocumentAIKit; using ComPDFKit_Conversion.Options; using Microsoft.Office.Interop.Word; using PDF_Office.Helper; namespace PDF_Office.Model.Dialog.ConverterDialogs { public class ConvertOptions { public COCRLanguage OCRLanguage = COCRLanguage.English; public bool IsAllowOCR = false; public bool IsContainOCRBgImage =false; public bool IsContainAnnotations = true; public bool IsContainImages = true; public ContentOptions ContentOpts = ContentOptions.AllContent; public WorksheetOptions WorksheetOpts = WorksheetOptions.ForEachPage; public PageAndNavigationPaneOptions PageAndNavigationPaneOpts = PageAndNavigationPaneOptions.SinglePageNavigationByBookmarks; public ImgType ImageType = ImgType.PNG; public uint ImageDpi = 150; public bool IsMergeCsv = false; } public class ConverterDialogsModel { /// /// 文档地址; /// public string InputPath=""; /// /// 输出地址; /// public string OutputPath=""; /// /// 进度; /// public OnProgress GetProgress=null; /// /// 页码 页码范围; /// public List PageIndexLists= new List { }; /// /// 页面信息 /// public string PageRange = ""; /// /// 文档密码; /// public string Pawssword=""; /// /// 文档密码; /// public bool IsCustomFileName=true; /// /// OCR,与部分功能; /// public ConvertOptions Options=new ConvertOptions(); private void ConverterClear() { ConverterHelper.Clear(); App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } private void SetProgress(int pageIndex) { App.mainWindowViewModel.Value = pageIndex; if (App.mainWindowViewModel.Value == App.mainWindowViewModel.MaxValue) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } } public async void OnOpened(Prism.Services.Dialogs.DialogResult e) { if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel|| e.Result== Prism.Services.Dialogs.ButtonResult.None) { return; } bool result = false; string convertType = ""; OnProgress GetProgress = null; GetProgress += SetProgress; App.mainWindowViewModel.ProcessCloseAction = ConverterClear; convertType = e.Parameters.GetValue(ParameterNames.ConverterType).ToString(); App.mainWindowViewModel.ProgressTitle = "Converting"; App.mainWindowViewModel.Value = 0; App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible; switch (convertType) { case "CSV": ConverterCSVDialogModel ConverterCSVModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterCSVModel != null) { App.mainWindowViewModel.MaxValue = ConverterCSVModel.PageIndexLists.Count(); for (int i = 0; ConverterCSVModel.PageIndexLists.Count > i; i++) { ConverterCSVModel.PageIndexLists[i] = ConverterCSVModel.PageIndexLists[i] + 1; } result = await ConverterHelper.CSVConvert(ConverterCSVModel.InputPath, ConverterCSVModel.OutputPath, GetProgress, ConverterCSVModel.PageIndexLists, ConverterCSVModel.Pawssword, ConverterCSVModel.csvOptions, ConverterCSVModel.IsCustomFileName); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "Excel": ConverterExcelDialogModel ConverterExcelModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterExcelModel != null) { App.mainWindowViewModel.MaxValue = ConverterExcelModel.PageIndexLists.Count(); for (int i = 0; ConverterExcelModel.PageIndexLists.Count > i; i++) { ConverterExcelModel.PageIndexLists[i] = ConverterExcelModel.PageIndexLists[i] + 1; } result = await ConverterHelper.ExcelConvert(ConverterExcelModel.InputPath, ConverterExcelModel.OutputPath, GetProgress, ConverterExcelModel.PageIndexLists, ConverterExcelModel.Pawssword, ConverterExcelModel.excelOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "HTML": ConverterHTMLDialogModel ConverterHTMLModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterHTMLModel != null) { App.mainWindowViewModel.MaxValue = ConverterHTMLModel.PageIndexLists.Count(); for (int i = 0; ConverterHTMLModel.PageIndexLists.Count > i; i++) { ConverterHTMLModel.PageIndexLists[i] = ConverterHTMLModel.PageIndexLists[i] + 1; } result = await ConverterHelper.HTMLConvert(ConverterHTMLModel.InputPath, ConverterHTMLModel.OutputPath, GetProgress, ConverterHTMLModel.PageIndexLists, ConverterHTMLModel.Pawssword, ConverterHTMLModel.htmlOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "Img": ConverterImgDialogModel ConverterImgModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterImgModel != null) { App.mainWindowViewModel.MaxValue = ConverterImgModel.PageIndexLists.Count(); for (int i = 0; ConverterImgModel.PageIndexLists.Count > i; i++) { ConverterImgModel.PageIndexLists[i] = ConverterImgModel.PageIndexLists[i] + 1; } result = await ConverterHelper.ImgConvert(ConverterImgModel.InputPath, ConverterImgModel.OutputPath, GetProgress, ConverterImgModel.PageIndexLists, ConverterImgModel.Pawssword, ConverterImgModel.imageType, ConverterImgModel.imgOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "PPT": ConverterPPTDialogModel ConverterPPTModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterPPTModel != null) { App.mainWindowViewModel.MaxValue = ConverterPPTModel.PageIndexLists.Count(); for (int i = 0; ConverterPPTModel.PageIndexLists.Count > i; i++) { ConverterPPTModel.PageIndexLists[i] = ConverterPPTModel.PageIndexLists[i] + 1; } result = await ConverterHelper.PPTConvert(ConverterPPTModel.InputPath, ConverterPPTModel.OutputPath, GetProgress, ConverterPPTModel.PageIndexLists, ConverterPPTModel.Pawssword, ConverterPPTModel.pPTOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "RTF": ConverterRTFDialogModel ConverterRTFModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterRTFModel != null) { App.mainWindowViewModel.MaxValue = ConverterRTFModel.PageIndexLists.Count(); for (int i = 0; ConverterRTFModel.PageIndexLists.Count > i; i++) { ConverterRTFModel.PageIndexLists[i] = ConverterRTFModel.PageIndexLists[i] + 1; } result = await ConverterHelper.RTFConvert(ConverterRTFModel.InputPath, ConverterRTFModel.OutputPath, GetProgress, ConverterRTFModel.PageIndexLists, ConverterRTFModel.Pawssword, ConverterRTFModel.rTFOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "Text": ConverterTextDialogModel ConverterTextModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterTextModel != null) { App.mainWindowViewModel.MaxValue = ConverterTextModel.PageIndexLists.Count(); for (int i = 0; ConverterTextModel.PageIndexLists.Count > i; i++) { ConverterTextModel.PageIndexLists[i] = ConverterTextModel.PageIndexLists[i] + 1; } result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword, ConverterTextModel.txtOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; case "Word": ConverterWordDialogModel ConverterWordModel = e.Parameters.GetValue(ParameterNames.ConverterTypeModel); if (ConverterWordModel != null) { App.mainWindowViewModel.MaxValue = ConverterWordModel.PageIndexLists.Count(); for (int i = 0; ConverterWordModel.PageIndexLists.Count > i; i++) { ConverterWordModel.PageIndexLists[i] = ConverterWordModel.PageIndexLists[i] + 1; } result = await ConverterHelper.WordConvert(ConverterWordModel.InputPath, ConverterWordModel.OutputPath, GetProgress, ConverterWordModel.PageIndexLists, ConverterWordModel.Pawssword, ConverterWordModel.wordOptions); } else { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; } break; default: break; } } } }