diff --git a/Toolbar/CustomToolbar/App.config b/Toolbar/CustomToolbar/App.config new file mode 100644 index 0000000..c365e08 --- /dev/null +++ b/Toolbar/CustomToolbar/App.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Toolbar/CustomToolbar/App.xaml b/Toolbar/CustomToolbar/App.xaml new file mode 100644 index 0000000..7e9e14c --- /dev/null +++ b/Toolbar/CustomToolbar/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Toolbar/CustomToolbar/App.xaml.cs b/Toolbar/CustomToolbar/App.xaml.cs new file mode 100644 index 0000000..15bc31b --- /dev/null +++ b/Toolbar/CustomToolbar/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace CustomToolBar +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Toolbar/CustomToolbar/CustomToolbar.csproj b/Toolbar/CustomToolbar/CustomToolbar.csproj new file mode 100644 index 0000000..769e813 --- /dev/null +++ b/Toolbar/CustomToolbar/CustomToolbar.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {6AC69A74-7539-4C2C-BDFD-F436674A7FBD} + WinExe + CustomToolbar + CustomToolbar + v4.6.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE;FRAMEWORK + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE;FRAMEWORK + prompt + 4 + + + + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + \ No newline at end of file diff --git a/Toolbar/CustomToolbar/CustomToolbar.sln b/Toolbar/CustomToolbar/CustomToolbar.sln new file mode 100644 index 0000000..cf96a8e --- /dev/null +++ b/Toolbar/CustomToolbar/CustomToolbar.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomToolbar", "CustomToolbar.csproj", "{BDB4645E-EC1F-6D00-4FE7-2C6AB5166375}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BDB4645E-EC1F-6D00-4FE7-2C6AB5166375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDB4645E-EC1F-6D00-4FE7-2C6AB5166375}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDB4645E-EC1F-6D00-4FE7-2C6AB5166375}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDB4645E-EC1F-6D00-4FE7-2C6AB5166375}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E4AE6383-1A5C-46C2-93BE-A60C75360BC0} + EndGlobalSection +EndGlobal diff --git a/Toolbar/CustomToolbar/CustomToolbar_NET.csproj b/Toolbar/CustomToolbar/CustomToolbar_NET.csproj new file mode 100644 index 0000000..717e54c --- /dev/null +++ b/Toolbar/CustomToolbar/CustomToolbar_NET.csproj @@ -0,0 +1,14 @@ + + + WinExe + net8.0-windows + true + + + + + + + + + diff --git a/Toolbar/CustomToolbar/CustomToolbar_NET.sln b/Toolbar/CustomToolbar/CustomToolbar_NET.sln new file mode 100644 index 0000000..8f7d9f0 --- /dev/null +++ b/Toolbar/CustomToolbar/CustomToolbar_NET.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.226.21692 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomToolbar_NET", "CustomToolbar_NET.csproj", "{A9693914-16B8-4605-BAF9-69C6FFE4ABB0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A9693914-16B8-4605-BAF9-69C6FFE4ABB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9693914-16B8-4605-BAF9-69C6FFE4ABB0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9693914-16B8-4605-BAF9-69C6FFE4ABB0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9693914-16B8-4605-BAF9-69C6FFE4ABB0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CBF28B5B-1546-4921-BF24-226CA1F9ED89} + EndGlobalSection +EndGlobal diff --git a/Toolbar/CustomToolbar/Data/F# Succinctly.pdf b/Toolbar/CustomToolbar/Data/F# Succinctly.pdf new file mode 100644 index 0000000..8773442 Binary files /dev/null and b/Toolbar/CustomToolbar/Data/F# Succinctly.pdf differ diff --git a/Toolbar/CustomToolbar/Data/PdfViewer/Approved.png b/Toolbar/CustomToolbar/Data/PdfViewer/Approved.png new file mode 100644 index 0000000..79d6257 Binary files /dev/null and b/Toolbar/CustomToolbar/Data/PdfViewer/Approved.png differ diff --git a/Toolbar/CustomToolbar/Helper/PdfViewerEventAttachUtil.cs b/Toolbar/CustomToolbar/Helper/PdfViewerEventAttachUtil.cs new file mode 100644 index 0000000..aae45f2 --- /dev/null +++ b/Toolbar/CustomToolbar/Helper/PdfViewerEventAttachUtil.cs @@ -0,0 +1,43 @@ +#region Copyright Syncfusion Inc. 2001-2021. +// Copyright Syncfusion Inc. 2001-2021. 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 System; +using System.Windows; +using System.Windows.Controls; + +namespace syncfusion.pdfviewerdemos.wpf +{ + public class PdfViewerEventAttachUtil + { + public static DependencyProperty WindowLoaded = DependencyProperty.RegisterAttached("WindowLoaded", typeof(bool), typeof(PdfViewerEventAttachUtil), new PropertyMetadata(new PropertyChangedCallback(WindowLoadedChanged))); + + public static void SetWindowLoaded(DependencyObject sender, bool command) + { + sender.SetValue(WindowLoaded, command); + } + /// + /// Retrieves the parent Window from the given Grid and assigns handlers from the ViewModel. + /// + public static void WindowLoadedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + Grid grid = sender as Grid; + if (grid != null) + { + Window view = grid.Parent as Window; + if (view != null) + { + CustomToolbarViewModel viewModel = view.DataContext as CustomToolbarViewModel; + if (viewModel != null) + { + view.Loaded += new RoutedEventHandler(viewModel.Loaded); + view.Closed += new EventHandler(viewModel.Closed); + } + } + } + } + } +} diff --git a/Toolbar/CustomToolbar/MainWindow.xaml b/Toolbar/CustomToolbar/MainWindow.xaml new file mode 100644 index 0000000..573c6cd --- /dev/null +++ b/Toolbar/CustomToolbar/MainWindow.xaml @@ -0,0 +1,591 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + 75 + 100 + 125 + 150 + 200 + 400 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Toolbar/CustomToolbar/MainWindow.xaml.cs b/Toolbar/CustomToolbar/MainWindow.xaml.cs new file mode 100644 index 0000000..4386edd --- /dev/null +++ b/Toolbar/CustomToolbar/MainWindow.xaml.cs @@ -0,0 +1,26 @@ +#region Copyright Syncfusion Inc. 2001 - 2015 +// Copyright Syncfusion Inc. 2001 - 2015. 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.SfSkinManager; +using Syncfusion.Windows.Tools.Controls; +using System.Windows; + +namespace syncfusion.pdfviewerdemos.wpf +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class CustomToolBar : RibbonWindow + { + public CustomToolBar() + { + SfSkinManager.SetTheme(this, new Theme() { ThemeName = "Office2019Colorful" }); + InitializeComponent(); + } + + } +} \ No newline at end of file diff --git a/Toolbar/CustomToolbar/Properties/AssemblyInfo.cs b/Toolbar/CustomToolbar/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dbab445 --- /dev/null +++ b/Toolbar/CustomToolbar/Properties/AssemblyInfo.cs @@ -0,0 +1,57 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +//[assembly: AssemblyTitle("CustomToolBar")] +//[assembly: AssemblyDescription("")] +//[assembly: AssemblyConfiguration("")] +//[assembly: AssemblyCompany("")] +//[assembly: AssemblyProduct("CustomToolBar")] +//[assembly: AssemblyCopyright("Copyright © 2021")] +//[assembly: AssemblyTrademark("")] +//[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyVersion("1.0.0.0")] +//[assembly: AssemblyFileVersion("1.0.0.0")] + + diff --git a/Toolbar/CustomToolbar/Properties/Resources.Designer.cs b/Toolbar/CustomToolbar/Properties/Resources.Designer.cs new file mode 100644 index 0000000..11087ab --- /dev/null +++ b/Toolbar/CustomToolbar/Properties/Resources.Designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace CustomToolBar.Properties +{ + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CustomToolBar.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Toolbar/CustomToolbar/Properties/Resources.resx b/Toolbar/CustomToolbar/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Toolbar/CustomToolbar/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Toolbar/CustomToolbar/Properties/Settings.Designer.cs b/Toolbar/CustomToolbar/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3e1ae99 --- /dev/null +++ b/Toolbar/CustomToolbar/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CustomToolbar_NET.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Toolbar/CustomToolbar/Properties/Settings.settings b/Toolbar/CustomToolbar/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/Toolbar/CustomToolbar/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Toolbar/CustomToolbar/ViewModel/ViewModel.cs b/Toolbar/CustomToolbar/ViewModel/ViewModel.cs new file mode 100644 index 0000000..cdaede5 --- /dev/null +++ b/Toolbar/CustomToolbar/ViewModel/ViewModel.cs @@ -0,0 +1,653 @@ +#region Copyright Syncfusion Inc. 2001-2021. +// Copyright Syncfusion Inc. 2001-2021. 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 Microsoft.Win32; +using Syncfusion.Pdf.Parsing; +using Syncfusion.Windows.PdfViewer; +using Syncfusion.Windows.Shared; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Ribbon; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; + + +namespace syncfusion.pdfviewerdemos.wpf +{ + /// + /// Represents the view model class + /// + public class CustomToolbarViewModel : NotificationObject + { + #region Private Members + private String m_filePath; + private RibbonButton m_customStampButton = null; + private List m_imageList = new List(); + CustomToolBar m_customToolbarWindow = null; + private string m_fileName; + private string m_selectedItem; + private int[] zoomLevels = { 50, 75, 100, 125, 150, 200, 400 }; + #endregion + + #region Constructor + /// + /// Initializes a new instance of the class. + /// + public CustomToolbarViewModel() + { +#if FRAMEWORK + m_filePath = "../../Data/F# Succinctly.pdf"; +#else + m_filePath = "../../../Data/F# Succinctly.pdf"; +#endif + } + /// + /// Opens and returns a file stream for the specified file from the Data directory, + /// + /// The name of the file to open. + /// A FileStream for the specified file. + + private Stream GetFileStream(string fileName) + { +#if FRAMEWORK + FileStream stream = new FileStream("../../Data/" + fileName, FileMode.Open); +#else + FileStream stream = new FileStream("../../../Data/" + fileName, FileMode.Open); +#endif + return stream; + } + +#endregion + + #region Properties + + /// + /// Gets or sets the file path. + /// + public String FilePath + { + get + { + return m_filePath; + } + set + { + m_filePath = value; + } + } + /// + /// Gets or sets the Zoom combo box selected item. + /// + public string SelectedItem + { + get + { + return m_selectedItem; + } + set + { + if (m_selectedItem != value) + { + m_selectedItem = value; + RaisePropertyChanged("SelectedItem"); + OnItemSelect(m_selectedItem); + } + } + } + #endregion + + /// + /// Loads PDF on load and initializes controls in custom toolbar. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + public void Loaded(object sender, RoutedEventArgs e) + { + m_customToolbarWindow = (sender as CustomToolBar).FindName("ribbonwindow") as CustomToolBar; + m_customToolbarWindow.Btnopen.Click += new RoutedEventHandler(BtnOpen_Click); + UnWireEvents(); + WireUpEvents(); + InitializeStamp(); + if (m_customToolbarWindow.MyRibbon.BackStageButton != null) + m_customToolbarWindow.MyRibbon.BackStageButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.file_tab.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Navigation.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Zoom.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Size.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.find_text.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Stamp.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.pdfviewer.CurrentPageChanged += pdfviewer1_CurrentPageChanged; + + if (m_customToolbarWindow.pdfviewer.LoadedDocument == null) + { + m_customToolbarWindow.txtCurrentPageIndex.Text = "0"; + m_customToolbarWindow.FitWidth.IsEnabled = false; + m_customToolbarWindow.FitPage.IsEnabled = false; + m_customToolbarWindow.Last.IsEnabled = false; + m_customToolbarWindow.First.IsEnabled = false; + m_customToolbarWindow.Previous.IsEnabled = false; + m_customToolbarWindow.Next.IsEnabled = false; + m_customToolbarWindow.Save.IsEnabled = false; + m_customToolbarWindow.Print1.IsEnabled = false; + m_customToolbarWindow.ZoomIn.IsEnabled = false; + m_customToolbarWindow.ZoomOut.IsEnabled = false; + m_customToolbarWindow.txtCurrentPageIndex.IsEnabled = false; + m_customToolbarWindow.ZoomComboBox.IsEnabled = false; + m_customToolbarWindow.FindText.IsEnabled = false; + m_customToolbarWindow.pageSeparator.IsEnabled = false; + m_customToolbarWindow.lblTotalPageCount.IsEnabled = false; + m_customToolbarWindow.ZoomPercentage.IsEnabled = false; + m_customToolbarWindow.Stamps.IsEnabled = false; + } + else + { + m_customToolbarWindow.lblTotalPageCount.Text = m_customToolbarWindow.pdfviewer.PageCount.ToString(); + m_customToolbarWindow.ZoomComboBox.SelectedIndex = 2; + } + } + /// + /// Handles cleanup operations when the custom toolbar window is closed. + /// + /// The button that triggered the event. + /// Event data for the EventArgs. + public void Closed(object sender, EventArgs e) + { + m_customToolbarWindow.CustomStampContextMenu.PreviewMouseDown -= M_customStampMenu_PreviewMouseDown; + m_customToolbarWindow.BrowseStamp.Click -= CustomStampBrowse_Click; + UnWireEvents(); + m_customToolbarWindow.pdfviewer.ShowToolbar = true; + m_customToolbarWindow.pdfviewer.Unload(true); + } + + /// + /// Occurs when the window size changed. + /// + /// The button that triggered the event. + /// Event data for the SizeChangedEventArgs. + public void Window_SizeChanged(object sender, SizeChangedEventArgs e) + { + if (m_customToolbarWindow != null) + { + m_customToolbarWindow.MyRibbon.BackStageButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.file_tab.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Navigation.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Zoom.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Size.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.find_text.LauncherButton.Visibility = Visibility.Collapsed; + m_customToolbarWindow.Stamp.LauncherButton.Visibility = Visibility.Collapsed; + } + } + /// + /// Handles the open file dialog to load a PDF document into the viewer. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void BtnOpen_Click(object sender, RoutedEventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Filter = "Pdf Files (.pdf)|*.pdf"; + dialog.ShowDialog(); + if (!string.IsNullOrEmpty(dialog.FileName)) + { + LoadDocument(dialog.FileName); + m_customToolbarWindow.txtCurrentPageIndex.Text = "1"; + m_customToolbarWindow.ribbonwindow.Title = dialog.SafeFileName; + m_customToolbarWindow.ZoomComboBox.SelectedIndex = 2; + m_customToolbarWindow.FitWidth.IsEnabled = true; + m_customToolbarWindow.IsEnabled = true; + m_customToolbarWindow.Last.IsEnabled = true; + m_customToolbarWindow.First.IsEnabled = true; + m_customToolbarWindow.Previous.IsEnabled = true; + m_customToolbarWindow.Next.IsEnabled = true; + m_customToolbarWindow.Save.IsEnabled = true; + m_customToolbarWindow.Print1.IsEnabled = true; + m_customToolbarWindow.ZoomIn.IsEnabled = true; + m_customToolbarWindow.ZoomOut.IsEnabled = true; + m_customToolbarWindow.txtCurrentPageIndex.IsEnabled = true; + m_customToolbarWindow.ZoomComboBox.IsEnabled = true; + m_customToolbarWindow.FindText.IsEnabled = true; + m_customToolbarWindow.pageSeparator.IsEnabled = true; + m_customToolbarWindow.lblTotalPageCount.IsEnabled = true; + m_customToolbarWindow.ZoomPercentage.IsEnabled = true; + m_customToolbarWindow.Stamps.IsEnabled = true; + } + m_customToolbarWindow.pdfviewer.CurrentPageChanged += pdfviewer1_CurrentPageChanged; + } + /// + /// Saves the loaded PDF document to a user-selected location. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void Save_Click(object sender, RoutedEventArgs e) + { + if (m_customToolbarWindow.pdfviewer.LoadedDocument != null) + { + PdfLoadedDocument ldoc = m_customToolbarWindow.pdfviewer.LoadedDocument; + SaveFileDialog save = new SaveFileDialog(); + save.Filter = "PDF Files (*.pdf)|*.pdf"; + save.FileName = m_fileName; + if (save.ShowDialog() == true) + { + FileInfo saveFi = new FileInfo(save.FileName); + if (save.FileName != string.Empty) + { + + m_customToolbarWindow.pdfviewer.LoadedDocument.Save(save.FileName); + MessageBox.Show("File saved succesfully"); + } + } + } + } + /// + /// Adjusts the PDF viewer zoom level based on the selected zoom percentage + /// + /// The selected zoom level from the dropdown. + private void OnItemSelect(string selectedItem) + { + if (selectedItem != null) + { + string[] zoomPercentage = selectedItem.ToString().Split(':'); + if (zoomPercentage.Length > 1) + { + string zoomValue = zoomPercentage[1].Trim(); + if (!string.IsNullOrEmpty(zoomValue) && m_customToolbarWindow.ZoomComboBox.IsDropDownOpen) + { + m_customToolbarWindow.pdfviewer.ZoomTo(int.Parse(zoomValue)); + m_customToolbarWindow.ZoomComboBox.Text = m_customToolbarWindow.pdfviewer.ZoomPercentage.ToString(); + m_customToolbarWindow.FitWidth.IsEnabled = true; + m_customToolbarWindow.FitPage.IsEnabled = true; + m_customToolbarWindow.ZoomOut.IsEnabled = true; + m_customToolbarWindow.ZoomIn.IsEnabled = true; + } + if (zoomValue.Equals(zoomLevels[0].ToString())) + { + m_customToolbarWindow.ZoomOut.IsEnabled = false; + m_customToolbarWindow.ZoomIn.IsEnabled = true; + } + if (zoomValue.Equals(zoomLevels[6].ToString())) + { + m_customToolbarWindow.ZoomOut.IsEnabled = true; + m_customToolbarWindow.ZoomIn.IsEnabled = false; + } + } + } + } + + /// + /// Sets the PDF viewer zoom mode to Fit Page and updates the toolbar controls accordingly. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void FitPage_Click(object sender, RoutedEventArgs e) + { + if (m_customToolbarWindow.pdfviewer.LoadedDocument != null) + { + m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.FitPage; + m_customToolbarWindow.ZoomComboBox.Text= m_customToolbarWindow.pdfviewer.ZoomPercentage.ToString(); + m_customToolbarWindow.ZoomIn.IsEnabled = true; + if(m_customToolbarWindow.pdfviewer.ZoomPercentage <= m_customToolbarWindow.pdfviewer.MinimumZoomPercentage) + m_customToolbarWindow.ZoomOut.IsEnabled = false; + m_customToolbarWindow.FitWidth.IsEnabled = true; + m_customToolbarWindow.FitPage.IsEnabled = false; + } + } + /// + /// Sets the PDF viewer zoom mode to Fit Width and updates the toolbar controls accordingly. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void FitWidth_Click(object sender, RoutedEventArgs e) + { + if (m_customToolbarWindow.pdfviewer.LoadedDocument != null) + { + m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.FitWidth; + m_customToolbarWindow.ZoomComboBox.Text = m_customToolbarWindow.pdfviewer.ZoomPercentage.ToString(); + m_customToolbarWindow.ZoomIn.IsEnabled = true; + m_customToolbarWindow.ZoomOut.IsEnabled = true; + if(m_customToolbarWindow.pdfviewer.ZoomPercentage >= m_customToolbarWindow.pdfviewer.MaximumZoomPercentage) + m_customToolbarWindow.ZoomIn.IsEnabled = false; + m_customToolbarWindow.FitWidth.IsEnabled = false; + m_customToolbarWindow.FitPage.IsEnabled = true; + } + } + /// + /// Increases the zoom level of the PDF viewer to the next predefined zoom level + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + + private void ZoomIn_Click(object sender, RoutedEventArgs e) + { + if (m_customToolbarWindow.pdfviewer.LoadedDocument != null) + { + int currentZoom = m_customToolbarWindow.pdfviewer.ZoomPercentage; + int nextZoom = -1; + int currentIndex = Array.IndexOf(zoomLevels, currentZoom); + if (currentIndex != -1) + { + if (currentIndex + 1 < zoomLevels.Length) + { + nextZoom = zoomLevels[currentIndex + 1]; + } + } + else + { + for (int i = 0; i < zoomLevels.Length; i++) + { + if (currentZoom < zoomLevels[i]) + { + nextZoom = zoomLevels[i]; + break; + } + } + } + if(nextZoom != -1) + { + m_customToolbarWindow.pdfviewer.ZoomTo(nextZoom); + m_customToolbarWindow.ZoomComboBox.Text = nextZoom.ToString(); + m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.Default; + m_customToolbarWindow.FitWidth.IsEnabled = true; + m_customToolbarWindow.FitPage.IsEnabled = true; + if (currentZoom >= m_customToolbarWindow.pdfviewer.MinimumZoomPercentage) + m_customToolbarWindow.ZoomOut.IsEnabled = true; + } + } + } + /// + /// Decreases the zoom level of the PDF viewer to the previous predefined zoom level + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void ZoomOut_Click(object sender, RoutedEventArgs e) + { + if (m_customToolbarWindow.pdfviewer.LoadedDocument != null) + { + int currentZoom = m_customToolbarWindow.pdfviewer.ZoomPercentage; + int nextZoom = -1; + int currentIndex = Array.IndexOf(zoomLevels, currentZoom); + if (currentIndex != -1) + { + if (currentIndex - 1 >= 0) + { + nextZoom = zoomLevels[currentIndex - 1]; + } + } + else + { + for (int i = zoomLevels.Length - 1; i >= 0; i--) + { + if (currentZoom > zoomLevels[i]) + { + nextZoom = zoomLevels[i]; + break; + } + } + + } + if (nextZoom != -1) + { + m_customToolbarWindow.pdfviewer.ZoomTo(nextZoom); + m_customToolbarWindow.ZoomComboBox.Text = nextZoom.ToString(); + m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.Default; + m_customToolbarWindow.FitWidth.IsEnabled = true; + if (currentZoom <= m_customToolbarWindow.pdfviewer.MaximumZoomPercentage) + m_customToolbarWindow.ZoomIn.IsEnabled = true; + } + } + } + /// + /// Opens the text search bar in the PDF viewer. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void FindText_Click(object sender, RoutedEventArgs e) + { + m_customToolbarWindow.pdfviewer.ShowTextSearchBar(); + } + /// + /// Opens the context menu for custom stamps in the PDF viewer. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + + private void CustomStamps_Click(object sender, RoutedEventArgs e) + { + m_customStampButton = sender as RibbonButton; + m_customStampButton.ContextMenu.IsOpen = true; + } + /// + /// Allows users to select and add image files as custom stamps in the PDF viewer. + /// + /// The button that triggered the event. + /// Event data for the RoutedEventArgs. + private void CustomStampBrowse_Click(object sender, RoutedEventArgs e) + { + OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); + openFileDialog.Multiselect = true; + openFileDialog.Filter = "PNG Files(*.png)|*.png|JPEG Files(*.jpeg)|*.jpeg"; + openFileDialog.Title = "Select Image File"; + if (openFileDialog.ShowDialog().Value) + { + foreach (string m_fileName in openFileDialog.FileNames) + { + string fileType = System.IO.Path.GetExtension(m_fileName); + fileType = fileType.ToLower(); + if (fileType == ".jpeg" || fileType == ".png") + { + if (m_customStampButton != null && m_customStampButton.ContextMenu != null && m_customToolbarWindow.CustomStampContextMenu != null) + m_customToolbarWindow.CustomStampContextMenu.Items.Add(GetImage(m_fileName)); + } + } + MessageBox.Show("Selected image(s) are added to the custom stamps collection.", "Message", MessageBoxButton.OK, MessageBoxImage.Information); + } + } + /// + /// Creates an Image control from the given file path. + /// + /// File path of the document + private System.Windows.Controls.Image GetImage(string filePath) + { + System.Windows.Controls.Image image = new System.Windows.Controls.Image(); + image.Source = new BitmapImage(new Uri(filePath, UriKind.RelativeOrAbsolute)); + ValidateImage(image); + m_imageList.Add(image); + return image; + } + // + /// Creates an Image control from a file in the specified folder. + /// + /// File path of the document + private Image GetImageFromFolder(string filePath) + { + System.Windows.Controls.Image image = new System.Windows.Controls.Image(); + BitmapImage bitmapImage = new BitmapImage(); + image.Source = bitmapImage; + bitmapImage.BeginInit(); + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.StreamSource = GetFileStream(filePath); + bitmapImage.EndInit(); + ValidateImage(image); + m_imageList.Add(image); + return image; + } + /// + /// Validates and adjusts the size of the given image. + /// + /// The Image control to be validated and resized. + + private void ValidateImage(Image image) + { + image.Margin = new Thickness(5); + if (image.Source.Width > 200f || image.Source.Height > 140f) + { + image.Stretch = Stretch.Fill; + if (image.Source.Width > image.Source.Height) + { + float widthPercentage = 200f / (float)image.Source.Width; + image.Width = image.Source.Width * widthPercentage; + image.Height = image.Source.Height * widthPercentage; + } + else + { + float heightPercentage = 140f / (float)image.Source.Height; + image.Width = image.Source.Width * heightPercentage; + image.Height = image.Source.Height * heightPercentage; + } + } + } + /// + /// Handles the selection of a custom stamp image. + /// + /// The source of the event (custom stamp menu). + /// Mouse button event arguments. + + private void M_customStampMenu_PreviewMouseDown(object sender, MouseButtonEventArgs e) + { + System.Windows.Controls.Image image = e.OriginalSource as System.Windows.Controls.Image; + if (m_customToolbarWindow.pdfviewer != null && image != null) + { + m_customToolbarWindow.pdfviewer.AnnotationMode = PdfDocumentView.PdfViewerAnnotationMode.Stamp; + if (m_customToolbarWindow.pdfviewer.ToolbarSettings != null && m_customToolbarWindow.pdfviewer.ToolbarSettings.StampAnnotations != null) + { + m_customToolbarWindow.pdfviewer.ToolbarSettings.StampAnnotations.Clear(); + System.Windows.Controls.Image selectedImage = new System.Windows.Controls.Image(); + selectedImage.Source = image.Source; + if (selectedImage.Source.Width > selectedImage.Source.Height) + { + float widthPercentage = 200f / (float)selectedImage.Source.Width; + selectedImage.Width = selectedImage.Source.Width * widthPercentage; + selectedImage.Height = selectedImage.Source.Height * widthPercentage; + } + else + { + float heightPercentage = 50f / (float)selectedImage.Source.Height; + selectedImage.Width = selectedImage.Source.Width * heightPercentage; + selectedImage.Height = selectedImage.Source.Height * heightPercentage; + } + if (selectedImage != null && selectedImage.Source != null) + m_customToolbarWindow.pdfviewer.ToolbarSettings.StampAnnotations.Add(new PdfStampAnnotation(selectedImage)); + } + } + } + /// + /// Initializes custom stamp functionality by wiring event handlers for stamp selection + /// + private void InitializeStamp() + { + m_customToolbarWindow.CustomStampContextMenu.PreviewMouseDown += M_customStampMenu_PreviewMouseDown; + m_customToolbarWindow.BrowseStamp.Click += CustomStampBrowse_Click; + m_customToolbarWindow.CustomStampContextMenu.Items.Add(GetImageFromFolder("pdfviewer/Approved.png")); + } + /// + /// Loads the specified PDF document into the viewer and updates the total page count label. + /// + /// The name of the file to open. + private void LoadDocument(string fileName) + { + FileInfo info = new FileInfo(fileName); + this.m_fileName = info.Name; + m_customToolbarWindow.pdfviewer.Load(fileName); + m_customToolbarWindow.lblTotalPageCount.Text = m_customToolbarWindow.pdfviewer.PageCount.ToString(); + } + /// + /// Updates the current page index display and enables or disables navigation buttons + /// + /// The button that triggered the event. + /// Event data for the EventArgs. + private void pdfviewer1_CurrentPageChanged(object sender, EventArgs args) + { + m_customToolbarWindow.txtCurrentPageIndex.Text = m_customToolbarWindow.pdfviewer.CurrentPageIndex.ToString(); + if (m_customToolbarWindow.pdfviewer.CurrentPage == 1) + { + m_customToolbarWindow.First.IsEnabled = false; + m_customToolbarWindow.Previous.IsEnabled = false; + } + else + { + m_customToolbarWindow.First.IsEnabled = true; + m_customToolbarWindow.Previous.IsEnabled = true; + } + if (m_customToolbarWindow.pdfviewer.CurrentPage == m_customToolbarWindow.pdfviewer.LoadedDocument.Pages.Count) + { + m_customToolbarWindow.Last.IsEnabled = false; + m_customToolbarWindow.Next.IsEnabled = false; + } + else + { + m_customToolbarWindow.Last.IsEnabled = true; + m_customToolbarWindow.Next.IsEnabled = true; + } + } + /// + /// Handles the Enter key press in the ZoomComboBox to set the PDF viewer zoom level. + /// + /// The button that triggered the event. + /// Event data for the KeyEventArgs. + private void ZoomComboBox_KeyDown(object sender, KeyEventArgs e) + { + ComboBox zoomBox = sender as ComboBox; + if (e.Key == Key.Enter) + { + string zoomEntered = zoomBox.Text; + int magnificationValue; + int.TryParse(zoomEntered, out magnificationValue); + if (magnificationValue != 0) + { + int minimumZoomPercentage = m_customToolbarWindow.pdfviewer.MinimumZoomPercentage; + int maximumZoomPercentage = m_customToolbarWindow.pdfviewer.MaximumZoomPercentage; + + if (magnificationValue < minimumZoomPercentage) + magnificationValue = minimumZoomPercentage; + if (magnificationValue > maximumZoomPercentage) + magnificationValue = maximumZoomPercentage; + if (magnificationValue > minimumZoomPercentage && !m_customToolbarWindow.ZoomOut.IsEnabled) + m_customToolbarWindow.ZoomOut.IsEnabled = true; + if (magnificationValue < maximumZoomPercentage && !m_customToolbarWindow.ZoomIn.IsEnabled) + m_customToolbarWindow.ZoomIn.IsEnabled = true; + m_customToolbarWindow.FitWidth.IsEnabled = true; + m_customToolbarWindow.FitPage.IsEnabled = true; + + m_customToolbarWindow.pdfviewer.ZoomMode = Syncfusion.Windows.PdfViewer.ZoomMode.Default; + m_customToolbarWindow.pdfviewer.ZoomTo(magnificationValue); + m_customToolbarWindow.ZoomComboBox.Text = magnificationValue.ToString(); + } + } + } + /// + /// Wires up event handlers for various UI elements in the custom toolbar, + /// + private void WireUpEvents() + { + m_customToolbarWindow.Save.Click += new RoutedEventHandler(Save_Click); + m_customToolbarWindow.FitPage.Click += new RoutedEventHandler(FitPage_Click); + m_customToolbarWindow.FitWidth.Click += new RoutedEventHandler(FitWidth_Click); + m_customToolbarWindow.FindText.Click += new RoutedEventHandler(FindText_Click); + m_customToolbarWindow.Stamps.Click += new RoutedEventHandler(CustomStamps_Click); + m_customToolbarWindow.ZoomIn.Click += new RoutedEventHandler(ZoomIn_Click); + m_customToolbarWindow.ZoomOut.Click += new RoutedEventHandler(ZoomOut_Click); + m_customToolbarWindow.ZoomComboBox.KeyDown += new KeyEventHandler(ZoomComboBox_KeyDown); + } + + /// + /// UnWire the event handlers from various UI elements in the custom toolbar + /// + private void UnWireEvents() + { + m_customToolbarWindow.Save.Click -= new RoutedEventHandler(Save_Click); + m_customToolbarWindow.FitPage.Click -= new RoutedEventHandler(FitPage_Click); + m_customToolbarWindow.FitWidth.Click -= new RoutedEventHandler(FitWidth_Click); + m_customToolbarWindow.Stamps.Click -= new RoutedEventHandler(CustomStamps_Click); + m_customToolbarWindow.ZoomIn.Click -= new RoutedEventHandler(ZoomIn_Click); + m_customToolbarWindow.ZoomOut.Click -= new RoutedEventHandler(ZoomOut_Click); + m_customToolbarWindow.ZoomComboBox.KeyDown -= new KeyEventHandler(ZoomComboBox_KeyDown); + } + } +}