瀏覽代碼

compdfkit(win) - 移除水印,补充批量操作时释放文档

liuaoran 1 年之前
父節點
當前提交
c2ec71a442
共有 21 個文件被更改,包括 685 次插入108 次删除
  1. 28 1
      Demo/Examples/Compdfkit_Tools/Asset/Styles/ButtonStyle.xaml
  2. 17 17
      Demo/Examples/Compdfkit_Tools/Common/PreviewControl/PreviewControl.xaml.cs
  3. 2 2
      Demo/Examples/Compdfkit_Tools/Common/PropertyControl/PDFLocation/CPDFRotationControl.xaml.cs
  4. 23 9
      Demo/Examples/Compdfkit_Tools/Compdfkit_Tools.csproj
  5. 18 9
      Demo/Examples/Compdfkit_Tools/Security/Encryption/EncryptionDialog.xaml.cs
  6. 9 3
      Demo/Examples/Compdfkit_Tools/Security/Encryption/FileGridListControl.xaml.cs
  7. 0 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/AddWatermark/FileGridListWithPageRangeControl.xaml
  8. 16 3
      Demo/Examples/Compdfkit_Tools/Security/Watermark/FileGridListWithPageRangeControl.xaml.cs
  9. 1 1
      Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml
  10. 14 4
      Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml.cs
  11. 15 9
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkDialog.xaml
  12. 23 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkDialog.xaml.cs
  13. 2 2
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListDialog.xaml
  14. 148 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/AddWatermark/WatermarkListDialog.xaml.cs
  15. 13 1
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkPreviewControl.cs
  16. 88 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListControl.xaml
  17. 177 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListControl.xaml.cs
  18. 22 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListDialog.xaml
  19. 64 0
      Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListDialog.xaml.cs
  20. 0 43
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListDialog.xaml.cs
  21. 5 4
      Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkOperationTypeDialog.xaml.cs

+ 28 - 1
Demo/Examples/Compdfkit_Tools/Asset/Styles/ButtonStyle.xaml

@@ -254,6 +254,33 @@
     </Style>
     </Style>
 
 
     <Style x:Key="ImagePathButtonStyle" TargetType="{x:Type Button}">
     <Style x:Key="ImagePathButtonStyle" TargetType="{x:Type Button}">
-        
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="Foreground" Value="Black" />
+        <Setter Property="BorderBrush" Value="#5A000000" />
+        <Setter Property="BorderThickness" Value="1" />
+        <Setter Property="Padding" Value="10" />
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="{x:Type Button}">
+                    <Border Background="{TemplateBinding Background}"
+                        BorderBrush="{TemplateBinding BorderBrush}"
+                        BorderThickness="{TemplateBinding BorderThickness}"
+                        x:Name="border">
+                        <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
+                    </Border>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsMouseOver" Value="True">
+                            <Setter TargetName="border" Property="Background" Value="#1A000000" />
+                        </Trigger>
+                        <Trigger Property="IsPressed" Value="True">
+                            <Setter TargetName="border" Property="Background" Value="#3A000000" />
+                        </Trigger>
+                        <Trigger Property="IsEnabled" Value="False">
+                            <Setter Property="Opacity" Value="0.5" />
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
     </Style>
     </Style>
 </ResourceDictionary> 
 </ResourceDictionary> 

+ 17 - 17
Demo/Examples/Compdfkit_Tools/Common/PreviewControl/PreviewControl.xaml.cs

@@ -199,29 +199,29 @@ namespace Compdfkit_Tools.PDFControl
             renderThread.Start(Document.PageAtIndex(pageIndex));
             renderThread.Start(Document.PageAtIndex(pageIndex));
         }
         }
 
 
-        private readonly object queueLock = new object();
+        protected readonly object queueLock = new object();
         protected void LoadImage(object pageObject)
         protected void LoadImage(object pageObject)
         {
         {
-            try
+            CPDFPage pdfPage = (CPDFPage)pageObject;
+            Size pageSize = pdfPage.PageSize;
+            double ratio = CalculateThumbnailSize(pageSize) * 3;
+            Rect pageRect = new Rect(0, 0, (int)(pageSize.Width * ratio), (int)(pageSize.Height * ratio));
+            byte[] bmpData = new byte[(int)(pageRect.Width * pageRect.Height * 4)];
+            lock (queueLock)
             {
             {
-                CPDFPage pdfPage = (CPDFPage)pageObject;
-                Size pageSize = pdfPage.PageSize;
-                double ratio = CalculateThumbnailSize(pageSize) * 3;
-                Rect pageRect = new Rect(0, 0, (int)(pageSize.Width * ratio), (int)(pageSize.Height * ratio));
-                byte[] bmpData = new byte[(int)(pageRect.Width * pageRect.Height * 4)];
-                pdfPage.RenderPageBitmapWithMatrix((float)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();
-                Application.Current.Dispatcher.Invoke(new Action(() =>
+                if(pdfPage.IsValid() == false)
                 {
                 {
-                    ImageSource = writeableBitmap;
-                }));
+                    pdfPage = Document.PageAtIndex(pdfPage.PageIndex);
+                }
+                pdfPage.RenderPageBitmapWithMatrix((float)ratio, pageRect, 0xFFFFFFFF, bmpData, 0, true);
             }
             }
-            catch (Exception ex)
+            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();
+            Application.Current.Dispatcher.Invoke(new Action(() =>
             {
             {
-                return;
-            }
+                ImageSource = writeableBitmap;
+            }));
         }
         }
 
 
 
 

+ 2 - 2
Demo/Examples/Compdfkit_Tools/Common/PropertyControl/PDFLocation/CPDFRotationControl.xaml.cs

@@ -62,7 +62,7 @@ namespace Compdfkit_Tools.Common
             {
             {
                 if (btn.Name == "CounterclockwiseBtn")
                 if (btn.Name == "CounterclockwiseBtn")
                 {
                 {
-                    RotationText = (int.Parse(RotationText) - 45).ToString();
+                    RotationText = (int.Parse(RotationText) + 45).ToString();
                 }
                 }
                 else if (btn.Name == "ResetBtn")
                 else if (btn.Name == "ResetBtn")
                 {
                 {
@@ -70,7 +70,7 @@ namespace Compdfkit_Tools.Common
                 }
                 }
                 else if (btn.Name == "ClockwiseBtn")
                 else if (btn.Name == "ClockwiseBtn")
                 {
                 {
-                    RotationText = (int.Parse(RotationText) + 45).ToString();
+                    RotationText = (int.Parse(RotationText) - 45).ToString();
                 }
                 }
             }
             }
         }
         }

+ 23 - 9
Demo/Examples/Compdfkit_Tools/Compdfkit_Tools.csproj

@@ -483,26 +483,32 @@
     <Compile Include="PDFView\PDFScaling\PDFScalingUI\CPDFScalingUI.xaml.cs">
     <Compile Include="PDFView\PDFScaling\PDFScalingUI\CPDFScalingUI.xaml.cs">
       <DependentUpon>CPDFScalingUI.xaml</DependentUpon>
       <DependentUpon>CPDFScalingUI.xaml</DependentUpon>
     </Compile>
     </Compile>
-    <Compile Include="Security\Watermark\FileGridListWithPageRangeControl.xaml.cs">
+    <Compile Include="Security\Watermark\AddWatermark\FileGridListWithPageRangeControl.xaml.cs">
       <DependentUpon>FileGridListWithPageRangeControl.xaml</DependentUpon>
       <DependentUpon>FileGridListWithPageRangeControl.xaml</DependentUpon>
     </Compile>
     </Compile>
-    <Compile Include="Security\Watermark\PageRangeDialog.xaml.cs">
+    <Compile Include="Security\Watermark\AddWatermark\PageRangeDialog.xaml.cs">
       <DependentUpon>PageRangeDialog.xaml</DependentUpon>
       <DependentUpon>PageRangeDialog.xaml</DependentUpon>
     </Compile>
     </Compile>
     <Compile Include="Common\PreviewControl\PreviewControl.xaml.cs">
     <Compile Include="Common\PreviewControl\PreviewControl.xaml.cs">
       <DependentUpon>PreviewControl.xaml</DependentUpon>
       <DependentUpon>PreviewControl.xaml</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="Security\Watermark\RemoveWatermark\RemoveWatermarkListControl.xaml.cs">
+      <DependentUpon>RemoveWatermarkListControl.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Security\Watermark\RemoveWatermark\RemoveWatermarkListDialog.xaml.cs">
+      <DependentUpon>RemoveWatermarkListDialog.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Security\Watermark\WatermarkData.cs" />
     <Compile Include="Security\Watermark\WatermarkData.cs" />
-    <Compile Include="Security\Watermark\WatermarkDialog.xaml.cs">
+    <Compile Include="Security\Watermark\AddWatermark\WatermarkDialog.xaml.cs">
       <DependentUpon>WatermarkDialog.xaml</DependentUpon>
       <DependentUpon>WatermarkDialog.xaml</DependentUpon>
     </Compile>
     </Compile>
-    <Compile Include="Security\Watermark\WatermarkListDialog.xaml.cs">
+    <Compile Include="Security\Watermark\AddWatermark\WatermarkListDialog.xaml.cs">
       <DependentUpon>WatermarkListDialog.xaml</DependentUpon>
       <DependentUpon>WatermarkListDialog.xaml</DependentUpon>
     </Compile>
     </Compile>
     <Compile Include="Security\Watermark\WatermarkOperationTypeDialog.xaml.cs">
     <Compile Include="Security\Watermark\WatermarkOperationTypeDialog.xaml.cs">
       <DependentUpon>WatermarkOperationTypeDialog.xaml</DependentUpon>
       <DependentUpon>WatermarkOperationTypeDialog.xaml</DependentUpon>
     </Compile>
     </Compile>
-    <Compile Include="Security\Watermark\WatermarkPreviewControl.cs" />
+    <Compile Include="Security\Watermark\AddWatermark\WatermarkPreviewControl.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -1044,11 +1050,11 @@
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
     <Page Include="PDFView\RegularViewerControl.xaml" />
     <Page Include="PDFView\RegularViewerControl.xaml" />
-    <Page Include="Security\Watermark\FileGridListWithPageRangeControl.xaml">
+    <Page Include="Security\Watermark\AddWatermark\FileGridListWithPageRangeControl.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
-    <Page Include="Security\Watermark\PageRangeDialog.xaml">
+    <Page Include="Security\Watermark\AddWatermark\PageRangeDialog.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
@@ -1056,11 +1062,19 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
-    <Page Include="Security\Watermark\WatermarkDialog.xaml">
+    <Page Include="Security\Watermark\AddWatermark\WatermarkDialog.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Security\Watermark\AddWatermark\WatermarkListDialog.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Security\Watermark\RemoveWatermark\RemoveWatermarkListControl.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
-    <Page Include="Security\Watermark\WatermarkListDialog.xaml">
+    <Page Include="Security\Watermark\RemoveWatermark\RemoveWatermarkListDialog.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>

+ 18 - 9
Demo/Examples/Compdfkit_Tools/Security/Encryption/EncryptionDialog.xaml.cs

@@ -26,9 +26,9 @@ namespace Compdfkit_Tools.PDFControl
         public int FileNum
         public int FileNum
         {
         {
             get => _fileNum;
             get => _fileNum;
-            set => UpdateProper(ref _fileNum,value);
+            set => UpdateProper(ref _fileNum, value);
         }
         }
-        
+
         private bool isEnsure;
         private bool isEnsure;
 
 
         public event PropertyChangedEventHandler PropertyChanged;
         public event PropertyChangedEventHandler PropertyChanged;
@@ -36,7 +36,7 @@ namespace Compdfkit_Tools.PDFControl
         {
         {
             get { return FileListControl.FileInfoDataList.Count > 0 && SetEncryptionControl.IsSettingValid; }
             get { return FileListControl.FileInfoDataList.Count > 0 && SetEncryptionControl.IsSettingValid; }
         }
         }
-        
+
         private List<string> failedList = new List<string>();
         private List<string> failedList = new List<string>();
         public EncryptionDialog()
         public EncryptionDialog()
         {
         {
@@ -56,19 +56,19 @@ namespace Compdfkit_Tools.PDFControl
             dialog.ShowDialog();
             dialog.ShowDialog();
             var savePath = dialog.SelectedPath;
             var savePath = dialog.SelectedPath;
             if (string.IsNullOrEmpty(savePath)) return;
             if (string.IsNullOrEmpty(savePath)) return;
-            
+
             CurrentFileNum = 0;
             CurrentFileNum = 0;
             var permissionsInfo = new CPDFPermissionsInfo();
             var permissionsInfo = new CPDFPermissionsInfo();
             string userPassword = string.Empty;
             string userPassword = string.Empty;
             string ownerPassword = string.Empty;
             string ownerPassword = string.Empty;
 
 
-            if (SetEncryptionControl.IsOwnerPasswordEnabled &&  !string.IsNullOrEmpty(SetEncryptionControl.OwnerPassword))
+            if (SetEncryptionControl.IsOwnerPasswordEnabled && !string.IsNullOrEmpty(SetEncryptionControl.OwnerPassword))
             {
             {
                 permissionsInfo.AllowsPrinting = SetEncryptionControl.IsAllowPrint;
                 permissionsInfo.AllowsPrinting = SetEncryptionControl.IsAllowPrint;
                 permissionsInfo.AllowsCopying = SetEncryptionControl.IsAllowCopy;
                 permissionsInfo.AllowsCopying = SetEncryptionControl.IsAllowCopy;
                 ownerPassword = SetEncryptionControl.OwnerPassword;
                 ownerPassword = SetEncryptionControl.OwnerPassword;
             }
             }
-            if(SetEncryptionControl.IsUserPasswordEnabled && !string.IsNullOrEmpty(SetEncryptionControl.UserPassword))
+            if (SetEncryptionControl.IsUserPasswordEnabled && !string.IsNullOrEmpty(SetEncryptionControl.UserPassword))
             {
             {
                 userPassword = SetEncryptionControl.UserPassword;
                 userPassword = SetEncryptionControl.UserPassword;
             }
             }
@@ -91,22 +91,31 @@ namespace Compdfkit_Tools.PDFControl
                     failedList.Add(fileInfoData.Location);
                     failedList.Add(fileInfoData.Location);
                 }
                 }
             }
             }
-            if(failedList.Count > 0)
+            if (failedList.Count > 0)
             {
             {
                 System.Windows.MessageBox.Show("Failed to encrypt the following files:\n" + string.Join("\n", failedList));
                 System.Windows.MessageBox.Show("Failed to encrypt the following files:\n" + string.Join("\n", failedList));
             }
             }
-            if(failedList.Count < FileListControl.FileInfoDataList.Count)
+            if (failedList.Count < FileListControl.FileInfoDataList.Count)
             {
             {
                 System.Diagnostics.Process.Start(savePath);
                 System.Diagnostics.Process.Start(savePath);
             }
             }
             this.Close();
             this.Close();
         }
         }
 
 
+        protected override void OnClosed(EventArgs e)
+        {
+            foreach (var fileInfo in FileListControl.FileInfoDataList)
+            {
+                fileInfo.Document.Release();
+            }
+            base.OnClosed(e);
+        }
+
         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
         {
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
         }
-        
+
         protected void UpdateProper<T>(ref T properValue,
         protected void UpdateProper<T>(ref T properValue,
             T newValue,
             T newValue,
             [CallerMemberName] string properName = "")
             [CallerMemberName] string properName = "")

+ 9 - 3
Demo/Examples/Compdfkit_Tools/Security/Encryption/FileGridListControl.xaml.cs

@@ -35,7 +35,7 @@ namespace Compdfkit_Tools.PDFControl
             public string FileName { get; set; }
             public string FileName { get; set; }
             public string Size { get; set; }
             public string Size { get; set; }
             public string Location { get; set; }
             public string Location { get; set; }
-            
+
             public CPDFDocument Document { get; set; }
             public CPDFDocument Document { get; set; }
         };
         };
 
 
@@ -100,7 +100,7 @@ namespace Compdfkit_Tools.PDFControl
                 {
                 {
                     continue;
                     continue;
                 }
                 }
-                
+
                 var document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
                 var document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
                 if (document.IsLocked)
                 if (document.IsLocked)
                 {
                 {
@@ -111,13 +111,14 @@ namespace Compdfkit_Tools.PDFControl
                     window.ShowDialog();
                     window.ShowDialog();
                     if (document.IsLocked)
                     if (document.IsLocked)
                     {
                     {
+                        document.Release();
                         continue;
                         continue;
                     }
                     }
                 }
                 }
 
 
                 fileInfoData.Document = document;
                 fileInfoData.Document = document;
                 FileInfoDataList.Add(fileInfoData);
                 FileInfoDataList.Add(fileInfoData);
-                
+
             }
             }
         }
         }
 
 
@@ -125,6 +126,10 @@ namespace Compdfkit_Tools.PDFControl
         {
         {
             if (FileDataGrid.SelectedItems.Count == 0)
             if (FileDataGrid.SelectedItems.Count == 0)
             {
             {
+                foreach (var item in FileInfoDataList)
+                {
+                    item.Document.Release();
+                }
                 FileInfoDataList.Clear();
                 FileInfoDataList.Clear();
                 OnPropertyChanged("FileNum");
                 OnPropertyChanged("FileNum");
                 return;
                 return;
@@ -134,6 +139,7 @@ namespace Compdfkit_Tools.PDFControl
 
 
             foreach (var item in selectedItemsList)
             foreach (var item in selectedItemsList)
             {
             {
+                item.Document.Release();
                 FileInfoDataList.Remove(item);
                 FileInfoDataList.Remove(item);
             }
             }
             OnPropertyChanged("FileNum");
             OnPropertyChanged("FileNum");

Demo/Examples/Compdfkit_Tools/Security/Watermark/FileGridListWithPageRangeControl.xaml → Demo/Examples/Compdfkit_Tools/Security/Watermark/AddWatermark/FileGridListWithPageRangeControl.xaml


+ 16 - 3
Demo/Examples/Compdfkit_Tools/Security/Watermark/FileGridListWithPageRangeControl.xaml.cs

@@ -19,6 +19,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 using System.Windows.Shapes;
+using static Compdfkit_Tools.PDFControl.FileGridListControl;
 using DataGrid = System.Windows.Controls.DataGrid;
 using DataGrid = System.Windows.Controls.DataGrid;
 using DataGridCell = System.Windows.Controls.DataGridCell;
 using DataGridCell = System.Windows.Controls.DataGridCell;
 using UserControl = System.Windows.Controls.UserControl;
 using UserControl = System.Windows.Controls.UserControl;
@@ -63,9 +64,6 @@ namespace Compdfkit_Tools.PDFControl
         }
         }
     }
     }
 
 
-    /// <summary>
-    /// Interaction logic for FileGridListWithPageRangeControl.xaml
-    /// </summary>
     public partial class FileGridListWithPageRangeControl : UserControl, INotifyPropertyChanged
     public partial class FileGridListWithPageRangeControl : UserControl, INotifyPropertyChanged
     {
     {
         public static readonly DependencyProperty IsEnsureProperty =
         public static readonly DependencyProperty IsEnsureProperty =
@@ -197,7 +195,22 @@ namespace Compdfkit_Tools.PDFControl
 
 
         private void RemoveBtn_Click(object sender, RoutedEventArgs e)
         private void RemoveBtn_Click(object sender, RoutedEventArgs e)
         {
         {
+            if (FileDataGrid.SelectedItems.Count == 0)
+            {
+                foreach (var item in FileInfoDataList)
+                {
+                    item.Document.Release();
+                }
+                FileInfoDataList.Clear();
+                return;
+            }
+            var selectedItems = FileDataGrid.SelectedItems;
+            var selectedItemsList = selectedItems.Cast<FileInfoWithRange>().ToList();
 
 
+            foreach (var item in selectedItemsList)
+            {
+                FileInfoDataList.Remove(item);
+            }
         }
         }
 
 
         private void PageRangeBtn_Click(object sender, RoutedEventArgs e)
         private void PageRangeBtn_Click(object sender, RoutedEventArgs e)

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml

@@ -10,7 +10,7 @@
     <Window.Resources>
     <Window.Resources>
         <ResourceDictionary>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
             <ResourceDictionary.MergedDictionaries>
-                <ResourceDictionary Source="../../Asset/Styles/RadioButtonStyle.xaml"></ResourceDictionary>
+                <ResourceDictionary Source="../../../Asset/Styles/RadioButtonStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
         </ResourceDictionary>
     </Window.Resources>
     </Window.Resources>

+ 14 - 4
Demo/Examples/Compdfkit_Tools/Security/Watermark/PageRangeDialog.xaml.cs

@@ -14,6 +14,8 @@ namespace Compdfkit_Tools.PDFControl
     /// </summary>
     /// </summary>
     public partial class PageRangeDialog : Window, INotifyPropertyChanged
     public partial class PageRangeDialog : Window, INotifyPropertyChanged
     {
     {
+        private bool canContinue = true;
+
         private int pageCount = 0;
         private int pageCount = 0;
 
 
         private List<int> defaultPageList = new List<int>(); 
         private List<int> defaultPageList = new List<int>(); 
@@ -48,9 +50,11 @@ namespace Compdfkit_Tools.PDFControl
                 if (fileInfo != null & UpdateProper(ref _pageRange, value))
                 if (fileInfo != null & UpdateProper(ref _pageRange, value))
                 {
                 {
                     List<int> list = new List<int>();
                     List<int> list = new List<int>();
-                    if (CommonHelper.GetPagesInRange(ref list, PageRange, fileInfo.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
+                    canContinue = CommonHelper.GetPagesInRange(ref list, PageRange, fileInfo.Document.PageCount, new char[] { ',' }, new char[] { '-' });
+                    if (canContinue)
                     {
                     {
-                        PageIndexList = list;
+                        List<int> newList = list.Select(item => item + 1).ToList();
+                        PageIndexList = newList;
                     }
                     }
                     else
                     else
                     {
                     {
@@ -79,6 +83,11 @@ namespace Compdfkit_Tools.PDFControl
 
 
         private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
         private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
         {
         {
+            if (!canContinue)
+            {
+                MessageBox.Show("Please enter the right page range", "", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
             WindowClosed?.Invoke(weakReference.Target, PageIndexList);
             WindowClosed?.Invoke(weakReference.Target, PageIndexList);
             this.Close();
             this.Close();
         }
         }
@@ -111,7 +120,7 @@ namespace Compdfkit_Tools.PDFControl
             var radioButton = sender as RadioButton;
             var radioButton = sender as RadioButton;
             if (radioButton != null && fileInfo != null)
             if (radioButton != null && fileInfo != null)
             {
             {
-
+                canContinue = true;
                 switch (radioButton.Tag)
                 switch (radioButton.Tag)
                 {
                 {
                     case "All":
                     case "All":
@@ -128,7 +137,8 @@ namespace Compdfkit_Tools.PDFControl
                         break;
                         break;
                     case "Custom":
                     case "Custom":
                         List<int> list = new List<int>();
                         List<int> list = new List<int>();
-                        if (CommonHelper.GetPagesInRange(ref list, PageRange, fileInfo.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
+                        canContinue = CommonHelper.GetPagesInRange(ref list, PageRange, fileInfo.Document.PageCount, new char[] { ',' }, new char[] { '-' }, false);
+                        if (canContinue)
                         {
                         {
                             PageIndexList = list;
                             PageIndexList = list;
                         }
                         }

File diff suppressed because it is too large
+ 15 - 9
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkDialog.xaml


+ 23 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkDialog.xaml.cs

@@ -16,6 +16,7 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using System.Windows.Shapes;
 using System.Windows.Shapes;
+using static Compdfkit_Tools.PDFControl.PageRangeDialog;
 
 
 namespace Compdfkit_Tools.PDFControl
 namespace Compdfkit_Tools.PDFControl
 {
 {
@@ -278,6 +279,9 @@ namespace Compdfkit_Tools.PDFControl
                 }
                 }
             }
             }
         }
         }
+        public delegate void WindowClosedEventHandler(object sender, WatermarkData watermarkData); 
+        public event WindowClosedEventHandler WindowClosed;
+        private WeakReference weakReference;
 
 
         public WatermarkDialog()
         public WatermarkDialog()
         {
         {
@@ -345,6 +349,7 @@ namespace Compdfkit_Tools.PDFControl
             PreviewControl.WatermarkData = watermarkData;
             PreviewControl.WatermarkData = watermarkData;
             watermarkData.ValueChanged += 
             watermarkData.ValueChanged += 
                 (sender, e) => PreviewControl.WatermarkData = watermarkData;
                 (sender, e) => PreviewControl.WatermarkData = watermarkData;
+            weakReference = new WeakReference(this);
         }
         }
 
 
         private void InitWatermarkData(in WatermarkData watermarkData)
         private void InitWatermarkData(in WatermarkData watermarkData)
@@ -486,5 +491,23 @@ namespace Compdfkit_Tools.PDFControl
                 VertOffset = float.Parse(locationControl.VertOffsetValue);
                 VertOffset = float.Parse(locationControl.VertOffsetValue);
             }
             }
         }
         }
+
+        private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+            WindowClosed?.Invoke(weakReference.Target,  watermarkData);
+        }
+
+        private void CancelBtn_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+            WindowClosed?.Invoke(weakReference.Target, null);
+        }
+
+        protected override void OnClosed(EventArgs e)
+        {
+            PreviewControl.DeleteDisplayWatermark();
+            base.OnClosed(e);
+        }
     }
     }
 }
 }

+ 2 - 2
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListDialog.xaml

@@ -6,7 +6,7 @@
         xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
         xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
         mc:Ignorable="d"
         mc:Ignorable="d"
         Title="WatermarkListDialog" 
         Title="WatermarkListDialog" 
-        Height="522" Width="516">
+        Height="522" Width="516" ShowInTaskbar="False" ResizeMode="NoResize">
     <Grid>
     <Grid>
         <Grid.RowDefinitions>
         <Grid.RowDefinitions>
             <RowDefinition></RowDefinition>
             <RowDefinition></RowDefinition>
@@ -16,7 +16,7 @@
         <Grid Grid.Row="1">
         <Grid Grid.Row="1">
             <StackPanel Orientation="Horizontal" Margin="0,24,24,12" HorizontalAlignment="Right">
             <StackPanel Orientation="Horizontal" Margin="0,24,24,12" HorizontalAlignment="Right">
                 <Button x:Name="NextBtn" Content="Next" Height="32" Width="112" IsEnabled="{Binding ElementName=FileGridListWithPageRangeControl, Path=IsEnsure}" Margin="0,0,8,0" Click="NextBtn_Click"></Button>
                 <Button x:Name="NextBtn" Content="Next" Height="32" Width="112" IsEnabled="{Binding ElementName=FileGridListWithPageRangeControl, Path=IsEnsure}" Margin="0,0,8,0" Click="NextBtn_Click"></Button>
-                <Button x:Name="CancelBtn" Height="32" Content="Cancel" Width="112" ></Button>
+                <Button x:Name="CancelBtn" Height="32" Content="Cancel" Width="112"  Click="CancelBtn_Click"></Button>
             </StackPanel>
             </StackPanel>
         </Grid>
         </Grid>
     </Grid>
     </Grid>

+ 148 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/AddWatermark/WatermarkListDialog.xaml.cs

@@ -0,0 +1,148 @@
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFWatermark;
+using Compdfkit_Tools.Helper;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Forms;
+
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Xml.Linq;
+using MessageBox = System.Windows.MessageBox;
+using Path = System.IO.Path;
+
+namespace Compdfkit_Tools.PDFControl
+{
+    /// <summary>
+    /// Interaction logic for WatermarkListDialog.xaml
+    /// </summary>
+    public partial class WatermarkListDialog : Window
+    {
+        private WatermarkData watermarkData;
+        public WatermarkListDialog()
+        {
+            InitializeComponent();
+        }
+
+        private void NextBtn_Click(object sender, RoutedEventArgs e)
+        {
+            WatermarkDialog watermarkDialog = new WatermarkDialog
+            {
+                Owner = this
+            };
+
+            watermarkDialog.WindowClosed += WatermarkDialog_WindowClosed;
+            if (watermarkDialog.InitWithFileInfo(FileGridListWithPageRangeControl.FileForDisplay))
+            {
+                watermarkDialog.ShowDialog();
+            }
+            else
+            {
+                MessageBox.Show("No file selected.");
+            }
+        }
+
+        private void WatermarkDialog_WindowClosed(object sender, WatermarkData watermarkData)
+        {
+            if (watermarkData != null)
+            {
+                this.watermarkData = watermarkData;
+                var dialog = new FolderBrowserDialog();
+                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
+                {
+                    return;
+                }
+                else
+                {
+                    var path = dialog.SelectedPath;
+                    foreach (var fileInfo in FileGridListWithPageRangeControl.FileInfoDataList)
+                    {
+                        if (watermarkData.Type == C_Watermark_Type.WATERMARK_TYPE_TEXT)
+                        {
+                            UpdateByTextWatermarkData(fileInfo.Document, fileInfo.PageRangeList);
+                        }
+                        else if (watermarkData.Type == C_Watermark_Type.WATERMARK_TYPE_IMG)
+                        {
+                            UpdateByImageWatermarkData(fileInfo.Document, fileInfo.PageRangeList);
+                        }
+                        else
+                        {
+                            return;
+                        }
+                        string savePath = Path.Combine(path, Path.GetFileNameWithoutExtension(fileInfo.Document.FileName) + "_Watermark.pdf");
+                        fileInfo.Document.WriteToFilePath(savePath);
+                    }
+                    System.Diagnostics.Process.Start(path);
+                }
+            }
+            Close();
+        }
+
+        private void UpdateByImageWatermarkData(CPDFDocument document, List<int> pageRangeList)
+        {
+            CPDFWatermark watermark = document.InitWatermark(watermarkData.Type);
+            Bitmap bitmap = new Bitmap(watermarkData.ImagePath);
+            bitmap = CommonHelper.ConvertTo32bppArgb(bitmap);
+            byte[] byteArray = CommonHelper.ConvertBitmapToByteArray(bitmap);
+            watermark.SetImage(byteArray, bitmap.Width, bitmap.Height);
+            watermark.SetScale((float)(watermarkData.ImageScale / 100.0));
+            UpdateByCommonWatermarkData(watermark, pageRangeList);
+        }
+
+        private void UpdateByTextWatermarkData(CPDFDocument document, List<int> pageRangeList)
+        {
+            CPDFWatermark watermark = document.InitWatermark(watermarkData.Type);
+            watermark.SetText(watermarkData.Text);
+            watermark.SetFontName(watermarkData.FontName);
+            watermark.SetTextRGBColor(watermarkData.Color);
+            watermark.SetFontSize(watermarkData.FontSize);
+            watermark.SetScale(1);
+            UpdateByCommonWatermarkData(watermark, pageRangeList);
+        }
+
+        private void UpdateByCommonWatermarkData(CPDFWatermark watermark, List<int> pageRangeList)
+        {
+            for (int i = 0; i < pageRangeList.Count; i++)
+            {
+                pageRangeList[i]--;
+            }
+            watermark.SetPages(CommonHelper.GetPageParmFromList(pageRangeList));
+            watermark.SetRotation((float)(watermarkData.Rotation * Math.PI / 180.0));
+            watermark.SetOpacity(watermarkData.Opacity);
+            watermark.SetVertalign(watermarkData.Vertalign);
+            watermark.SetHorizalign(watermarkData.Horizalign);
+            watermark.SetVertOffset(watermarkData.VertOffset);
+            watermark.SetHorizOffset(watermarkData.HorizOffset);
+            watermark.SetFront(watermarkData.IsFront);
+            watermark.SetFullScreen(watermarkData.IsFullScreen);
+            watermark.SetVerticalSpacing(watermarkData.VerticalSpacing);
+            watermark.SetHorizontalSpacing(watermarkData.HorizontalSpacing);
+            watermark.CreateWatermark();
+        }
+
+        private void CancelBtn_Click(object sender, RoutedEventArgs e)
+        {
+            Close();
+        }
+
+        protected override void OnClosed(EventArgs e)
+        {
+            foreach (var fileInfo in FileGridListWithPageRangeControl.FileInfoDataList)
+            {
+                fileInfo.Document.Release();
+            }
+            base.OnClosed(e);
+        }
+    }
+}

+ 13 - 1
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkPreviewControl.cs

@@ -33,9 +33,13 @@ namespace Compdfkit_Tools.PDFControl
             set
             set
             {
             {
                 _watermarkData = value;
                 _watermarkData = value;
+
                 if (watermark != null)
                 if (watermark != null)
                 {
                 {
-                    Document.ReleasePages();
+                    lock (queueLock)
+                    {
+                        Document.ReleasePages();
+                    }
                     Document.DeleteWatermarks();
                     Document.DeleteWatermarks();
                     watermark?.ClearWatermark();
                     watermark?.ClearWatermark();
                     watermark?.Release();
                     watermark?.Release();
@@ -116,6 +120,14 @@ namespace Compdfkit_Tools.PDFControl
             watermark.CreateWatermark();
             watermark.CreateWatermark();
         }
         }
 
 
+        public void DeleteDisplayWatermark()
+        {
+            if (watermark != null)
+            {
+                Document.DeleteWatermarks();
+            }
+        }   
+
         override public void BeginLoadImageThread(int pageIndex)
         override public void BeginLoadImageThread(int pageIndex)
         {
         {
             UpdateByWatermarkData();
             UpdateByWatermarkData();

+ 88 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListControl.xaml

@@ -0,0 +1,88 @@
+<UserControl x:Class="Compdfkit_Tools.PDFControl.RemoveWatermarkListControl"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
+             mc:Ignorable="d" 
+             Loaded="UserControl_Loaded"
+             d:DesignHeight="450" d:DesignWidth="800">
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <Style x:Key="CustomDataGridStyle" TargetType="DataGrid">
+                <Setter Property="BorderBrush" Value="#E6E6E6" />
+                <Setter Property="BorderThickness" Value="1" />
+                <Setter Property="CellStyle">
+                    <Setter.Value>
+                        <Style TargetType="DataGridCell">
+                            <Setter Property="BorderThickness" Value="1" />
+                            <Setter Property="BorderBrush" Value="#E6E6E6" />
+                        </Style>
+                    </Setter.Value>
+                </Setter>
+            </Style>
+        </ResourceDictionary>
+    </UserControl.Resources>
+    <Grid Margin="10,0,0,0">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="50"></RowDefinition>
+            <RowDefinition Height="*"></RowDefinition>
+        </Grid.RowDefinitions>
+
+        <DockPanel Grid.Row="0" Grid.Column="0">
+            <Button x:Name="AddFilesBtn" Content="Add Files" Height="32" Width="112" FontFamily="Segoe UI" FontSize="14" Padding="28,6,27,6" HorizontalAlignment="Left" Click="AddFilesBtn_Click"></Button>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
+                <TextBlock Text="Total " FontFamily="Segoe UI" FontSize="14"></TextBlock>
+                <TextBlock FontFamily="Segoe UI" FontSize="14" Text="{Binding FileNumText}" ></TextBlock>
+                <TextBlock Text=" Files" FontFamily="Segoe UI" FontSize="14"></TextBlock>
+            </StackPanel>
+        </DockPanel>
+
+        <Border Grid.Row="1" Grid.Column="0" BorderBrush="#CCCCCC" BorderThickness="1">
+            <Grid Margin="10,10,10,0">
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="*"></RowDefinition>
+                    <RowDefinition Height="50"></RowDefinition>
+                </Grid.RowDefinitions>
+                <Grid Grid.Row="0" VerticalAlignment="Stretch">
+                    <DataGrid Background="White" BorderBrush="#E6E6E6" x:Name="FileDataGrid" HeadersVisibility="Column"
+                               IsReadOnly="True" AutoGenerateColumns="False" FontSize="14" SelectionMode="Extended"
+                               ScrollViewer.CanContentScroll="False" HorizontalScrollBarVisibility="Auto" SelectionChanged="FileDataGrid_SelectionChanged"
+                              MouseLeftButtonDown="FileDataGrid_MouseLeftButtonDown">
+                        <DataGrid.Columns>
+                            <DataGridTextColumn Header="File" Width="*" Binding="{Binding Name}" />
+                            <DataGridTextColumn Header="Size" Width="*" Binding="{Binding Size}" />
+                            <DataGridTextColumn Header="Location" Width="*" Binding="{Binding Path}" />
+                        </DataGrid.Columns>
+                        <DataGrid.Resources>
+                            <Style TargetType="DataGrid">
+                                <Setter Property="HorizontalGridLinesBrush" Value="#E6E6E6" />
+                                <Setter Property="VerticalGridLinesBrush" Value="#E6E6E6" />
+                            </Style>
+                            <Style TargetType="DataGridColumnHeader">
+                                <Setter Property="Foreground" Value="#666666" />
+                                <Setter Property="FontFamily" Value="Segoe UI" />
+                                <Setter Property="FontSize" Value="12" />
+                            </Style>
+                            <Style TargetType="DataGridCell">
+                                <Setter Property="FontFamily" Value="Segoe UI" />
+                                <Setter Property="FontSize" Value="12" />
+                                <Setter Property="Foreground" Value="#666666" />
+                                <Setter Property="BorderThickness" Value="0"></Setter>
+                                <Style.Triggers>
+                                    <Trigger Property="IsSelected" Value="True">
+                                        <Setter Property="Background" Value="#0078D7" />
+                                        <Setter Property="Foreground" Value="White" />
+                                    </Trigger>
+                                </Style.Triggers>
+                            </Style>
+                        </DataGrid.Resources>
+                    </DataGrid>
+                </Grid>
+                <StackPanel Grid.Row="1" Orientation="Horizontal">
+                    <Button x:Name="RemoveBtn" FontFamily="Segoe UI" FontSize="14" Content="Remove All" Width="112" Height="32" HorizontalAlignment="Left" Click="RemoveBtn_Click"></Button>
+                </StackPanel>
+            </Grid>
+        </Border>
+    </Grid>
+</UserControl>

+ 177 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListControl.xaml.cs

@@ -0,0 +1,177 @@
+using ComPDFKit.PDFDocument;
+using Compdfkit_Tools.Common;
+using Compdfkit_Tools.Helper;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+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.Data;
+using System.Windows.Documents;
+using System.Windows.Forms;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using DataGrid = System.Windows.Controls.DataGrid;
+using UserControl = System.Windows.Controls.UserControl;
+
+namespace Compdfkit_Tools.PDFControl
+{
+    /// <summary>
+    /// Interaction logic for RemoveWatermarkListControl.xaml
+    /// </summary>
+    public partial class RemoveWatermarkListControl : UserControl, INotifyPropertyChanged
+    {
+        private int _fileNumText;
+        public int FileNumText
+        {
+            get => _fileNumText;
+            set
+            {
+                if (UpdateProper(ref _fileNumText, value))
+                    IsEnsure = _fileNumText > 0;
+            }
+        }
+
+        private ObservableCollection<FileInfoWithRange> _fileInfoDataList;
+        public ObservableCollection<FileInfoWithRange> FileInfoDataList
+        {
+            get { return _fileInfoDataList; }
+            set
+            {
+                _fileInfoDataList = value;
+                _fileInfoDataList.CollectionChanged += (sender, args) =>
+                {
+                    FileNumText = _fileInfoDataList.Count;
+                };
+            }
+        }
+
+        public static readonly DependencyProperty IsEnsureProperty =
+DependencyProperty.Register(nameof(IsEnsure), typeof(bool), typeof(RemoveWatermarkListControl), new PropertyMetadata(false));
+
+
+        public bool IsEnsure
+        {
+            get => (bool)GetValue(IsEnsureProperty);
+            private set
+            {
+                SetValue(IsEnsureProperty, value);
+            }
+        }
+
+        public RemoveWatermarkListControl()
+        {
+            InitializeComponent();
+            DataContext = this;
+        }
+
+        private void UserControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            FileInfoDataList = new ObservableCollection<FileInfoWithRange>();
+            FileDataGrid.ItemsSource = FileInfoDataList;
+        }
+
+        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 AddFilesBtn_Click(object sender, RoutedEventArgs e)
+        {
+            var openFileDialog = new OpenFileDialog();
+            openFileDialog.Multiselect = true;
+            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
+            if (openFileDialog.ShowDialog() == DialogResult.OK)
+            {
+                foreach (string filePath in openFileDialog.FileNames)
+                {
+                    CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
+                    if (document.IsLocked)
+                    {
+                        PasswordWindow passwordWindow = new PasswordWindow();
+                        passwordWindow.InitWithDocument(document);
+                        passwordWindow.Owner = Window.GetWindow(this);
+                        passwordWindow.PasswordDialog.SetShowText(filePath + " is encrypted.");
+                        passwordWindow.ShowDialog();
+                        if (document.IsLocked)
+                        {
+                            document.Release();
+                            continue;
+                        }
+                    }
+
+                    List<int> pageRangeList = new List<int>();
+                    for (int i = 0; i < document.PageCount; i++)
+                    {
+                        pageRangeList.Add(i + 1);
+                    }
+
+                    FileInfoDataList.Add(new FileInfoWithRange
+                    {
+                        Document = document,
+                        Name = document.FileName,
+                        Size = CommonHelper.GetFileSize(filePath),
+                        Path = document.FilePath,
+                        PageRangeList = pageRangeList
+                    });
+                }
+            }
+        }
+
+        private void RemoveBtn_Click(object sender, RoutedEventArgs e)
+        {
+            if (FileDataGrid.SelectedItems.Count == 0)
+            {
+                foreach(var item in FileInfoDataList)
+                {
+                    item.Document.Release();
+                }
+                FileInfoDataList.Clear();
+                return;
+            }
+            var selectedItems = FileDataGrid.SelectedItems;
+            var selectedItemsList = selectedItems.Cast<FileInfoWithRange>().ToList();
+
+            foreach (var item in selectedItemsList)
+            {
+                item.Document.Release();
+                FileInfoDataList.Remove(item);
+            }
+        }
+
+        private void FileDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            var dataGrid = sender as DataGrid;
+            if (dataGrid != null)
+            {
+                RemoveBtn.Content = dataGrid.SelectedItems.Count > 0 ? "Remove" : "Remove All";
+            }
+        }
+
+        private void FileDataGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            FileDataGrid.UnselectAll();
+        }
+    }
+}

+ 22 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListDialog.xaml

@@ -0,0 +1,22 @@
+<Window x:Class="Compdfkit_Tools.PDFControl.RemoveWatermarkListDialog"
+        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"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
+        mc:Ignorable="d"
+        Title="RemoveWatermarkListDialog" Height="522" Width="516" ShowInTaskbar="False" ResizeMode="NoResize">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition></RowDefinition>
+            <RowDefinition Height="auto"></RowDefinition>
+        </Grid.RowDefinitions>
+        <local:RemoveWatermarkListControl x:Name="RemoveWatermarkListControl"></local:RemoveWatermarkListControl>
+        <Grid Grid.Row="1">
+            <StackPanel Orientation="Horizontal" Margin="0,24,24,12" HorizontalAlignment="Right">
+                <Button x:Name="ApplyBtn" Content="Apply" Height="32" Width="112" IsEnabled="{Binding ElementName=FileGridListWithPageRangeControl, Path=IsEnsure}" Margin="0,0,8,0" Click="ApplyBtn_Click"></Button>
+                <Button x:Name="CancelBtn" Height="32" Content="Cancel" Width="112" Click="CancelBtn_Click"></Button>
+            </StackPanel>
+        </Grid>
+    </Grid>
+</Window>

+ 64 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/RemoveWatermark/RemoveWatermarkListDialog.xaml.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Forms;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using Path = System.IO.Path;
+
+namespace Compdfkit_Tools.PDFControl { 
+    /// <summary>
+    /// Interaction logic for RemoveWatermarkListDialog.xaml
+    /// </summary>
+    public partial class RemoveWatermarkListDialog : Window
+    {
+        public RemoveWatermarkListDialog()
+        {
+            InitializeComponent();
+        }
+
+        private void CancelBtn_Click(object sender, RoutedEventArgs e)
+        { 
+            Close();
+        }
+
+        private void ApplyBtn_Click(object sender, RoutedEventArgs e)
+        {
+            var dialog = new FolderBrowserDialog();
+            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
+            {
+                return;
+            }
+            else
+            {
+                var path = dialog.SelectedPath;
+                foreach (var fileInfo in RemoveWatermarkListControl.FileInfoDataList)
+                {
+                    fileInfo.Document.DeleteWatermarks();
+                    string savePath = Path.Combine(path, Path.GetFileNameWithoutExtension(fileInfo.Document.FileName) + "_RemoveWatermark.pdf");
+                    fileInfo.Document.WriteToFilePath(savePath);
+                }
+                System.Diagnostics.Process.Start(path);
+                Close();
+            }
+        }
+
+        protected override void OnClosed(EventArgs e)
+        {
+            foreach (var fileInfo in RemoveWatermarkListControl.FileInfoDataList)
+            {
+                fileInfo.Document.Release();
+            }
+            base.OnClosed(e);
+        }
+    }
+}

+ 0 - 43
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListDialog.xaml.cs

@@ -1,43 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
-
-namespace Compdfkit_Tools.PDFControl
-{
-    /// <summary>
-    /// Interaction logic for WatermarkListDialog.xaml
-    /// </summary>
-    public partial class WatermarkListDialog : Window
-    {
-        public WatermarkListDialog()
-        {
-            InitializeComponent();
-        }
-
-        private void NextBtn_Click(object sender, RoutedEventArgs e)
-        {
-            WatermarkDialog watermarkDialog = new WatermarkDialog
-            {
-                Owner = this
-            };
-            if (watermarkDialog.InitWithFileInfo(FileGridListWithPageRangeControl.FileForDisplay))
-            {
-                watermarkDialog.ShowDialog();
-            }
-            else
-            {
-                MessageBox.Show("No file selected.");
-            }
-        }
-    }
-}

+ 5 - 4
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkOperationTypeDialog.xaml.cs

@@ -13,16 +13,17 @@ namespace Compdfkit_Tools.PDFControl
 
 
         private void Confirm_Click(object sender, RoutedEventArgs e)
         private void Confirm_Click(object sender, RoutedEventArgs e)
         {
         {
-            WatermarkListDialog watermarkListDialog = new WatermarkListDialog(); 
             if (AddWatermarkRdo.IsChecked == true)
             if (AddWatermarkRdo.IsChecked == true)
             {
             {
-               
+                WatermarkListDialog watermarkListDialog = new WatermarkListDialog();
+                OpenNewDialog(watermarkListDialog);
+
             }
             }
             else if (RemoveWatermarkRdo.IsChecked == true)
             else if (RemoveWatermarkRdo.IsChecked == true)
             {
             {
-                
+                RemoveWatermarkListDialog removeWatermarkListDialog = new RemoveWatermarkListDialog();
+                OpenNewDialog(removeWatermarkListDialog);
             }
             }
-            OpenNewDialog(watermarkListDialog);
         }
         }
 
 
         private void OpenNewDialog(Window newDialog)
         private void OpenNewDialog(Window newDialog)