ScanPropertyPanelViewModel.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace PDF_Office.ViewModels.PropertyPanel.Scan
  14. {
  15. class ScanPropertyPanelViewModel : BindableBase, INavigationAware
  16. {
  17. private int pageCount;
  18. public int PageCount
  19. {
  20. get { return pageCount; }
  21. set
  22. {
  23. SetProperty(ref pageCount, value);
  24. }
  25. }
  26. private List<int> setPageRange;
  27. public List<int> SetPageRange
  28. {
  29. get { return setPageRange; }
  30. set
  31. {
  32. SetProperty(ref setPageRange, value);
  33. }
  34. }
  35. private CPDFViewer PDFViewer;
  36. public IEventAggregator events;
  37. public DelegateCommand OCRCommand { get; set; }
  38. public bool IsNavigationTarget(NavigationContext navigationContext)
  39. {
  40. return true;
  41. }
  42. public void OnNavigatedFrom(NavigationContext navigationContext)
  43. {
  44. return;
  45. }
  46. public void OnNavigatedTo(NavigationContext navigationContext)
  47. {
  48. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  49. if (PDFViewer == null)
  50. {
  51. return;
  52. }
  53. else
  54. {
  55. PageCount = PDFViewer.Document.PageCount;
  56. }
  57. }
  58. public ScanPropertyPanelViewModel(IEventAggregator eventAggregator)
  59. {
  60. setPageRange = new List<int>();
  61. events = eventAggregator;
  62. OCRCommand = new DelegateCommand(OCR);
  63. }
  64. private void OCR()
  65. {
  66. try
  67. {
  68. events.GetEvent<ScanEvent>().Publish(new ScanEventArgs()
  69. {
  70. Unicode = App.mainWindowViewModel.SelectedItem.Unicode,
  71. PageRange = SetPageRange,
  72. Mode = ScanMode.OCR,
  73. ScanLanguage = ScanLanguageMode.ChineseS
  74. }
  75. );
  76. }
  77. catch (Exception e)
  78. {
  79. }
  80. }
  81. }
  82. }