Ver código fonte

compdfkit(win) - 密码弹窗增加权限密码选项

liuaoran 1 ano atrás
pai
commit
cd69e4e67d

+ 11 - 6
Demo/Examples/Compdfkit_Tools/Common/HomePage/HomePageControl.xaml.cs

@@ -1,5 +1,4 @@
-using Compdfkit_Tools.Encryption;
-using System;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -56,14 +55,21 @@ namespace Compdfkit_Tools.PDFControl
 
         private void FeaturesListControl_SelectionChanged(object sender, CustomItem e)
         {
+            var parentWindow = Window.GetWindow(this);
+
             switch (e.TitleText)
             {
                 case "Watermark":
-                    MessageBox.Show(e.TitleText + " is under development.");
-                    break;
+                    {
+                        WatermarkOperationTypeDialog watermarkOperationTypeDialog = new WatermarkOperationTypeDialog()
+                        {
+                            Owner = parentWindow
+                        };
+                        watermarkOperationTypeDialog.ShowDialog();
+                        break;
+                    }
                 case "Security":
                     {
-                        var parentWindow = Window.GetWindow(this);
                         SecurityOperationTypeDialog securityOperationTypeDialog = new SecurityOperationTypeDialog()
                         {
                             Owner = parentWindow
@@ -75,7 +81,6 @@ namespace Compdfkit_Tools.PDFControl
                     MessageBox.Show(e.TitleText + " is under development.");
                     break;
             }
-
         }
 
 

+ 28 - 5
Demo/Examples/Compdfkit_Tools/Common/PasswordControl/PasswordWindow.xaml.cs

@@ -6,6 +6,12 @@ using ComPDFKit.PDFDocument;
 
 namespace Compdfkit_Tools.Common
 {
+    public enum PasswordType : byte
+    {
+        UserPassword,
+        OwnerPassword
+    }
+
     /// <summary>
     /// Interaction logic for PasswordWindow.xaml
     /// </summary>
@@ -13,6 +19,7 @@ namespace Compdfkit_Tools.Common
     {
         private CPDFDocument document;
 
+        public PasswordType PasswordType = PasswordType.UserPassword;
         public delegate void DialogCloseEventHandler(object sender, PasswordEventArgs e);
         public event DialogCloseEventHandler DialogClosed;
 
@@ -55,16 +62,32 @@ namespace Compdfkit_Tools.Common
         {
             if (document != null)
             {
-                document.UnlockWithPassword(e);
-                if (document.IsLocked == false)
+                if(PasswordType == PasswordType.UserPassword)
                 {
-                    PasswordEventArgs passwordEventArgs = new PasswordEventArgs(e);
-                    CloseWindow(passwordEventArgs);
+                    document.UnlockWithPassword(e);
+                    if (document.IsLocked == false)
+                    {
+                        PasswordEventArgs passwordEventArgs = new PasswordEventArgs(e);
+                        CloseWindow(passwordEventArgs);
+                    }
+                    else
+                    {
+                        PasswordDialog.SetShowError("Wrong Password", Visibility.Visible);
+                    }
                 }
                 else
                 {
-                    PasswordDialog.SetShowError("Wrong Password", Visibility.Visible);
+                    if (document.CheckOwnerPassword(e))
+                    {
+                        PasswordEventArgs passwordEventArgs = new PasswordEventArgs(e);
+                        CloseWindow(passwordEventArgs);
+                    }
+                    else
+                    {
+                        PasswordDialog.SetShowError("Wrong Password", Visibility.Visible);
+                    }
                 }
+
             }
         }
 

+ 21 - 0
Demo/Examples/Compdfkit_Tools/Compdfkit_Tools.csproj

@@ -466,6 +466,15 @@
     <Compile Include="PDFView\PDFScaling\PDFScalingUI\CPDFScalingUI.xaml.cs">
       <DependentUpon>CPDFScalingUI.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Security\Watermark\FileGridListWithPageRangeControl.xaml.cs">
+      <DependentUpon>FileGridListWithPageRangeControl.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Security\Watermark\WatermarkListControl.xaml.cs">
+      <DependentUpon>WatermarkListControl.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Security\Watermark\WatermarkOperationTypeDialog.xaml.cs">
+      <DependentUpon>WatermarkOperationTypeDialog.xaml</DependentUpon>
+    </Compile>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -991,7 +1000,19 @@
       <Generator>MSBuild:Compile</Generator>
     </Page>
     <Page Include="PDFView\RegularViewerControl.xaml" />
+    <Page Include="Security\Watermark\FileGridListWithPageRangeControl.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Security\Watermark\WatermarkListControl.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Security\Watermark\WatermarkOperationTypeDialog.xaml">
+      <SubType>Designer</SubType>
+    </Page>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="..\packages\ComPDFKit.NetFramework.1.10.0\build\ComPDFKit.NetFramework.targets" Condition="Exists('..\packages\ComPDFKit.NetFramework.1.10.0\build\ComPDFKit.NetFramework.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 1 - 2
Demo/Examples/Compdfkit_Tools/Security/Encryption/FileGridListControl.xaml.cs

@@ -47,7 +47,7 @@ namespace Compdfkit_Tools.PDFControl
         public event PropertyChangedEventHandler PropertyChanged;
         public event EventHandler FileNumChanged;
         
-        ObservableCollection<FileInfoData> _fileInfoDataList;
+        private ObservableCollection<FileInfoData> _fileInfoDataList;
 
         public ObservableCollection<FileInfoData> FileInfoDataList
         {
@@ -81,7 +81,6 @@ namespace Compdfkit_Tools.PDFControl
             dialog.Multiselect = true;
             dialog.Filter = @"PDF Files (*.pdf)|*.pdf";
             dialog.ShowDialog();
-            dialog.Multiselect = true;
 
             foreach (var fileName in dialog.FileNames)
             {

+ 2 - 2
Demo/Examples/Compdfkit_Tools/Security/Encryption/SecurityOperationTypeDialog.xaml

@@ -1,9 +1,9 @@
-<Window x:Class="Compdfkit_Tools.Encryption.SecurityOperationTypeDialog"
+<Window x:Class="Compdfkit_Tools.PDFControl.SecurityOperationTypeDialog"
         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.Encryption"
+        xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
         mc:Ignorable="d"
         ResizeMode="NoResize"
         ShowInTaskbar="False"

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Security/Encryption/SecurityOperationTypeDialog.xaml.cs

@@ -2,7 +2,7 @@ using System.Linq;
 using System.Windows;
 using Compdfkit_Tools.PDFControl;
 
-namespace Compdfkit_Tools.Encryption
+namespace Compdfkit_Tools.PDFControl
 {
     public partial class SecurityOperationTypeDialog : Window
     {

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

@@ -0,0 +1,88 @@
+<UserControl x:Class="Compdfkit_Tools.PDFControl.FileGridListWithPageRangeControl"
+             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" 
+             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">
+                        <DataGrid.Columns>
+                            <DataGridTextColumn Header="File" Width="*" Binding="{Binding FileName}" />
+                            <DataGridTextColumn Header="Size" Width="*" Binding="{Binding Size}" />
+                            <DataGridTextColumn Header="Page Range" Width="*" Binding="{Binding PageRange}" />
+                            <DataGridTextColumn Header="Location" Width="*" Binding="{Binding Location}" />
+                        </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>
+                    <Button x:Name="PageRangeBtn" FontFamily="Segoe UI" FontSize="14" Content="Page Range" Width="112" Height="32" HorizontalAlignment="Left" Margin="20,0,0,0" Click="PageRangeBtn_Click"></Button>
+                </StackPanel>
+            </Grid>
+        </Border>
+    </Grid>
+</UserControl>

+ 124 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/FileGridListWithPageRangeControl.xaml.cs

@@ -0,0 +1,124 @@
+using ComPDFKit.PDFDocument;
+using Compdfkit_Tools.Common;
+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 UserControl = System.Windows.Controls.UserControl;
+
+namespace Compdfkit_Tools.PDFControl
+{
+    /// <summary>
+    /// Interaction logic for FileGridListWithPageRangeControl.xaml
+    /// </summary>
+    public partial class FileGridListWithPageRangeControl : UserControl, INotifyPropertyChanged
+    {
+        public static readonly DependencyProperty IsEnsureProperty =
+    DependencyProperty.Register(nameof(IsEnsure), typeof(bool), typeof(FileGridListControl), new PropertyMetadata(false));
+
+
+        public bool IsEnsure
+        {
+            get => (bool)GetValue(IsEnsureProperty);
+            private set
+            {
+                SetValue(IsEnsureProperty, value);
+            }
+        }
+
+
+        private int _fileNumText;
+        public int FileNumText
+        {
+            get => _fileNumText;
+            set
+            {
+                if (UpdateProper(ref _fileNumText, value))
+                    IsEnsure = _fileNumText > 0;
+            }
+        }
+
+        private ObservableCollection<CPDFDocument> _fileInfoDataList;
+        public ObservableCollection<CPDFDocument> FileInfoDataList
+        {
+            get { return _fileInfoDataList; }
+            set
+            {
+                _fileInfoDataList = value;
+                _fileInfoDataList.CollectionChanged += (sender, args) =>
+                {
+                    FileNumText = _fileInfoDataList.Count;
+                };
+            }
+        }
+
+        public FileGridListWithPageRangeControl()
+        {
+            InitializeComponent();
+
+        }
+
+        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 dialog = new OpenFileDialog();
+            dialog.Multiselect = true;
+            dialog.Filter = "PDF Files (*.pdf)|*.pdf";
+            dialog.ShowDialog();
+
+            foreach (string filePath in dialog.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.PasswordDialog.SetShowText("Password error");
+                }
+            }
+
+        }
+
+        private void RemoveBtn_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+
+        private void PageRangeBtn_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+    }
+}

+ 12 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListControl.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="Compdfkit_Tools.Security.Watermark.WatermarkListControl"
+             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.Security.Watermark"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+            
+    </Grid>
+</UserControl>

+ 28 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkListControl.xaml.cs

@@ -0,0 +1,28 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace Compdfkit_Tools.Security.Watermark
+{
+    /// <summary>
+    /// Interaction logic for WatermarkListControl.xaml
+    /// </summary>
+    public partial class WatermarkListControl : UserControl
+    {
+        public WatermarkListControl()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 35 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkOperationTypeDialog.xaml

@@ -0,0 +1,35 @@
+<Window x:Class="Compdfkit_Tools.PDFControl.WatermarkOperationTypeDialog"
+        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"
+        ResizeMode="NoResize"
+        ShowInTaskbar="False"
+        WindowStartupLocation="CenterScreen"
+        Title="Operation Type" Height="214" Width="432">
+    <Grid Margin="10,20,5,0">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="104"></RowDefinition>
+            <RowDefinition Height="40"></RowDefinition>
+        </Grid.RowDefinitions>
+        <Grid Background="White" Margin="20,0,0,0"  Panel.ZIndex="1" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top">
+            <TextBlock Foreground="#001A4E" FontFamily="Segoe UI" Text="Watermark Type" FontWeight="DemiBold" FontSize="14"></TextBlock>
+        </Grid>
+        <Border Margin="0,10,7,12" BorderBrush="#33000000" BorderThickness="1">
+            <Grid Margin="10" VerticalAlignment="Center" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Border}}}">
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="*"></RowDefinition>
+                    <RowDefinition Height="*"></RowDefinition>
+                </Grid.RowDefinitions>
+                <RadioButton x:Name="AddWatermarkRdo" IsChecked="True" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="Add Watermarks"></RadioButton>
+                <RadioButton Grid.Row="1" x:Name="RemoveWatermarkRdo" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="Remove Watermarks"></RadioButton>
+            </Grid>
+        </Border>
+        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
+            <Button Content="Cancel" Width="112" Height="32" FontFamily="Segoe UI" FontSize="14" Click="Cancel_Click"></Button>
+            <Button Content="OK" Width="112" Height="32" FontFamily="Segoe UI" FontSize="14" Margin="10,0,10,0" Click="Confirm_Click"></Button>
+        </StackPanel>
+    </Grid>
+</Window>

+ 42 - 0
Demo/Examples/Compdfkit_Tools/Security/Watermark/WatermarkOperationTypeDialog.xaml.cs

@@ -0,0 +1,42 @@
+using System.Linq;
+using System.Windows;
+using Compdfkit_Tools.PDFControl;
+
+namespace Compdfkit_Tools.PDFControl
+{
+    public partial class WatermarkOperationTypeDialog : Window
+    {
+        public WatermarkOperationTypeDialog()
+        {
+            InitializeComponent();
+        }
+
+        private void Confirm_Click(object sender, RoutedEventArgs e)
+        {
+            if (AddWatermarkRdo.IsChecked == true)
+            {
+               
+            }
+            else if (RemoveWatermarkRdo.IsChecked == true)
+            {
+                
+            }
+            else
+            {
+                MessageBox.Show("Please select an operation type.");
+            }
+        }
+
+        private void OpenNewDialog(Window newDialog)
+        {
+            newDialog.Owner = this.Owner;
+            this.Close();
+            newDialog.ShowDialog();
+        }
+
+        private void Cancel_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+    }
+}