Browse Source

compdfkit(win) - 初步设计注释、Form整合方案

weixiangjie 1 year ago
parent
commit
f17efa5088

+ 0 - 1
Demo/Examples/AnnotationViewControl/packages.config

@@ -1,5 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="ComPDFKit.NetFramework" version="1.9.0" targetFramework="net461" />
-  <package id="PresentationFramework.Aero2" version="1.0.1" targetFramework="net461" />
 </packages>

+ 6 - 0
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -654,5 +654,11 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
         #endregion
+        
+        public void ClearViewerControl()
+        {
+            PDFGrid.Child = null;
+            BotaContainer.Child = null;
+        }
     }
 }

+ 5 - 0
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -268,5 +268,10 @@ namespace Compdfkit_Tools.PDFControl
             newPDFViewer.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
 
+        public void ClearViewerControl()
+        {
+            PDFGrid.Child = null;
+            BotaContainer.Child = null;
+        }
     }
 }

+ 47 - 2
Demo/Examples/PDFViewer_new/App.xaml.cs

@@ -3,15 +3,60 @@ using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
 using System.Linq;
+using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Xml;
+using ComPDFKit.NativeMethod;
 
 namespace PDFViewer_new
 {
+    public class SDKLicenseHelper
+    {
+        public string key = string.Empty;
+        public string secret = string.Empty;
+        public SDKLicenseHelper()
+        {
+
+            string sdkLicensePath = "license_key_win.xml";
+            Assembly assembly = Assembly.GetExecutingAssembly();
+            XmlDocument xmlDocument = new XmlDocument();
+            xmlDocument.Load(sdkLicensePath);
+            var node = xmlDocument.SelectSingleNode("License");
+            if (node != null)
+            {
+                key = node.Attributes["key"].Value;
+                secret = node.Attributes["secret"].Value;
+            }
+        }
+
+    }
+    
     /// <summary>
-    /// App.xaml 的交互逻辑
+    /// Interaction logic for App.xaml
     /// </summary>
-    public partial class App : Application
+    public partial class App: Application
     {
+        protected override void OnStartup(StartupEventArgs e)
+        {
+            string str = this.GetType().Assembly.Location;
+            base.OnStartup(e);
+            LicenseVerify();
+        }
+        
+        private static bool LicenseVerify()
+        {
+            bool result = false;
+
+            result = CPDFSDKVerifier.LoadNativeLibrary();
+            if (!result)
+                return false;
+            SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
+
+            LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
+            if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
+                return false;
+            return result;
+        }
     }
 }

+ 103 - 9
Demo/Examples/PDFViewer_new/MainPage.xaml

@@ -7,7 +7,8 @@
               xmlns:cpdftools="clr-namespace:Compdfkit_Tools.PDFControl;assembly=Compdfkit_Tools"
              xmlns:cpdfcommon="clr-namespace:Compdfkit_Tools.Common;assembly=Compdfkit_Tools"
              mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
+             Loaded="MainWindow_Loaded"
+             d:DesignHeight="720" d:DesignWidth="1080">
     <UserControl.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
@@ -29,7 +30,9 @@
                     <ColumnDefinition Width="*"></ColumnDefinition>
                     <ColumnDefinition Width="auto"></ColumnDefinition>
                 </Grid.ColumnDefinitions>
+
                 <StackPanel Orientation="Horizontal" Height="40" Margin="20,0,0,0">
+
                     <Button BorderThickness="0" VerticalContentAlignment="Center" Width="30" Height="30" Style="{StaticResource LightButtonStyle}" Background="Transparent" Click="OpenFile_Click">
                         <Button.Content>
                             <Viewbox Width="20" Height="20">
@@ -90,15 +93,36 @@
                     </ToggleButton>
 
                     <Line Margin="13,0,13,0" Stroke="#E0E0E0" X1="0" Y1="5" X2="0" Y2="35"></Line>
-                    <cpdftools:CPDFScalingControl x:Name="CPDFSaclingControl"></cpdftools:CPDFScalingControl>
 
+                    <ToggleButton BorderThickness="0" Width="30" Height="30" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" IsChecked="True" IsEnabled="False" Visibility="Collapsed">
+                        <ToggleButton.Content>
+                            <Path Fill="#43474D">
+                                <Path.Data>
+                                    M8.7463 7.94055L8.43134 3.20358C8.38986 2.6073 8.82031 2.08322 9.40947 2.01273L9.46546 2.00656C9.75502 1.97416 10.0451 2.06271 10.2681 2.25159C10.4911 
+                                2.44047 10.6276 2.71317 10.6457 3.00614L10.9886 8.17061C10.999 8.31659 11.1097 8.43516 11.2537 8.45444C11.3176 8.46288 11.382 8.44409 11.4315 
+                                8.40258C11.481 8.36108 11.5111 8.30063 11.5145 8.23584L11.7612 3.47595C11.7918 2.85998 12.3116 2.38523 12.923 2.41468H12.9309C13.5429 2.44972 
+                                14.0111 2.97745 13.9773 3.59407L13.7218 8.51438C13.7137 8.66679 13.8235 8.79975 13.9738 8.81936C14.1225 8.83876 14.2625 8.73915 14.2914 
+                                8.59018L14.8006 6.02337C14.9178 5.41517 15.497 5.01851 16.0954 5.13574L16.1041 5.13751C16.7058 5.25854 17.0969 5.84695 16.979 6.45353L16.3684 
+                                9.53687C15.8189 13.3474 15.0586 15.5052 14.3946 16.4246C13.3649 17.8508 11.5573 17.8667 10.1251 17.8667C8.69381 17.8667 7.16012 17.5291 6.44796 
+                                16.9993C5.73492 16.4696 4.77079 15.2575 4.15837 13.9327L4.16712 13.9283C4.11876 13.8639 4.0774 13.7945 4.04376 13.7212L3.105 11.685C2.84552 11.1243 
+                                3.08338 10.4577 3.63781 10.1918L3.64656 10.1874C3.91235 10.0626 4.21656 10.0497 4.49179 10.1517C4.76702 10.2536 4.99055 10.4619 5.11287 10.7304C5.62206 
+                                11.8234 5.94227 12.324 6.07526 12.2324C6.27386 12.0949 6.12075 11.7176 5.85478 9.21249C5.67578 7.53039 5.45319 5.85328 5.18724 4.18289C5.07653 3.5968 
+                                5.44002 3.02581 6.01489 2.88273L6.07526 2.86775C6.35866 2.79957 6.65742 2.85178 6.90147 3.01215C7.14552 3.17252 7.3134 3.42693 7.36572 3.71571L8.168 
+                                8.02341C8.19642 8.17613 8.33897 8.27937 8.49171 8.25787C8.64561 8.23564 8.75656 8.09774 8.7463 7.94143V7.94055Z
+                                </Path.Data>
+                            </Path>
+                        </ToggleButton.Content>
+                    </ToggleButton>
+
+                    <Line Margin="13,0,13,0" Stroke="#E0E0E0" X1="0" Y1="5" X2="0" Y2="35"></Line>
+
+                    <cpdftools:CPDFScalingControl x:Name="CPDFSaclingControl"></cpdftools:CPDFScalingControl>
                 </StackPanel>
-                <ComboBox Name="ModeComboBox" Style="{StaticResource ComboBoxStyle1}" Width="140" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" Tag="Viewer">Viewer</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Annotation">Annotation</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Content Editor">Content Editor</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Forms">Forms</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Docs Editor">Docs Editor</ComboBoxItem>
+
+                <ComboBox Name="ModeComboBox" SelectedIndex="2" Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
+                    <ComboBoxItem Tag="Viewer">Viewer</ComboBoxItem>
+                    <ComboBoxItem Tag="Annotation">Annotation</ComboBoxItem>
+                    <ComboBoxItem IsSelected="True" Tag="Form">Form</ComboBoxItem>
                 </ComboBox>
 
                 <StackPanel Orientation="Horizontal" Grid.Column="2">
@@ -171,8 +195,78 @@
                         </Button.ToolTip>
                     </Button>
                 </StackPanel>
+
+            </Grid>
+            <Grid Name="BodyGrid" Grid.Row="1">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="0"></ColumnDefinition>
+                    <ColumnDefinition Width="0"></ColumnDefinition>
+                    <ColumnDefinition Width="*"></ColumnDefinition>
+                    <ColumnDefinition Width="auto"></ColumnDefinition>
+                </Grid.ColumnDefinitions>
+
+                <GridSplitter  Name="Splitter" Grid.Column="1" Width="15" ResizeBehavior="PreviousAndNext" Visibility="Collapsed">
+                    <GridSplitter.Template>
+                        <ControlTemplate TargetType="{x:Type GridSplitter}">
+                            <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
+                        BorderBrush="{TemplateBinding Border.BorderBrush}"
+                        Background="{TemplateBinding Panel.Background}" >
+                                <Path Fill="Gray" VerticalAlignment="Center">
+                                    <Path.Data>
+                                        M15 3.75H1V2.25H15V3.75ZM15 8.75H1V7.25H15V8.75ZM1 13.75H15V12.25H1V13.75Z
+                                    </Path.Data>
+                                </Path>
+                            </Border>
+                        </ControlTemplate>
+                    </GridSplitter.Template>
+                </GridSplitter>
+
+                <Grid Grid.Column="2" >
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="auto"/>
+                        <RowDefinition Height="*"/>
+                    </Grid.RowDefinitions>
+
+                    <Grid Grid.Row="1">
+                        <Grid.ColumnDefinitions>
+                            <ColumnDefinition></ColumnDefinition>
+                            <ColumnDefinition Width="auto"></ColumnDefinition>
+                        </Grid.ColumnDefinitions>
+                        <Border x:Name="PDFGrid" Background="#CECECE"></Border>
+                    </Grid>
+
+                </Grid>
             </Grid>
-            <Grid Grid.Row="1"></Grid>
         </Grid>
+        <Border Name="PopupBorder" Background="#A0000000" Visibility="Collapsed">
+            <Grid>
+
+                <Grid Name="FileInfoUI"  Width="422" Height="680" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White" Visibility="Collapsed">
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="*"></ColumnDefinition>
+                        <ColumnDefinition Width="*"></ColumnDefinition>
+                    </Grid.ColumnDefinitions>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="auto"></RowDefinition>
+                        <RowDefinition Height="*"></RowDefinition>
+                    </Grid.RowDefinitions>
+
+                    <TextBlock Width="50" Height="20" FontSize="14" LineHeight="16" Margin="12,6,0,0" HorizontalAlignment="Left">FileInfo:</TextBlock>
+                    <Button Grid.Column="1" Width="16" Height="16" HorizontalAlignment="Right" Margin="0,8,8,0" BorderThickness="0" Click="FileInfoCloseBtn_Click">
+                        <Button.Content>
+                            <Path Fill="Black">
+                                <Path.Data>
+                                    M6.69495 6L11.5 1.19495L10.805 0.5L6 5.30505L1.19495 0.5L0.5 1.19495L5.30505 6L0.5 10.805L1.19495 11.5L6 6.69495L10.805 11.5L11.5 10.805L6.69495 6Z
+                                </Path.Data>
+                            </Path>
+                        </Button.Content>
+                    </Button>
+                    <cpdftools:CPDFInfoControl Grid.Row="1" Margin="25,10,25,0" Grid.ColumnSpan="2" Name="FileInfoControl"></cpdftools:CPDFInfoControl>
+                </Grid>
+
+                <cpdfcommon:PasswordDialog x:Name="PasswordUI" Visibility="Collapsed"></cpdfcommon:PasswordDialog>
+            </Grid>
+
+        </Border>
     </Grid>
 </UserControl>

+ 371 - 10
Demo/Examples/PDFViewer_new/MainPage.xaml.cs

@@ -1,10 +1,13 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Input;
@@ -12,57 +15,415 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using Compdfkit_Tools.Helper;
+using Compdfkit_Tools.PDFControl;
+using ComPDFKit.PDFDocument;
+using ComPDFKitViewer;
+using ComPDFKitViewer.PdfViewer;
+using Microsoft.Win32;
 
 namespace PDFViewer_new
 {
-    /// <summary>
-    /// MainPage.xaml 的交互逻辑
-    /// </summary>
-    public partial class MainPage : UserControl
+    public partial class MainPage : UserControl, INotifyPropertyChanged
     {
+        private PDFViewControl pdfViewer;
+        private PDFViewControl passwordViewer;
+        private AnnotationControl annotationControl = new AnnotationControl();
+        private FormControl formControl = new FormControl();
+        private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl();
+
+        private bool _canSave = false;
+        public bool CanSave
+        {
+
+            get => _canSave;
+            set
+            {
+                _canSave = value;
+                OnPropertyChanged();
+            }
+        }
         public MainPage()
         {
             InitializeComponent();
         }
 
-        private void OpenFile_Click(object sender, RoutedEventArgs e)
+                #region Load document
+
+        private void LoadDefaultDocument()
+        {
+            string defaultFilePath = "PDF32000_2008.pdf";
+            pdfViewer.PDFView.InitDocument(defaultFilePath);
+            LoadDocument();
+            PDFGrid.Child = formControl;
+        }
+
+        private void LoadDocument()
+        {
+            pdfViewer.PDFView.Load();
+            pdfViewer.PDFView.SetShowLink(true);
+            
+            pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
+            pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
+
+            pdfViewer.PDFView.SetFormFieldHighlight(true);
+            PasswordUI.Closed -= PasswordUI_Closed;
+            PasswordUI.Canceled -= PasswordUI_Canceled;
+            PasswordUI.Confirmed -= PasswordUI_Confirmed;
+            PasswordUI.Closed += PasswordUI_Closed;
+            PasswordUI.Canceled += PasswordUI_Canceled;
+            PasswordUI.Confirmed += PasswordUI_Confirmed;
+
+            pdfViewer.PDFView.ChangeFitMode(FitMode.FitWidth);
+            CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.PDFView.ZoomFactor * 100)));
+
+            ViewSettingBtn.IsChecked = false;
+            botaBarControl.InitWithPDFViewer(pdfViewer.PDFView);
+            botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
+            botaBarControl.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
+            LoadCustomControl();
+        }
+
+        private void PdfFormControlRefreshAnnotList(object sender, EventArgs e)
+        {
+            botaBarControl.LoadAnnotationList();
+        }
+
+        private void FormControlOnCanSaveChanged(object sender, bool e)
+        {
+           this.CanSave = e;
+        }
+
+        #endregion
+        
+        #region Password
+
+        private void PasswordUI_Confirmed(object sender, string e)
+        {
+            if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
+            {
+                passwordViewer.PDFView.Document.UnlockWithPassword(e);
+                if (passwordViewer.PDFView.Document.IsLocked == false)
+                {
+                    PasswordUI.SetShowError("", Visibility.Collapsed);
+                    PasswordUI.ClearPassword();
+                    PasswordUI.Visibility = Visibility.Collapsed;
+                    PopupBorder.Visibility = Visibility.Collapsed;
+                    pdfViewer = passwordViewer;
+                    LoadDocument();
+                }
+                else
+                {
+                    PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
+                }
+            }
+        }
+
+        private void PasswordUI_Canceled(object sender, EventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+            PasswordUI.Visibility = Visibility.Collapsed;
+        }
+
+        private void PasswordUI_Closed(object sender, EventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+            PasswordUI.Visibility = Visibility.Collapsed;
+        }
+
+        #endregion
+        
+        #region Load Unload custom control
+        private void LoadCustomControl()
+        {
+            formControl.PdfViewControl = pdfViewer;
+            formControl.InitWithPDFViewer(pdfViewer.PDFView);
+            InitialPDFViewControl(formControl.PdfViewControl);
+            formControl.OnCanSaveChanged -= FormControlOnCanSaveChanged;
+            formControl.OnCanSaveChanged += FormControlOnCanSaveChanged;
+            formControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
+            formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
+            formControl.SetBOTAContainer(botaBarControl);
+            formControl.InitialPDFViewControl(formControl.PdfViewControl);
+            
+            annotationControl.PdfViewControl = pdfViewer;
+        }
+        
+        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
+            pdfViewer = new PDFViewControl();
+            LoadDefaultDocument();
+        }
+        #endregion
+        
+        #region Annotation
 
+        public void InitialPDFViewControl(PDFViewControl newPDFViewer)
+        {
+            formControl.ClearAllToolState();
+            formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
         }
+          
+        #endregion
+        
+        #region Event handle
 
+        private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
+        { 
+            if (e.Key == "Zoom")
+            {
+                CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
+            }
+        }
+        
+        
+        
+        #endregion
+        
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
+            SaveFile();
+            pdfViewer.PDFView.UndoManager.CanSave = false;
+        }
+        
+        private void OpenFile()
+        {
+            string filePath = CommonHelper.GetFilePathOrEmpty();
+            if (!string.IsNullOrEmpty(filePath) && formControl.PdfViewControl != null)
+            {
+                if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+                {
+                    string oldFilePath = pdfViewer.PDFView.Document.FilePath;
+                    if (oldFilePath.ToLower() == filePath.ToLower())
+                    {
+                        return;
+                    }
+                }
 
+                passwordViewer = new PDFViewControl();
+                passwordViewer.PDFView.InitDocument(filePath);
+                if (passwordViewer.PDFView.Document == null)
+                {
+                    MessageBox.Show("Open File Failed");
+                    return;
+                }
+
+                if (passwordViewer.PDFView.Document.IsLocked)
+                {
+                    PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
+                    PasswordUI.ClearPassword();
+                    PopupBorder.Visibility = Visibility.Visible;
+                    PasswordUI.Visibility = Visibility.Visible;
+                }
+                else
+                {
+                    pdfViewer = passwordViewer;
+                    LoadDocument();
+                }
+            }
         }
 
-        private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
+        private void OpenFile_Click(object sender, RoutedEventArgs e)
         {
+            OpenFile();
+        }
 
+        private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
+        {
+            ToggleButton expandBtn = sender as ToggleButton;
+            if (expandBtn != null)
+            {
+                bool isExpand = expandBtn.IsChecked == true;
+                formControl.ExpandLeftPanel(isExpand);
+            }
         }
 
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-
+            var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
+            if ((string)item.Content == "Viewer")
+            {
+                formControl.ClearAllToolState();
+                formControl.SetToolBarContainerVisibility(Visibility.Collapsed);
+                formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
+                //formControl.FromPropertyControl.AnnotationCancel();
+                RightPanelButton.IsChecked = false;
+                if (formControl.PdfViewControl != null && formControl.PdfViewControl.PDFView != null)
+                {
+                    formControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
+                }
+            }
+            else if ((string)item.Content == "Annotation")
+            {
+                annotationControl.SetToolBarContainerVisibility(Visibility.Visible);
+                if (annotationControl.PdfViewControl != null && annotationControl.PdfViewControl.PDFView != null)
+                {
+                    formControl.ClearViewerControl();
+                    PDFGrid.Child = annotationControl;
+                    annotationControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
+                    annotationControl.InitWithPDFViewer(pdfViewer.PDFView);
+                    InitialPDFViewControl(annotationControl.PdfViewControl);
+                    annotationControl.OnCanSaveChanged -= FormControlOnCanSaveChanged;
+                    annotationControl.OnCanSaveChanged += FormControlOnCanSaveChanged;
+                    annotationControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
+                    annotationControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
+                    annotationControl.SetBOTAContainer(botaBarControl);
+                    annotationControl.InitialPDFViewControl(annotationControl.PdfViewControl);
+                }
+            }
+            else if ((string)item.Content == "Form")
+            {
+                formControl.SetToolBarContainerVisibility(Visibility.Visible);
+                if (formControl.PdfViewControl != null && formControl.PdfViewControl.PDFView != null)
+                {
+                    annotationControl.ClearViewerControl();
+                    PDFGrid.Child = formControl;
+                    formControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.FormEditTool);
+                    formControl.PdfViewControl = pdfViewer;
+                    formControl.InitWithPDFViewer(pdfViewer.PDFView);
+                    InitialPDFViewControl(formControl.PdfViewControl);
+                    formControl.OnCanSaveChanged -= FormControlOnCanSaveChanged;
+                    formControl.OnCanSaveChanged += FormControlOnCanSaveChanged;
+                    formControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
+                    formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
+                    formControl.SetBOTAContainer(botaBarControl);
+                    formControl.InitialPDFViewControl(formControl.PdfViewControl);
+                }
+            }
         }
 
-        private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
+        private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
         {
+            PasswordUI.Visibility = Visibility.Collapsed;
+            FileInfoUI.Visibility = Visibility.Visible;
+            FileInfoControl.InitWithPDFViewer(pdfViewer.PDFView);
+            PopupBorder.Visibility = Visibility.Visible;
+        }
 
+        private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
+        {
+            ShowViewSettings();
         }
 
+        private void ShowViewSettings()
+        {
+            if (ViewSettingBtn != null)
+            {
+                if (ViewSettingBtn.IsChecked == true)
+                {
+                    CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
+                    displayPanel.InitWithPDFViewer(formControl.PdfViewControl.PDFView);
+                    formControl.SetViewSettings(Visibility.Visible, displayPanel); 
+                    if ((bool)RightPanelButton.IsChecked)
+                    {
+                        RightPanelButton.IsChecked = false;
+                    }
+                }
+                else
+                {
+                    formControl.SetViewSettings(Visibility.Collapsed); 
+                }
+            }
+        }
         private void RightPanelButton_Click(object sender, RoutedEventArgs e)
         {
+            ControlRightPanel();
+        }
 
+        private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
+        {
+            formControl.ExpandLeftPanel(true);
+            botaBarControl.SelectBotaTool(BOTATools.Search);
+        }
+        
+        private void ControlRightPanel()
+        { 
+            if (RightPanelButton != null)
+            {
+                if (RightPanelButton.IsChecked == true)
+                {
+                    if (formControl.FromPropertyControl != null)
+                    {
+                        formControl.ExpandRightPropertyPanel(formControl.FromPropertyControl, Visibility.Visible);
+                        if ((bool)ViewSettingBtn.IsChecked)
+                        {
+                            ViewSettingBtn.IsChecked = false;
+                        }
+                    }
+                }
+                else
+                {
+                    formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
+                }
+            }
         }
 
-        private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
+        #region Save file
+        /// <summary>
+        /// Save the file to another PDF file.
+        /// </summary>
+        public void SaveAsFile()
         {
+            {
+                if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+                {
+                    CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
+                    SaveFileDialog saveDialog = new SaveFileDialog();
+                    saveDialog.Filter = "(*.pdf)|*.pdf";
+                    saveDialog.DefaultExt = ".pdf";
+                    saveDialog.OverwritePrompt = true;
 
+                    if (saveDialog.ShowDialog() == true)
+                    {
+                        pdfDoc.WriteToFilePath(saveDialog.FileName);
+                    }
+                }
+            }
         }
 
-        private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
+        /// <summary>
+        /// Save the file in the current path.
+        /// </summary>
+        private void SaveFile()
         {
+            if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+            {
+                try
+                {
+                    CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
+                    if (pdfDoc.WriteToLoadedPath())
+                    {
+                        return;
+                    }
 
+                    SaveFileDialog saveDialog = new SaveFileDialog();
+                    saveDialog.Filter = "(*.pdf)|*.pdf";
+                    saveDialog.DefaultExt = ".pdf";
+                    saveDialog.OverwritePrompt = true;
+
+                    if (saveDialog.ShowDialog() == true)
+                    {
+                        pdfDoc.WriteToFilePath(saveDialog.FileName);
+                    }
+                }
+                catch (Exception ex)
+                {
+
+                }
+            }
+        }
+        #endregion
+
+        private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+        }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        
+        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
     }
 }

+ 10 - 0
Demo/Examples/PDFViewer_new/PDFViewer_new.csproj

@@ -116,6 +116,16 @@
       <Name>Compdfkit_Tools</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="..\license_key_win.xml">
+      <Link>license_key_win.xml</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+    <Content Include="..\TestFile\PDF32000_2008.pdf">
+      <Link>PDF32000_2008.pdf</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="..\packages\ComPDFKit.NetFramework.1.9.0\build\ComPDFKit.NetFramework.targets" Condition="Exists('..\packages\ComPDFKit.NetFramework.1.9.0\build\ComPDFKit.NetFramework.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">