ConverterExcelDialogViewModel.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. using ComDocumentAIKit;
  2. using ComPDFKit_Conversion.Converter;
  3. using ComPDFKit_Conversion.Options;
  4. using ComPDFKitViewer.PdfViewer;
  5. using ImageMagick;
  6. using Microsoft.Office.Interop.Excel;
  7. using PDF_Master.CustomControl;
  8. using PDF_Master.Helper;
  9. using PDF_Master.Model;
  10. using PDF_Master.Model.Dialog.ConverterDialogs;
  11. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  12. using PDF_Master.Properties;
  13. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter;
  14. using Prism.Commands;
  15. using Prism.Mvvm;
  16. using Prism.Services.Dialogs;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Globalization;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Windows;
  24. using System.Windows.Forms;
  25. using DialogResult = Prism.Services.Dialogs.DialogResult;
  26. namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
  27. {
  28. public class ConverterExcelDialogViewModel : BindableBase, IDialogAware
  29. {
  30. #region 文案
  31. private string T_title;
  32. public string T_Title
  33. {
  34. get { return T_title; }
  35. set
  36. {
  37. SetProperty(ref T_title, value);
  38. }
  39. }
  40. private string T_yes;
  41. public string T_YES
  42. {
  43. get { return T_yes; }
  44. set
  45. {
  46. SetProperty(ref T_yes, value);
  47. }
  48. }
  49. private string T_no;
  50. public string T_No
  51. {
  52. get { return T_no; }
  53. set
  54. {
  55. SetProperty(ref T_no, value);
  56. }
  57. }
  58. private string T_onlyTables;
  59. public string T_OnlyTables
  60. {
  61. get { return T_onlyTables; }
  62. set
  63. {
  64. SetProperty(ref T_onlyTables, value);
  65. }
  66. }
  67. private string T_allContents;
  68. public string T_AllContents
  69. {
  70. get { return T_allContents; }
  71. set
  72. {
  73. SetProperty(ref T_allContents, value);
  74. }
  75. }
  76. private string T_eachPageAllContents;
  77. public string T_EachPageAllContents
  78. {
  79. get { return T_eachPageAllContents; }
  80. set
  81. {
  82. SetProperty(ref T_eachPageAllContents, value);
  83. }
  84. }
  85. private string T_fileAllContents;
  86. public string T_FileAllContents
  87. {
  88. get { return T_fileAllContents; }
  89. set
  90. {
  91. SetProperty(ref T_fileAllContents, value);
  92. }
  93. }
  94. private string T_eachTableOnlyTables;
  95. public string T_EachTableOnlyTables
  96. {
  97. get { return T_eachTableOnlyTables; }
  98. set
  99. {
  100. SetProperty(ref T_eachTableOnlyTables, value);
  101. }
  102. }
  103. private string T_eachPageOnlyTables;
  104. public string T_EachPageOnlyTables
  105. {
  106. get { return T_eachPageOnlyTables; }
  107. set
  108. {
  109. SetProperty(ref T_eachPageOnlyTables, value);
  110. }
  111. }
  112. private string T_fileOnlyTables;
  113. public string T_FileOnlyTables
  114. {
  115. get { return T_fileOnlyTables; }
  116. set
  117. {
  118. SetProperty(ref T_fileOnlyTables, value);
  119. }
  120. }
  121. private string T_onlyText;
  122. public string T_OnlyText
  123. {
  124. get { return T_onlyText; }
  125. set
  126. {
  127. SetProperty(ref T_onlyText, value);
  128. }
  129. }
  130. private string T_settings;
  131. public string T_Settings
  132. {
  133. get { return T_settings; }
  134. set
  135. {
  136. SetProperty(ref T_settings, value);
  137. }
  138. }
  139. private string T_pageRange;
  140. public string T_PageRange
  141. {
  142. get { return T_pageRange; }
  143. set
  144. {
  145. SetProperty(ref T_pageRange, value);
  146. }
  147. }
  148. private string _TextUpgrade;
  149. public string TextUpgrade
  150. {
  151. get { return _TextUpgrade; }
  152. set { _TextUpgrade = value; }
  153. }
  154. private void IntString()
  155. {
  156. TextUpgrade = App.ServiceLoader.GetString("TextUpgrade");
  157. T_Title = App.MainPageLoader.GetString("Convert_PDFToExcelTitle");
  158. T_YES = App.MainPageLoader.GetString("Convert_Yes");
  159. T_No = App.MainPageLoader.GetString("Convert_No");
  160. T_AllContents = App.MainPageLoader.GetString("Convert_PDFToExcelAllContents");
  161. T_EachPageAllContents = App.MainPageLoader.GetString("Convert_PDFToExcelAllContentsEachPage");
  162. T_FileAllContents = App.MainPageLoader.GetString("Convert_PDFToExcelAllContentsFile");
  163. T_OnlyTables = App.MainPageLoader.GetString("Convert_PDFToExcelAllOnlyTables");
  164. T_EachTableOnlyTables = App.MainPageLoader.GetString("Convert_PDFToExcelAllOnlyTablesEachTable");
  165. T_EachPageOnlyTables = App.MainPageLoader.GetString("Convert_PDFToExcelAllOnlyTablesEachPage");
  166. T_FileOnlyTables = App.MainPageLoader.GetString("Convert_PDFToExcelAllOnlyTablesFile");
  167. T_OnlyText = App.MainPageLoader.GetString("Convert_PDFToExcelOnlyText");
  168. T_Settings = App.MainPageLoader.GetString("Convert_PDFToExcelSettings");
  169. T_PageRange = App.MainPageLoader.GetString("Convert_PDFPageRange");
  170. }
  171. #endregion 参数和属性
  172. public string Title => "";
  173. public event Action<IDialogResult> RequestClose;
  174. #region 参数和属性
  175. public ConverterExcelDialogModel ConverterExcelModel = new ConverterExcelDialogModel();
  176. public CPDFViewer currentViewer;
  177. public string CurrentPageIndex = "1";
  178. public bool IsCurrentPageIndex = false;
  179. public IDialogService dialogs;
  180. public string PageRangeText { set; get; } = "0";
  181. public string PageRangeSelectIndex { set; get; } = "0";
  182. private int _anyContentSelectIndex = 0;
  183. public int AnyContentSelectIndex
  184. {
  185. get { return _anyContentSelectIndex; }
  186. set
  187. {
  188. SetProperty(ref _anyContentSelectIndex, value);
  189. AnyContent(_anyContentSelectIndex);
  190. }
  191. }
  192. private int _onlyTableSelectIndex = 0;
  193. public int OnlyTableSelectIndex
  194. {
  195. get { return _onlyTableSelectIndex; }
  196. set
  197. {
  198. SetProperty(ref _onlyTableSelectIndex, value);
  199. OnlyTable(_onlyTableSelectIndex);
  200. }
  201. }
  202. private int maxPageRange = 0;
  203. public int MaxPageRange
  204. {
  205. get { return maxPageRange; }
  206. set
  207. {
  208. SetProperty(ref maxPageRange, value);
  209. }
  210. }
  211. private bool oCRCheckBoxIsCheckBox = false;
  212. public bool OCRCheckBoxIsCheckBox
  213. {
  214. get { return oCRCheckBoxIsCheckBox; }
  215. set
  216. {
  217. SetProperty(ref oCRCheckBoxIsCheckBox, value);
  218. ConverterExcelModel.Options.IsAllowOCR = oCRCheckBoxIsCheckBox;
  219. }
  220. }
  221. private bool oCRIsEnable = true;
  222. public bool OCRIsEnable
  223. {
  224. get { return oCRIsEnable; }
  225. set
  226. {
  227. SetProperty(ref oCRIsEnable, value);
  228. if (value == true)
  229. {
  230. ConverterExcelModel.Options.IsAllowOCR = OCRCheckBoxIsCheckBox;
  231. }
  232. else
  233. {
  234. ConverterExcelModel.Options.IsAllowOCR = false;
  235. }
  236. }
  237. }
  238. private int languageSelectedIndex = 2;
  239. public int LanguageSelectedIndex
  240. {
  241. get { return languageSelectedIndex; }
  242. set
  243. {
  244. SetProperty(ref languageSelectedIndex, value);
  245. SelectLanguage(languageSelectedIndex);
  246. }
  247. }
  248. private Dictionary<string, string> CheckPageSelect = new Dictionary<string, string>();
  249. private void InitCheckPageSelect()
  250. {
  251. CheckPageSelect.Clear();
  252. if (!IsCurrentPageIndex)
  253. {
  254. CheckPageSelect.Add("0", "0");
  255. CheckPageSelect.Add("1", "1");
  256. CheckPageSelect.Add("2", "2");
  257. CheckPageSelect.Add("3", "3");
  258. CheckPageSelect.Add("4", "4");
  259. }
  260. else
  261. {
  262. CheckPageSelect.Add("0", "0");
  263. CheckPageSelect.Add("1", "-2");
  264. CheckPageSelect.Add("2", "1");
  265. CheckPageSelect.Add("3", "2");
  266. CheckPageSelect.Add("4", "3");
  267. }
  268. }
  269. private Visibility limitationsConvertVisible = Visibility.Hidden;
  270. public Visibility LimitationsConvertVisible
  271. {
  272. get { return limitationsConvertVisible; }
  273. set
  274. {
  275. SetProperty(ref limitationsConvertVisible, value);
  276. }
  277. }
  278. #endregion
  279. #region 委托声明
  280. public DelegateCommand<string> RadioButtonCommand { get; set; }
  281. public DelegateCommand CancelCommand { get; set; }
  282. public DelegateCommand ConverterCommnad { get; set; }
  283. public DelegateCommand<object> CmbPageSelectionChanged { get; set; }
  284. public DelegateCommand<object> CmbPageTextChanged { get; set; }
  285. public DelegateCommand BatchConverterCommand { get; set; }
  286. public DelegateCommand<object> PreviewCancelDownCommand { get; set; }
  287. public DelegateCommand SetCustomPageRangeCommand { get; set; }
  288. public DelegateCommand UnlockMouseDownCommand { get; set; }
  289. public DelegateCommand OpenOCRCommand { get; set; }
  290. #endregion
  291. public ConverterExcelDialogViewModel(IDialogService dialogService)
  292. {
  293. IntString();
  294. CancelCommand = new DelegateCommand(cancel);
  295. ConverterCommnad = new DelegateCommand(converter);
  296. RadioButtonCommand = new DelegateCommand<string>(radiobutton);
  297. SetCustomPageRangeCommand = new DelegateCommand(SetCustomPageRange);
  298. CmbPageSelectionChanged = new DelegateCommand<object>(CmbPageSelectionChangedEvent);
  299. CmbPageTextChanged = new DelegateCommand<object>(CmbPageTextChangedEvent);
  300. PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
  301. BatchConverterCommand = new DelegateCommand(BatchConverter);
  302. UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
  303. OpenOCRCommand = new DelegateCommand(openOCR);
  304. dialogs = dialogService;
  305. }
  306. #region 逻辑函数
  307. private void openOCR()
  308. {
  309. if (OCRCheckBoxIsCheckBox == true)
  310. {
  311. bool folderMD5 = FileComparisonHelper.OCRModelItExist();
  312. if (folderMD5)
  313. {
  314. string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
  315. CPDFConverter.InitOCRLibrary(Path.Combine(folderPath, "x64"));
  316. CPDFConverter.SetOCRModelPath(Path.Combine(folderPath, "source", "models"));
  317. }
  318. else
  319. {
  320. AlertsMessage alertsMessage = new AlertsMessage();
  321. alertsMessage.ShowDialog(App.MainPageLoader.GetString("OCR_PleaseDownload"), "", App.MainPageLoader.GetString("OCR_CancelDownload"), App.MainPageLoader.GetString("OCR_Download"));
  322. if (alertsMessage.result == ContentResult.Ok)
  323. {
  324. FileComparisonHelper.RemoveOCRModel();
  325. DialogParameters oCRDownloadProgress = new DialogParameters();
  326. dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
  327. {
  328. if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
  329. {
  330. string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
  331. CPDFConverter.InitOCRLibrary(Path.Combine(folderPath, "x64"));
  332. CPDFConverter.SetOCRModelPath(Path.Combine(folderPath, "source", "models"));
  333. }
  334. else
  335. {
  336. OCRCheckBoxIsCheckBox = false;
  337. }
  338. });
  339. }
  340. else
  341. {
  342. OCRCheckBoxIsCheckBox = false;
  343. }
  344. }
  345. }
  346. }
  347. public void SetCustomPageRange()
  348. {
  349. if (PageRangeSelectIndex == CheckPageSelect["4"])
  350. {
  351. List<int> PageIndexLists = new List<int>();
  352. if (!CommonHelper.GetPagesInRange(ref PageIndexLists, PageRangeText, currentViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  353. { //TODO
  354. //AlertsMessage alertsMessage = new AlertsMessage();
  355. //alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  356. //if (alertsMessage.result == ContentResult.Ok)
  357. //{
  358. // return;
  359. //}
  360. //else
  361. //{
  362. // //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
  363. // //{
  364. // // Unicode = Unicode,
  365. // // Status = EnumDelete.StatusCreate
  366. // //});
  367. // return;
  368. //}
  369. }
  370. }
  371. }
  372. private void cancel()
  373. {
  374. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  375. }
  376. private void PreviewCancelDown(object e)
  377. {
  378. var PageRangeComboBox = e as WritableComboBox;
  379. if (PageRangeComboBox != null)
  380. {
  381. PageRangeComboBox.IsloseFocus = false;
  382. }
  383. }
  384. private void converter()
  385. {
  386. if (PageRangeSelectIndex == CheckPageSelect["4"])
  387. {
  388. List<int> PageIndexLists = new List<int>();
  389. if (!CommonHelper.GetPagesInRange(ref PageIndexLists, PageRangeText, currentViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  390. { //TODO
  391. AlertsMessage alertsMessage = new AlertsMessage();
  392. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  393. if (alertsMessage.result == ContentResult.Ok)
  394. {
  395. return;
  396. }
  397. else
  398. {
  399. //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
  400. //{
  401. // Unicode = Unicode,
  402. // Status = EnumDelete.StatusCreate
  403. //});
  404. return;
  405. }
  406. }
  407. }
  408. System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
  409. /*
  410. *设置这个对话框的起始保存路径
  411. */
  412. sfd.InitialDirectory = currentViewer.Document.FilePath;
  413. /*
  414. *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
  415. */
  416. sfd.Filter = "Excel|*.xlsx;";
  417. /*
  418. *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
  419. */
  420. sfd.FileName = currentViewer.Document.FileName + ".xlsx";
  421. /*
  422. * 做一些工作
  423. */
  424. if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  425. {
  426. ConverterExcelModel.OutputPath = sfd.FileName;
  427. try { if (File.Exists(ConverterExcelModel.OutputPath)) File.Delete(ConverterExcelModel.OutputPath); }
  428. catch
  429. {
  430. AlertsMessage alertsMessage = new AlertsMessage();
  431. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("FileNotExistWarning"), App.ServiceLoader.GetString("Text_ok"));
  432. return;
  433. }
  434. }
  435. else
  436. {
  437. return;
  438. }
  439. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterExcelModel.PageRange, PageRangeText, !IsCurrentPageIndex, CurrentPageIndex);
  440. if (ConverterExcelModel.PageRange == "")
  441. {
  442. Trace.WriteLine("输入不对");
  443. AlertsMessage alertsMessage = new AlertsMessage();
  444. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  445. return;
  446. }
  447. char[] enumerationSeparator = new char[] { ',' };
  448. char[] rangeSeparator = new char[] { '-' };
  449. if (!CommonHelper.GetPagesInRange(ref ConverterExcelModel.PageIndexLists, ConverterExcelModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  450. { //TODO
  451. Trace.WriteLine("输入不对");
  452. AlertsMessage alertsMessage = new AlertsMessage();
  453. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  454. return;
  455. }
  456. ConverterExcelModel.excelOptions = ConverterExcelModel.ExcelOptions();
  457. //DialogParameters value = new DialogParameters();
  458. //value.Add(ParameterNames.ConverterType, "Excel");
  459. //value.Add(ParameterNames.ConverterTypeModel, ConverterExcelModel);
  460. var dialogresult = new DialogResult(ButtonResult.OK);
  461. dialogresult.Parameters.Add(ParameterNames.ConverterType, "Excel");
  462. dialogresult.Parameters.Add(ParameterNames.ConverterTypeModel, ConverterExcelModel);
  463. RequestClose.Invoke(dialogresult);
  464. //RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  465. //dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e =>
  466. //{
  467. //});
  468. }
  469. private void CmbPageSelectionChangedEvent(object e)
  470. {
  471. ///这里采用的是将预览UI控件传递过来的方式,为下下策
  472. ///正确的方式应该是 通过声明一些属性,再通过绑定来更新预览控件对应值的形式
  473. ///但是目前发现自定义控件的依赖属性绑定有些问题,因此先用此方法,将业务逻辑代码先调整到VM里
  474. var ConverterPreview = e as PageTurningPreview;
  475. if (ConverterPreview != null)
  476. {
  477. string PageRangeSelectIndex = this.PageRangeSelectIndex;
  478. var currentViewer = this.currentViewer;
  479. string PageRange = "";
  480. var PageRangeText = this.PageRangeText;
  481. if (PageRangeSelectIndex == CheckPageSelect["0"] || PageRangeSelectIndex == CheckPageSelect["2"] || PageRangeSelectIndex == CheckPageSelect["3"] || PageRangeSelectIndex == CheckPageSelect["4"])
  482. {
  483. if (PageRangeSelectIndex == CheckPageSelect["4"]) { HomePageEditHelper.GetPagerange("0", currentViewer, ref PageRange, PageRangeText, !IsCurrentPageIndex); } else { HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref PageRange, PageRangeText, !IsCurrentPageIndex); }
  484. char[] enumerationSeparator = new char[] { ',' };
  485. char[] rangeSeparator = new char[] { '-' };
  486. if (!CommonHelper.GetPagesInRange(ref ConverterPreview.PageIndexLists, PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  487. { //TODO
  488. ConverterPreview.PageIndexLists.Add(0);
  489. Trace.WriteLine("输入不对");
  490. AlertsMessage alertsMessage = new AlertsMessage();
  491. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  492. return;
  493. }
  494. }
  495. if (PageRangeSelectIndex == CheckPageSelect["1"])
  496. {
  497. char[] enumerationSeparator = new char[] { ',' };
  498. char[] rangeSeparator = new char[] { '-' };
  499. if (!CommonHelper.GetPagesInRange(ref ConverterPreview.PageIndexLists, (currentViewer.CurrentIndex + 1).ToString()
  500. , currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  501. { //TODO
  502. Trace.WriteLine("输入不对");
  503. AlertsMessage alertsMessage = new AlertsMessage();
  504. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  505. return;
  506. }
  507. this.CurrentPageIndex = (ConverterPreview.PageIndexLists.Last<int>() + 1).ToString();
  508. }
  509. // ConverterPreview.PageIndex.Text = (ConverterPreview.PageIndexLists.Last<int>() + 1).ToString();
  510. ConverterPreview.PageIndex.Text = ConverterPreview.PageIndexLists.Count.ToString();
  511. ConverterPreview.CurrentIndex = 0;
  512. }
  513. }
  514. private void CmbPageTextChangedEvent(object e)
  515. {
  516. var ConverterPreview = e as PageTurningPreview;
  517. if (ConverterPreview != null)
  518. {
  519. if (ConverterPreview != null)
  520. {
  521. string PageRangeSelectIndex = this.PageRangeSelectIndex;
  522. var currentViewer = this.currentViewer;
  523. string PageRange = "";
  524. var PageRangeText = this.PageRangeText;
  525. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref PageRange, PageRangeText, !IsCurrentPageIndex);
  526. char[] enumerationSeparator = new char[] { ',' };
  527. char[] rangeSeparator = new char[] { '-' };
  528. if (!CommonHelper.GetPagesInRange(ref ConverterPreview.PageIndexLists, PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  529. { //TODO
  530. HomePageEditHelper.GetPagerange("0", currentViewer, ref PageRange, PageRangeText, !IsCurrentPageIndex);
  531. if (!CommonHelper.GetPagesInRange(ref ConverterPreview.PageIndexLists, PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  532. { //TODO
  533. ConverterPreview.PageIndexLists.Add(0);
  534. Trace.WriteLine("输入不对");
  535. AlertsMessage alertsMessage = new AlertsMessage();
  536. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  537. return;
  538. }
  539. ConverterPreview.PageIndex.Text = ConverterPreview.PageIndexLists.Count.ToString();
  540. ConverterPreview.CurrentIndex = 0;
  541. return;
  542. }
  543. else
  544. {
  545. // ConverterPreview.PageIndex.Text = (ConverterPreview.PageIndexLists.Last<int>() + 1).ToString();
  546. ConverterPreview.PageIndex.Text = ConverterPreview.PageIndexLists.Count.ToString();
  547. ConverterPreview.CurrentIndex = 0;
  548. }
  549. }
  550. }
  551. }
  552. private void BatchConverter()
  553. {
  554. DialogParameters convertpdftoword = new DialogParameters();
  555. convertpdftoword.Add(ParameterNames.BatchProcessing_Name, "0");
  556. convertpdftoword.Add("ConverterTypeIndex", 1);
  557. HomePageBatchProcessingDialogModel.FilePaths = new List<string> { currentViewer.Document.FilePath.ToString() };
  558. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 1;
  559. convertpdftoword.Add(ParameterNames.FilePath, new string[] { currentViewer.Document.FilePath.ToString() });
  560. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdftoword, e => { });
  561. }
  562. private void UnlockMouseDown()
  563. {
  564. ConverterHelper.convertUnlock();
  565. }
  566. private void radiobutton(string e)
  567. {
  568. string radioButton = e;
  569. if (radioButton != null)
  570. {
  571. switch (radioButton)
  572. {
  573. case "AnyContentRadioBtn":
  574. OCRIsEnable = true;
  575. AnyContent(AnyContentSelectIndex);
  576. break;
  577. case "OnlyTableRadioBtn":
  578. OnlyTable(OnlyTableSelectIndex);
  579. OCRIsEnable = false;
  580. break;
  581. case "OnlyTextRadioBtn":
  582. OCRIsEnable = true;
  583. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForTheDocument;
  584. ConverterExcelModel.Options.ContentOpts = ContentOptions.OnlyText;
  585. break;
  586. default:
  587. break;
  588. }
  589. }
  590. }
  591. private void AnyContent(int SelectedIndex)
  592. {
  593. switch (SelectedIndex)
  594. {
  595. case 0:
  596. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachPage;
  597. ConverterExcelModel.Options.ContentOpts = ContentOptions.AllContent;
  598. break;
  599. case 1:
  600. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForTheDocument;
  601. ConverterExcelModel.Options.ContentOpts = ContentOptions.AllContent;
  602. break;
  603. default:
  604. break;
  605. }
  606. }
  607. private void OnlyTable(int SelectedIndex)
  608. {
  609. ConverterExcelModel.Options.ContentOpts = ContentOptions.OnlyTable;
  610. switch (SelectedIndex)
  611. {
  612. case 0:
  613. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachTable;
  614. break;
  615. case 1:
  616. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForEachPage;
  617. break;
  618. case 2:
  619. ConverterExcelModel.Options.WorksheetOpts = WorksheetOptions.ForTheDocument;
  620. break;
  621. default:
  622. break;
  623. }
  624. }
  625. private void SelectLanguage(int SelectedIndex)
  626. {
  627. switch (SelectedIndex)
  628. {
  629. case 0:
  630. ConverterExcelModel.Options.OCRLanguage = COCRLanguage.COCRLanguageChinese;
  631. break;
  632. case 1:
  633. ConverterExcelModel.Options.OCRLanguage = COCRLanguage.COCRLanguageChineseTraditional;
  634. break;
  635. case 2:
  636. ConverterExcelModel.Options.OCRLanguage = COCRLanguage.COCRLanguageEnglish;
  637. break;
  638. case 3:
  639. ConverterExcelModel.Options.OCRLanguage = COCRLanguage.COCRLanguageJapanese;
  640. break;
  641. case 4:
  642. ConverterExcelModel.Options.OCRLanguage = COCRLanguage.COCRLanguageKorean;
  643. break;
  644. default:
  645. break;
  646. }
  647. }
  648. #endregion
  649. #region 构架行为
  650. public bool CanCloseDialog()
  651. {
  652. return true;
  653. }
  654. public void OnDialogClosed()
  655. {
  656. }
  657. public void OnDialogOpened(IDialogParameters parameters)
  658. {
  659. CPDFViewer pdfViewer = null;
  660. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  661. parameters.TryGetValue<bool>("PageRangeComboBoxCurrentPage", out IsCurrentPageIndex);
  662. if (pdfViewer != null)
  663. {
  664. InitCheckPageSelect();
  665. currentViewer = pdfViewer;
  666. MaxPageRange = currentViewer.Document.PageCount;
  667. if (currentViewer.Tag != null) { ConverterExcelModel.Pawssword = currentViewer.Tag.ToString(); }
  668. ConverterExcelModel.InputPath = pdfViewer.Document.FilePath;
  669. FileInfo fileinfo = new FileInfo(ConverterExcelModel.InputPath);
  670. ConverterExcelModel.OutputPath = fileinfo.DirectoryName;
  671. if (Settings.Default.UserDate.subscribestatus != 1)
  672. {
  673. LimitationsConvertVisible = Visibility.Visible;
  674. }
  675. LanguageSelectedIndex = ConverterHelper.GetCOCRLanguageInt();
  676. }
  677. }
  678. #endregion
  679. }
  680. }