ScanPropertyPanelViewModel.cs 2.4 KB

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