123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- 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
- {
- /// <summary>
- /// 文档地址;
- /// </summary>
- public string InputPath="";
- /// <summary>
- /// 输出地址;
- /// </summary>
- public string OutputPath="";
- /// <summary>
- /// 进度;
- /// </summary>
- public OnProgress GetProgress=null;
- /// <summary>
- /// 页码 页码范围;
- /// </summary>
- public List<int> PageIndexLists= new List<int> { };
- /// <summary>
- /// 页面信息
- /// </summary>
- public string PageRange = "";
- /// <summary>
- /// 文档密码;
- /// </summary>
- public string Pawssword="";
- /// <summary>
- /// 文档密码;
- /// </summary>
- public bool IsCustomFileName=true;
-
- /// <summary>
- /// OCR,与部分功能;
- /// </summary>
- 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<string>(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<ConverterCSVDialogModel>(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<ConverterExcelDialogModel>(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<ConverterHTMLDialogModel>(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<ConverterImgDialogModel>(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<ConverterPPTDialogModel>(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<ConverterRTFDialogModel>(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<ConverterTextDialogModel>(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<ConverterWordDialogModel>(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;
- }
- }
- }
- }
|