-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAnnotationsViewModel.cs
135 lines (124 loc) · 4.15 KB
/
AnnotationsViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using syncfusion.demoscommon.wpf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Windows.PdfViewer;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Resources;
namespace syncfusion.pdfviewerdemos.wpf
{
/// <summary>
/// Represents the view model class
/// </summary>
public class AnnotationsViewModel : INotifyPropertyChanged
{
private Stream m_documentStream;
ICommand m_showAnnotationsCommand;
ICommand m_documentLoadedCommand;
bool m_showAnnotationsParameter = true;
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Initializes a new instance of the <see cref="TextMarkupsViewModel"/> class.
/// </summary>
public AnnotationsViewModel()
{
m_documentStream = GetFileStream("Annotations.pdf");
}
/// <summary>
/// Gets or sets the value to show or hide annotations
/// </summary>
public bool ShowAnnotationsParameter
{
get
{
return m_showAnnotationsParameter;
}
set
{
m_showAnnotationsParameter = value;
OnPropertyChanged(new PropertyChangedEventArgs("ShowAnnotationsParameter"));
}
}
/// <summary>
/// Gets or sets the document path.
/// </summary>
public Stream DocumentStream
{
get
{
return m_documentStream;
}
set
{
m_documentStream = value;
}
}
/// <summary>
/// Command to show or hide annotations
/// </summary>
public ICommand ShowAnnotationsCommand
{
get
{
if (m_showAnnotationsCommand == null)
{
m_showAnnotationsCommand = new DelegateCommand<PdfViewerControl>(ShowAnnotations);
}
return m_showAnnotationsCommand;
}
}
/// <summary>
/// Command for document loaded
/// </summary>
public ICommand DocumentLoadedCommand
{
get
{
if (m_documentLoadedCommand == null)
{
m_documentLoadedCommand = new DelegateCommand<object>(OnDocumentLoaded);
}
return m_documentLoadedCommand;
}
}
void OnDocumentLoaded(object sender)
{
ShowAnnotationsParameter = true;
}
void ShowAnnotations(PdfViewerControl pdfViewerControl)
{
PdfLoadedDocument pdfLoadedDocument = pdfViewerControl.LoadedDocument;
for (int i = 0; i < pdfLoadedDocument.Pages.Count; i++)
{
for (int j = 0; j < pdfLoadedDocument.Pages[i].Annotations.Count; j++)
{
string annotationName = pdfLoadedDocument.Pages[i].Annotations[j].Name;
if (ShowAnnotationsParameter)
pdfViewerControl.ShowAnnotation(annotationName);
else
pdfViewerControl.HideAnnotation(annotationName);
}
}
}
private Stream GetFileStream(string fileName)
{
Uri uriResource = new Uri("/syncfusion.pdfviewerdemos.wpf;component/Assets/" + fileName, UriKind.Relative);
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uriResource);
return streamResourceInfo.Stream;
}
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
}
}