RedactionDocumentContentViewModel.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public int PageRangeNumber
  35. {
  36. get { return PDFViewer.Document.PageCount; }
  37. }
  38. public RedactionDocumentContentViewModel(IRegionManager regionManager)
  39. {
  40. this.regionManager = regionManager;
  41. ViewerRegionName = RegionNames.BackgroundViewerRegionName;
  42. }
  43. private void CurrentViewer_CustomDrawHandler(object sender, CustomDrawData e)
  44. {
  45. }
  46. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  47. {
  48. }
  49. public bool IsNavigationTarget(NavigationContext navigationContext)
  50. {
  51. return true;
  52. }
  53. public void OnNavigatedFrom(NavigationContext navigationContext)
  54. {
  55. }
  56. public void OnNavigatedTo(NavigationContext navigationContext)
  57. {
  58. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  59. if (pdfViewer != null)
  60. {
  61. if (!regionManager.Regions[ViewerRegionName].Views.Contains(PDFViewer))
  62. {
  63. PDFViewer = new CPDFViewer();
  64. PDFViewer.InitDocument(pdfViewer.Document);
  65. Document = PDFViewer.Document;
  66. PDFViewer.CustomDrawHandler += CurrentViewer_CustomDrawHandler;
  67. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  68. regionManager.AddToRegion(ViewerRegionName, PDFViewer);
  69. PDFViewer.SetAnnotInteraction(!PDFViewer.GetAnnotInteraction());
  70. PDFViewer.Load();
  71. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  72. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  73. }
  74. }
  75. }
  76. }
  77. }