Browse Source

compdfkit(win) - 预览更新

liuaoran 1 year ago
parent
commit
e9a6117bda

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Common/BarControl/CPDFBOTABarControl.xaml.cs

@@ -117,7 +117,7 @@ namespace Compdfkit_Tools.PDFControl
                 {
                     if (BOTABarTitleGrid.Children[0] is ToggleButton buttonTool)
                     {
-                        SelectBotaTool(botaToolBtnDic.FirstOrDefault(x => x.Value == buttonTool).Key);
+                        //SelectBotaTool(botaToolBtnDic.FirstOrDefault(x => x.Value == buttonTool).Key);
                     }
                 }
                 else

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Common/Convert/WindowStateToThicknessConverter.cs

@@ -18,7 +18,7 @@ namespace Compdfkit_Tools.Common
             else
             {
                 // left, right and bottom borders are still drawn by the system
-                return new Thickness(2);
+                return new Thickness(1);
             }
         }
 

+ 46 - 0
Demo/Examples/Compdfkit_Tools/Common/Helper/CommonHelper.cs

@@ -21,6 +21,7 @@ using ComPDFKit.DigitalSign;
 using ComPDFKit.PDFAnnotation.Form;
 using Point = System.Windows.Point;
 using Size = System.Windows.Size;
+using System.Collections.ObjectModel;
 
 namespace Compdfkit_Tools.Helper
 {
@@ -162,6 +163,51 @@ namespace Compdfkit_Tools.Helper
             return selectedFilePath;
         }
 
+        public static string GetPageParmFromList(List<int> pagesList)
+        {
+            string pageParam = "";
+            if (pagesList.Count != 0)
+            {
+                pagesList.Sort();
+
+                for (int i = 0; i < pagesList.Count; i++)
+                {
+                    if (i == 0)
+                    {
+                        pageParam += pagesList[0].ToString();
+                    }
+                    else
+                    {
+                        if (pagesList[i] == pagesList[i - 1] + 1)
+                        {
+                            if (i >= 2)
+                            {
+                                if (pagesList[i - 1] != pagesList[i - 2] + 1)
+                                    pageParam += "-";
+                            }
+                            else
+                                pageParam += "-";
+
+                            if (i == pagesList.Count - 1)
+                            {
+                                pageParam += pagesList[i].ToString();
+                            }
+                        }
+                        else
+                        {
+                            if (i >= 2)
+                            {
+                                if (pagesList[i - 1] == pagesList[i - 2] + 1)
+                                    pageParam += pagesList[i - 1].ToString();
+                            }
+                            pageParam += "," + pagesList[i].ToString();
+                        }
+                    }
+                }
+            }
+            return pageParam;
+        }
+
         public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
         {
             string[] rangeSplit = pageRange.Split(enumerationSeparator); 

+ 1 - 2
Demo/Examples/Compdfkit_Tools/Common/HomePage/FeaturesListControl.xaml.cs

@@ -188,7 +188,7 @@ namespace Compdfkit_Tools.PDFControl
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
 
         private void ListGd_SizeChanged(object sender, SizeChangedEventArgs e)
-        {
+        {  
             if (FeaturesListBox != null && CustomItem.ItemWidth > 0 && CustomItem.ItemHeight > 0)
             {
                 HorizontalItemNumber = (int)((FeaturesListBox.ActualWidth) / (CustomItem.ItemWidth + 2 * CustomItem.ItemMargin));
@@ -240,7 +240,6 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
 
-
         public event PropertyChangedEventHandler PropertyChanged;
         protected void UpdateProper<T>(ref T properValue,
                             T newValue,

+ 8 - 5
Demo/Examples/Compdfkit_Tools/DigitalSignature/CPDFSignatureListControl/CPDFSignatureListControl.xaml.cs

@@ -83,11 +83,14 @@ namespace Compdfkit_Tools.DigitalSignature.CPDFSignatureListControl
             if (index >= 0 && index < signatureList.Count)
             {
                 var widget = signatureList[index].GetSignatureWidget(pdfViewer.Document);
-                pdfViewer.Document.RemoveSignature(signatureList[index], true);
-                widget.ResetForm();
-                widget.SetIsLocked(false);
-                pdfViewer.ReloadVisibleAnnots();
-                DeleteSignatureEvent?.Invoke(this, null);
+                if (widget != null)
+                {
+                    pdfViewer.Document.RemoveSignature(signatureList[index], true);
+                    widget.ResetForm();
+                    widget.SetIsLocked(false);
+                    pdfViewer.ReloadVisibleAnnots();
+                    DeleteSignatureEvent?.Invoke(this, null);
+                }
             }
         }
         

+ 55 - 22
Demo/Examples/Compdfkit_Tools/Security/Watermark/FileGridListWithPageRangeControl.xaml.cs

@@ -24,9 +24,44 @@ using DataGridCell = System.Windows.Controls.DataGridCell;
 using UserControl = System.Windows.Controls.UserControl;
 
 namespace Compdfkit_Tools.PDFControl
-{
+{ 
+    public class FileInfoWithRange : INotifyPropertyChanged
+    {
+        public CPDFDocument Document;
+        public string Name { get; set; }
+        public string Path { get; set; }
 
+        private string _pageRange;
+        public string PageRange { get => _pageRange; set => UpdateProper(ref _pageRange, value); }
+        public string Size { get; set; }
 
+        private List<int> _pageRangeList = new List<int>();
+        public List<int> PageRangeList
+        {
+            get => _pageRangeList;
+            set
+            {
+                _pageRangeList = value;
+                PageRange = CommonHelper.GetPageParmFromList(PageRangeList);
+            }
+        }
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected virtual void OnPropertyChanged(string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+        protected bool UpdateProper<T>(ref T properValue,
+    T newValue,
+    [CallerMemberName] string properName = "")
+        {
+            if (object.Equals(properValue, newValue))
+                return false;
+
+            properValue = newValue;
+            OnPropertyChanged(properName);
+            return true;
+        }
+    }
 
     /// <summary>
     /// Interaction logic for FileGridListWithPageRangeControl.xaml
@@ -45,14 +80,7 @@ namespace Compdfkit_Tools.PDFControl
                 SetValue(IsEnsureProperty, value);
             }
         }
-        public class FileInfo
-        {
-            public CPDFDocument Document;
-            public string Name { get; set; }
-            public string Path { get; set; }
-            public string PageRange { get; set; }
-            public string Size { get; set; }
-        }
+
 
         private int _fileNumText;
         public int FileNumText
@@ -66,8 +94,8 @@ namespace Compdfkit_Tools.PDFControl
         }
 
 
-        private ObservableCollection<FileInfo> _fileInfoDataList;
-        public ObservableCollection<FileInfo> FileInfoDataList
+        private ObservableCollection<FileInfoWithRange> _fileInfoDataList;
+        public ObservableCollection<FileInfoWithRange> FileInfoDataList
         {
             get { return _fileInfoDataList; }
             set
@@ -124,27 +152,27 @@ namespace Compdfkit_Tools.PDFControl
                         {
                             document.Release();
                             continue;
-                        }
+                        } 
+                    }
 
+                    List<int> pageRangeList = new List<int>();
+                    for (int i = 0; i < document.PageCount; i++)
+                    {
+                        pageRangeList.Add(i + 1);
                     }
 
-                    FileInfoDataList.Add(new FileInfo
+                    FileInfoDataList.Add(new FileInfoWithRange
                     {
                         Document = document,
                         Name = document.FileName,
                         Size = CommonHelper.GetFileSize(filePath),
                         Path = document.FilePath,
-                        PageRange = "1-"+document.PageCount.ToString(),
+                        PageRangeList = pageRangeList
                     });
                 }
             }
         }
 
-        private void PasswordWindow_DialogClosed(object sender, PasswordEventArgs e)
-        {
-            throw new NotImplementedException();
-        }
-
         private void RemoveBtn_Click(object sender, RoutedEventArgs e)
         {
 
@@ -153,12 +181,18 @@ namespace Compdfkit_Tools.PDFControl
         private void PageRangeBtn_Click(object sender, RoutedEventArgs e)
         {
             PageRangeDialog pageRangeDialog = new PageRangeDialog();
+            if (FileDataGrid.SelectedItems[0] is FileInfoWithRange fileInfo)
+            {
+                pageRangeDialog.InitWithFileInfo(fileInfo);
+            }
+
+            pageRangeDialog.Owner = Window.GetWindow(this);
             pageRangeDialog.ShowDialog();
         }
 
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
-            FileInfoDataList = new ObservableCollection<FileInfo>();
+            FileInfoDataList = new ObservableCollection<FileInfoWithRange>();
             FileDataGrid.ItemsSource = FileInfoDataList;
         }
 
@@ -168,9 +202,8 @@ namespace Compdfkit_Tools.PDFControl
             if (dataGrid != null)
             {
                 RemoveBtn.Content = dataGrid.SelectedItems.Count > 0 ? "Remove" : "Remove All";
-                PageRangeBtn.Visibility = dataGrid.SelectedItems.Count == 1? Visibility.Visible : Visibility.Collapsed;
+                PageRangeBtn.Visibility = dataGrid.SelectedItems.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
             }
-
         }
 
         private void FileDataGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

+ 10 - 45
Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml

@@ -1,4 +1,4 @@
-<Window x:Class="Compdfkit_Tools.PDFControl.PageRangeDialog"
+<Window x:Class="Compdfkit_Tools.PDFControl.PageRangeDialog" 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -6,47 +6,12 @@
         xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
         mc:Ignorable="d"
         ResizeMode="NoResize"
-        Title="Settings" Height="580" Width="704">
+        Title="Settings" Height="580" Width="704" Loaded="Window_Loaded">
     <Window.Resources>
         <ResourceDictionary>
-            <Style x:Key="CommonRadioButtonStyle" TargetType="{x:Type RadioButton}">
-                <Setter Property="Template">
-                    <Setter.Value>
-                        <ControlTemplate TargetType="{x:Type RadioButton}">
-                            <Grid HorizontalAlignment="Left">
-                                <Grid.ColumnDefinitions>
-                                    <ColumnDefinition Width="32"></ColumnDefinition>
-                                    <ColumnDefinition></ColumnDefinition>
-                                </Grid.ColumnDefinitions>
-                                <Grid>
-                                    <Ellipse x:Name="radioEllipse"
-                                         Width="20"
-                                         Height="20"
-                                         Fill="White"
-                                         Stroke="{TemplateBinding BorderBrush}"
-                                         StrokeThickness="1"/>
-                                    <Ellipse x:Name="innerEllipse"
-                                         Width="14"
-                                         Height="14"
-                                         Fill="Black"
-                                         Opacity="0"/>
-                                </Grid>
-                                <Grid x:Name="textGd"  Grid.Column="1">
-                                    <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
-                                </Grid>
-                            </Grid>
-                            <ControlTemplate.Triggers>
-                                <Trigger Property="IsChecked" Value="True">
-                                    <Setter TargetName="innerEllipse" Property="Opacity" Value="1"></Setter>
-                                </Trigger>
-                                <Trigger Property="IsMouseOver" Value="True">
-                                    <Setter TargetName="radioEllipse" Property="Stroke" Value="DodgerBlue"></Setter>
-                                </Trigger>
-                            </ControlTemplate.Triggers>
-                        </ControlTemplate>
-                    </Setter.Value>
-                </Setter>
-            </Style>
+            <ResourceDictionary.MergedDictionaries>
+                <ResourceDictionary Source="../../Asset/Styles/RadioButtonStyle.xaml"></ResourceDictionary>
+            </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Window.Resources>
     <Grid Margin="24">
@@ -59,7 +24,7 @@
             <ColumnDefinition></ColumnDefinition>
         </Grid.ColumnDefinitions>
         <Grid>
-            <local:PreviewControl></local:PreviewControl>
+            <local:PreviewControl x:Name="PreviewControl"></local:PreviewControl>
         </Grid>
         <Grid Grid.Column="1">
             <Border BorderThickness="1" BorderBrush="#33000000" Margin="10,10,0,0" Height="190" VerticalAlignment="Top">
@@ -70,16 +35,16 @@
                         <RowDefinition></RowDefinition>
                         <RowDefinition></RowDefinition>
                     </Grid.RowDefinitions>
-                    <RadioButton Style="{StaticResource CommonRadioButtonStyle}" Margin="0,0,0,8" IsChecked="True">
+                    <RadioButton Margin="0,0,0,8" IsChecked="True">
                         <TextBlock Text="All Pages" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI"></TextBlock>
                     </RadioButton>
-                    <RadioButton Grid.Row="1" Style="{StaticResource CommonRadioButtonStyle}" Margin="0,0,0,8">
+                    <RadioButton Grid.Row="1" Margin="0,0,0,8">
                         <TextBlock Text="Odd page only" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI"></TextBlock>
                     </RadioButton>
-                    <RadioButton Grid.Row="2" Style="{StaticResource CommonRadioButtonStyle}" Margin="0,0,0,8">
+                    <RadioButton Grid.Row="2" Margin="0,0,0,8">
                         <TextBlock Text="Even page only" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI"></TextBlock>
                     </RadioButton>
-                    <RadioButton Grid.Row="3" Style="{StaticResource CommonRadioButtonStyle}" Margin="0,0,0,8">
+                    <RadioButton Grid.Row="3" Margin="0,0,0,8">
                         <TextBlock Text="Custom Range" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI"></TextBlock>
                     </RadioButton>
                 </Grid>

+ 23 - 3
Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml.cs

@@ -1,7 +1,10 @@
 using ComPDFKit.PDFDocument;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
@@ -20,16 +23,28 @@ namespace Compdfkit_Tools.PDFControl
     /// </summary>
     public partial class PageRangeDialog : Window
     {
-        private List<int> pageRangeArray;
+        private List<int> _pageIndexList = new List<int>();
+        public List<int> PageIndexList
+        {
+            get => _pageIndexList;
+            set
+            {
+                _pageIndexList = value;
+                PreviewControl.PageRangeList = _pageIndexList;
+            }
+        }
+
+        private FileInfoWithRange fileInfo;
 
         public PageRangeDialog()
         {
+            this.DataContext = this;
             InitializeComponent();
         }
 
-        public void InitWithDocument(CPDFDocument document, string pageRange)
+        public void InitWithFileInfo(FileInfoWithRange fileInfo)
         {
-
+            this.fileInfo = fileInfo;
         }
 
         private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
@@ -41,5 +56,10 @@ namespace Compdfkit_Tools.PDFControl
         {
 
         }
+         
+        private void Window_Loaded(object sender, RoutedEventArgs e)
+        { 
+            PreviewControl.InitPreview(fileInfo.Document, fileInfo.PageRangeList);
+        }
     }
 }

+ 20 - 21
Demo/Examples/Compdfkit_Tools/Security/Watermark/PreviewControl.xaml

@@ -5,24 +5,25 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
              mc:Ignorable="d" 
-             d:DesignHeight="449" d:DesignWidth="248">
+             d:DesignHeight="449" d:DesignWidth="248" Loaded="UserControl_Loaded">
     <UserControl.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
             </ResourceDictionary.MergedDictionaries>
             <Style x:Key="TransparentButtonStyle" TargetType="{x:Type Button}">
-                <Setter Property="Background" Value="Transparent" />
                 <Setter Property="BorderThickness" Value="0" />
                 <Setter Property="Template">
                     <Setter.Value>
                         <ControlTemplate TargetType="Button">
-                            <ContentPresenter />
+                            <Border Name="border">
+                                <ContentPresenter />
+                            </Border>
                             <ControlTemplate.Triggers>
                                 <Trigger Property="IsMouseOver" Value="True">
-                                    <Setter Property="Background" Value="#1a000000" />
+                                    <Setter TargetName="border" Property="Background" Value="#1a000000" />
                                 </Trigger>
                                 <Trigger Property="IsPressed" Value="True">
-                                    <Setter Property="Background" Value="#5a000000" />
+                                    <Setter TargetName="border" Property="Background" Value="#5a000000" />
                                 </Trigger>
                             </ControlTemplate.Triggers>
                         </ControlTemplate>
@@ -30,21 +31,19 @@
                 </Setter>
             </Style>
             <Style x:Key="PageButtonStyle" TargetType="{x:Type Button}">
-                <Setter Property="Background" Value="#E1E1E1"></Setter>
                 <Setter Property="BorderThickness" Value="0"></Setter>
                 <Setter Property="Template">
                     <Setter.Value>
                         <ControlTemplate TargetType="Button">
-                            <ContentPresenter />
+                            <Border Name="border" Background="#E1E1E1">
+                                <ContentPresenter />
+                            </Border>
                             <ControlTemplate.Triggers>
                                 <Trigger Property="IsMouseOver" Value="True">
-                                    <Setter Property="Background" Value="#C1C1C1" />
-                                </Trigger>
-                                <Trigger Property="IsMouseOver" Value="False">
-                                    <Setter Property="Background" Value="#E1E1E1" />
-                                </Trigger>
+                                    <Setter TargetName="border" Property="Background" Value="#C1C1C1" />
+                                </Trigger> 
                                 <Trigger Property="IsPressed" Value="True">
-                                    <Setter Property="Background" Value="#A1A1A1" />
+                                    <Setter TargetName="border"  Property="Background" Value="#A1A1A1" />
                                 </Trigger>
                             </ControlTemplate.Triggers>
                         </ControlTemplate>
@@ -62,12 +61,12 @@
         <Grid Margin="0,0,0,10">
             <TextBlock Text="Preview" FontWeight="DemiBold" FontFamily="Segoe UI" FontSize="14"></TextBlock>
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
-                <Button Style="{StaticResource TransparentButtonStyle}" Margin="0,0,10,0">
-                    <Path Data="M0,6.5 C0,2.91015 2.91015,0 6.5,0 C10.0899,0 13,2.91015 13,6.5 C13,8.12212 12.4058,9.60545 11.4232,10.7442 L15.5,14.821 L14.821,15.5 L10.7442,11.4232 C9.60545,12.4058 8.12212,13 6.5,13 C2.91015,13 0,10.0899 0,6.5 Z M12,6.5 C12,3.46243 9.53757,1 6.5,1 C3.46243,1 1,3.46243 1,6.5 C1,9.53757 3.46243,12 6.5,12 C9.53757,12 12,9.53757 12,6.5 Z M10,6 V7 H3 V6 H10 Z" 
+                <Button Height="20" Width="20" Style="{StaticResource TransparentButtonStyle}" Margin="0,0,10,0">
+                    <Path HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,6.5 C0,2.91015 2.91015,0 6.5,0 C10.0899,0 13,2.91015 13,6.5 C13,8.12212 12.4058,9.60545 11.4232,10.7442 L15.5,14.821 L14.821,15.5 L10.7442,11.4232 C9.60545,12.4058 8.12212,13 6.5,13 C2.91015,13 0,10.0899 0,6.5 Z M12,6.5 C12,3.46243 9.53757,1 6.5,1 C3.46243,1 1,3.46243 1,6.5 C1,9.53757 3.46243,12 6.5,12 C9.53757,12 12,9.53757 12,6.5 Z M10,6 V7 H3 V6 H10 Z" 
               Fill="Black" />
                 </Button>
-                <Button Style="{StaticResource TransparentButtonStyle}">
-                    <Path Data="M6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.12212 13 9.60545 12.4058 10.7442 11.4232L14.821 15.5L15.5 14.821L11.4232 10.7442C12.4058 9.60545 13 8.12212 13 6.5C13 2.91015 10.0899 0 6.5 0ZM6.5 1C9.53757 1 12 3.46243 12 6.5C12 9.53757 9.53757 12 6.5 12C3.46243 12 1 9.53757 1 6.5C1 3.46243 3.46243 1 6.5 1ZM10 6H7V3H6V6H3V7H6V10H7V7H10V6Z" 
+                <Button  Height="20" Width="20"  Style="{StaticResource TransparentButtonStyle}">
+                    <Path HorizontalAlignment="Center" VerticalAlignment="Center" Data="M6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.12212 13 9.60545 12.4058 10.7442 11.4232L14.821 15.5L15.5 14.821L11.4232 10.7442C12.4058 9.60545 13 8.12212 13 6.5C13 2.91015 10.0899 0 6.5 0ZM6.5 1C9.53757 1 12 3.46243 12 6.5C12 9.53757 9.53757 12 6.5 12C3.46243 12 1 9.53757 1 6.5C1 3.46243 3.46243 1 6.5 1ZM10 6H7V3H6V6H3V7H6V10H7V7H10V6Z" 
               Fill="Black" />
                 </Button>
             </StackPanel>
@@ -82,14 +81,14 @@
             </ScrollViewer>
         </Border>
         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="2" Margin="0,8,0,0">
-            <Button x:Name="PrePageBtn" Height="28" Width="28" Margin="0,0,16,0" Style="{StaticResource PageButtonStyle}">
+            <Button x:Name="PrePageBtn" Height="28" Width="28" Margin="0,0,16,0" Style="{StaticResource PageButtonStyle}" Click="PageBtn_Click">
                 <Path Height="16" Width="16" Data="M11.2978 14L12 13.2733L6.90446 8L12 2.72673L11.2978 2L5.5 8L11.2978 14Z" 
               Fill="Black" />
             </Button>
-            <TextBox Height="32" Width="48" Margin="0,0,8,0"></TextBox>
+            <TextBox x:Name="CurrentIndexTxt" Text="{Binding CurrentIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Height="32" Width="48" Margin="0,0,8,0" PreviewTextInput="CurrentIndexTxt_PreviewTextInput" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"  InputMethod.IsInputMethodEnabled="False" CommandManager.CanExecute="CurrentIndexTxt_CanExecute"></TextBox>
             <TextBlock Text="/" FontSize="14" VerticalAlignment="Center" FontFamily="Segoe UI"></TextBlock>
-            <TextBlock Text="{Binding SumPage}" Margin="5,0,0,0" FontSize="14" VerticalAlignment="Center" FontFamily="Segoe UI"></TextBlock>
-            <Button x:Name="NextPageBtn" Height="28" Width="28"  Margin="16,0,0,0" Style="{StaticResource PageButtonStyle}">
+            <TextBlock Text="{Binding PageCount}" Margin="5,0,0,0" FontSize="14" VerticalAlignment="Center" FontFamily="Segoe UI"></TextBlock>
+            <Button x:Name="NextPageBtn" Height="28" Width="28"  Margin="16,0,0,0" Style="{StaticResource PageButtonStyle}"  Click="PageBtn_Click">
                 <Path Height="16" Width="16" Data="M6.20223 14L5.5 13.2733L10.5955 8L5.5 2.72673L6.20223 2L12 8L6.20223 14Z" 
               Fill="Black" />
             </Button>

+ 206 - 2
Demo/Examples/Compdfkit_Tools/Security/Watermark/PreviewControl.xaml.cs

@@ -1,7 +1,13 @@
-using System;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using System;
 using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
@@ -12,17 +18,102 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using System.Xml.Linq;
 
 namespace Compdfkit_Tools.PDFControl
 {
     /// <summary>
     /// Interaction logic for PreviewControl.xaml
     /// </summary>
-    public partial class PreviewControl : UserControl
+    public partial class PreviewControl : UserControl, INotifyPropertyChanged
     {
+        private List<int> _pageIndexList = new List<int>();
+        public List<int> PageRangeList
+        {
+            get => _pageIndexList;
+            set
+            {
+                _pageIndexList = value;
+                PageCount = _pageIndexList.Count;
+            }
+        }
+
+        private int _pageCount = 1;
+        public int PageCount
+        {
+            get => _pageCount;
+            set
+            {
+                UpdateProper(ref _pageCount, value);
+            }
+        }
+
+        private int _currentIndex = 1;
+        public int CurrentIndex
+        {
+            get => _currentIndex;
+            set
+            {
+                if (value < 1)
+                {
+                    value = 1;
+                }
+                else if (value > PageCount)
+                {
+                    value = PageCount;
+                }
+
+                if (UpdateProper(ref _currentIndex, value))
+                {
+                    ImageSource = LoadImage(Document.PageAtIndex(_currentIndex - 1));
+                }
+            }
+        }
+
+        private double _scale = 1.0;
+        public double Scale
+        {
+            get => _scale;
+            set
+            {
+                UpdateProper(ref _scale, Math.Min((Math.Max(value, 0.1)), 10));
+            }
+        }
+
+        private WriteableBitmap _imageSource;
+        public WriteableBitmap ImageSource
+        {
+            get => _imageSource;
+            set
+            {
+                UpdateProper(ref _imageSource, value);
+            }
+        }
+
+        private CPDFDocument _document;
+        public CPDFDocument Document
+        {
+            get { return _document; }
+            set
+            {
+                _document = value;
+            }
+        }
+
+        private double aspectRatio;
+        private double thumbnailWidth;
+        private double thumbnailHeight;
+
         public PreviewControl()
         {
             InitializeComponent();
+            DataContext = this;
+        }
+
+        public void InitPreview(CPDFDocument document, List<int> pageRangeList)
+        {
+            Document = document;
+            this.PageRangeList = pageRangeList;
         }
 
         private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@@ -39,5 +130,118 @@ namespace Compdfkit_Tools.PDFControl
         {
 
         }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected virtual void OnPropertyChanged(string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+        protected bool UpdateProper<T>(ref T properValue,
+            T newValue,
+            [CallerMemberName] string properName = "")
+        {
+            if (object.Equals(properValue, newValue))
+                return false;
+
+            properValue = newValue;
+            OnPropertyChanged(properName);
+            return true;
+        }
+
+        private void CurrentIndexTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            TextBox textBox = sender as TextBox;
+            if (textBox != null)
+            {
+                if (!System.Text.RegularExpressions.Regex.IsMatch(e.Text, @"^[0-9]$"))
+                {
+                    e.Handled = true;
+                }
+            }
+        }
+
+        public async Task LoadImageAsync(CPDFPage pdfPage)
+        {
+            ImageSource = null;
+            WriteableBitmap bitmap = await Task.Run(() => LoadImage(pdfPage));
+
+            Application.Current.Dispatcher.Invoke(new Action(() =>
+            {
+                ImageSource = bitmap;
+            }));
+        }
+
+        private WriteableBitmap LoadImage(CPDFPage pdfPage)
+        {
+            Size pageSize = pdfPage.PageSize;
+            double ratio = CalculateThumbnailSize(pageSize);
+            Rect pageRect = new Rect(0, 0, (int)(pageSize.Width / 72.0 * 96 * ratio), (int)(pageSize.Height / 72.0 * 96 * ratio));
+            byte[] bmpData = new byte[(int)(pageRect.Width * pageRect.Height * (96 / 72.0) * (96 / 72.0) * 4)];
+            pdfPage.RenderPageBitmapWithMatrix((float)(96 / 72.0 * ratio), pageRect, 0xFFFFFFFF, bmpData, 0, true);
+
+            WriteableBitmap writeableBitmap = new WriteableBitmap((int)pageRect.Width, (int)pageRect.Height, 96, 96, PixelFormats.Bgra32, null);
+            writeableBitmap.WritePixels(new Int32Rect(0, 0, (int)pageRect.Width, (int)pageRect.Height), bmpData, writeableBitmap.BackBufferStride, 0);
+            writeableBitmap.Freeze();
+            return writeableBitmap;
+        }
+
+        private double CalculateThumbnailSize(Size size)
+        {
+
+            if (size.Height / size.Width > aspectRatio)
+            {
+                return thumbnailWidth / size.Width;
+            }
+            else
+            {
+                return thumbnailHeight / size.Height;
+
+            }
+        }
+
+        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            aspectRatio = ImageGd.ActualHeight / ImageGd.ActualWidth;
+            thumbnailWidth = ImageGd.ActualWidth;
+            thumbnailHeight = ImageGd.ActualHeight;
+
+            await LoadImageAsync(Document.PageAtIndex(0));
+        }
+
+        private void CurrentIndexTxt_CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            try
+            {
+                if (e.Command == ApplicationCommands.Paste && Clipboard.ContainsText())
+                {
+                    string checkText = Clipboard.GetText();
+                    if (int.TryParse(checkText, out int value))
+                    {
+                        e.CanExecute = true;
+                    }
+                    e.Handled = true;
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+        }
+
+        private void PageBtn_Click(object sender, RoutedEventArgs e)
+        {
+            var button = sender as Button;
+            if (button != null)
+            {
+                if (button.Name == "PrePageBtn")
+                {
+                    CurrentIndex--;
+                }
+                else
+                {
+                    CurrentIndex++;
+                }
+            }
+        }
     }
 }

File diff suppressed because it is too large
+ 81 - 81
Demo/Examples/PDFViewer/MainWindow.xaml


+ 1 - 2
Demo/Examples/PDFViewer/SettingsDialog.xaml

@@ -8,8 +8,7 @@
         Title="Settings" Height="613" Width="418"
         ResizeMode="NoResize">
     <Window.Resources>
-        <ResourceDictionary>
-            
+        <ResourceDictionary> 
             <ResourceDictionary.MergedDictionaries> 
                 <ResourceDictionary Source="pack://application:,,,/Compdfkit_Tools;component/Asset/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>