RedactionDocumentContentViewModel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.PdfViewer;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model;
  6. using PDF_Office.Model.EditTools.Background;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing.Printing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Media.Imaging;
  16. namespace PDF_Office.ViewModels.EditTools.Redaction
  17. {
  18. public class RedactionDocumentContentViewModel : BindableBase, INavigationAware
  19. {
  20. private CPDFViewer pdfViewer;
  21. public IRegionManager regionManager;
  22. public CPDFViewer PDFViewer;
  23. public CPDFDocument Document;
  24. public string ViewerRegionName { get; set; }
  25. private int _currentPageIndex;
  26. public int CurrentPageIndex
  27. {
  28. get { return _currentPageIndex; }
  29. set
  30. {
  31. SetProperty(ref _currentPageIndex, PDFViewer.CurrentIndex);
  32. }
  33. }
  34. private int _pageSize;
  35. public int PageRangeNumber
  36. {
  37. get { return _pageSize; }
  38. set { SetProperty(ref _pageSize, value); }
  39. }
  40. public RedactionDocumentContentViewModel(IRegionManager regionManager)
  41. {
  42. this.regionManager = regionManager;
  43. PageRangeNumber = PDFViewer.Document.PageCount;
  44. ViewerRegionName = RegionNames.BackgroundViewerRegionName;
  45. }
  46. private void CurrentViewer_CustomDrawHandler(object sender, CustomDrawData e)
  47. {
  48. }
  49. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  50. {
  51. }
  52. public bool IsNavigationTarget(NavigationContext navigationContext)
  53. {
  54. return true;
  55. }
  56. public void OnNavigatedFrom(NavigationContext navigationContext)
  57. {
  58. }
  59. public void OnNavigatedTo(NavigationContext navigationContext)
  60. {
  61. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  62. if (pdfViewer != null)
  63. {
  64. if (!regionManager.Regions[ViewerRegionName].Views.Contains(PDFViewer))
  65. {
  66. PDFViewer = new CPDFViewer();
  67. PDFViewer.InitDocument(pdfViewer.Document);
  68. Document = PDFViewer.Document;
  69. PDFViewer.CustomDrawHandler += CurrentViewer_CustomDrawHandler;
  70. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  71. regionManager.AddToRegion(ViewerRegionName, PDFViewer);
  72. PDFViewer.SetAnnotInteraction(!PDFViewer.GetAnnotInteraction());
  73. PDFViewer.Load();
  74. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  75. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  76. }
  77. }
  78. }
  79. }
  80. }