Parcourir la source

compdfkit(win) - 更换sdk license,部分bug修复

liuaoran il y a 1 an
Parent
commit
32ccdde87f

+ 1 - 20
Demo/Examples/AnnotationViewControl/App.xaml.cs

@@ -1,30 +1,11 @@
 using ComPDFKit.NativeMethod;
+using Compdfkit_Tools.Helper;
 using System.Reflection;
 using System.Windows;
 using System.Xml;
 
 namespace AnnotationViewControl
 {
-    public class SDKLicenseHelper
-    {
-        public string key = string.Empty;
-        public string secret = string.Empty;
-        public SDKLicenseHelper()
-        {
-
-            string sdkLicensePath = "license_key_windows.xml";
-            Assembly assembly = Assembly.GetExecutingAssembly();
-            XmlDocument xmlDocument = new XmlDocument();
-            xmlDocument.Load(sdkLicensePath);
-            var node = xmlDocument.SelectSingleNode("License");
-            if (node != null)
-            {
-                key = node.Attributes["key"].Value;
-                secret = node.Attributes["secret"].Value;
-            }
-        }
-
-    }
     /// <summary>
     /// Interaction logic for App.xaml
     /// </summary>

+ 11 - 2
Demo/Examples/Compdfkit_Tools/Common/Helper/CommonHelper.cs

@@ -124,11 +124,20 @@ namespace Compdfkit_Tools.Helper
         public static string GetExistedPathOrEmpty(string filter = "PDF files (*.pdf)|*.pdf")
         {
             string selectedFilePath = string.Empty;
-            OpenFileDialog openFileDialog = new OpenFileDialog
+            OpenFileDialog openFileDialog;
+            try
+            {
+                openFileDialog = new OpenFileDialog
+                {
+                    Filter = filter
+                };
+            }
+            catch
             {
-                Filter = filter
+                return string.Empty;
             };
 
+
             if (openFileDialog.ShowDialog() == true)
             {
                 selectedFilePath = openFileDialog.FileName;

+ 18 - 11
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -2,8 +2,8 @@
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using System;
-using System.ComponentModel; 
-using System.Runtime.CompilerServices; 
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
@@ -14,7 +14,7 @@ using Compdfkit_Tools.Helper;
 using ComPDFKit.PDFAnnotation.Form;
 
 namespace Compdfkit_Tools.PDFControl
-{ 
+{
     public partial class DigitalSignatureControl : UserControl, INotifyPropertyChanged
     {
         private bool isFirstLoad = true;
@@ -26,6 +26,7 @@ namespace Compdfkit_Tools.PDFControl
         private bool _isActive = false;
         public event EventHandler<bool> OnCanSaveChanged;
         private CPDFSignatureWidget currentSignatureWidget;
+        public event EventHandler<string> AfterFillSignature;
 
         public event PropertyChangedEventHandler PropertyChanged;
         protected void OnPropertyChanged([CallerMemberName] string name = null)
@@ -106,7 +107,7 @@ namespace Compdfkit_Tools.PDFControl
 
             PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
             PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
-            
+
             panelState.PropertyChanged -= PanelState_PropertyChanged;
             panelState.PropertyChanged += PanelState_PropertyChanged;
 
@@ -152,9 +153,15 @@ namespace Compdfkit_Tools.PDFControl
                 SignatureWidget = currentSignatureWidget,
                 Document = PDFViewControl.PDFView.Document
             };
+            fillDigitalSignatureDialog.AfterFillSignature += FillDigitalSignatureDialog_AfterFillSignature; ;
             fillDigitalSignatureDialog.ShowDialog();
         }
 
+        private void FillDigitalSignatureDialog_AfterFillSignature(object sender, string e)
+        {
+            AfterFillSignature?.Invoke(this, e);
+        }
+
         private void DigitalSignatureBarControl_DigitalSignatureActionChanged(object sender, Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction e)
         {
             if (e == Common.CPDFDigitalSignatureBarControl.DigitalSignatureAction.AddSignatureField)
@@ -206,7 +213,7 @@ namespace Compdfkit_Tools.PDFControl
             PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
             PDFViewControl.PDFView.SetFormFieldHighlight(true);
         }
-        
+
         private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
@@ -217,7 +224,7 @@ namespace Compdfkit_Tools.PDFControl
             {
                 if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
                 {
-                    ExpandRightPropertyPanel((IsActive)?displaySettingsControl:null, Visibility.Visible);
+                    ExpandRightPropertyPanel((IsActive) ? displaySettingsControl : null, Visibility.Visible);
                 }
                 else
                 {
@@ -242,14 +249,14 @@ namespace Compdfkit_Tools.PDFControl
                 BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
             }
         }
-        
+
         public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
         {
             PropertyContainer.Width = 260;
             PropertyContainer.Child = propertytPanel;
             PropertyContainer.Visibility = visible;
         }
-        
+
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
         {
             this.BotaContainer.Child = botaControl;
@@ -257,12 +264,12 @@ namespace Compdfkit_Tools.PDFControl
             this.botaControl.DeleteSignatureEvent -= BotaControlOnDeleteSignatureEvent;
             this.botaControl.DeleteSignatureEvent += BotaControlOnDeleteSignatureEvent;
         }
-        
+
         public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
         {
             this.displaySettingsControl = displaySettingsControl;
         }
-        
+
         public void SetSignatureStatusBarControl(SignatureStatusBarControl signatureStatusBarControl)
         {
             this.signatureStatusBarControl = signatureStatusBarControl;
@@ -276,7 +283,7 @@ namespace Compdfkit_Tools.PDFControl
                 SignatureStatusBorder.Visibility = Visibility.Collapsed;
             }
         }
-        
+
         /// <summary>
         /// Undo Redo Event Noitfy
         /// </summary>

+ 1 - 1
Demo/Examples/Compdfkit_Tools/DigitalSignature/FillDigitalSignatureControl/FillDigitalSignatureControl.xaml

@@ -207,7 +207,7 @@
 
                     <Button Grid.Column="2" Height="32" Width="82" Style="{StaticResource LightButtonStyle}" Background="#DFE9FF" 
                             BorderThickness="0" Click="CanvasPopupClose_Click">Cancel</Button>
-                    <Button Grid.Column="3" Margin="10,0,25,0" Height="32" Width="97" Style="{StaticResource ButtonStyle}">OK</Button>
+                    <Button Grid.Column="3" Click="CanvasPopupConfirm_Click" Margin="10,0,25,0" Height="32" Width="97" Style="{StaticResource ButtonStyle}">OK</Button>
 
                 </Grid>
             </Grid>

+ 53 - 13
Demo/Examples/Compdfkit_Tools/DigitalSignature/FillDigitalSignatureControl/FillDigitalSignatureControl.xaml.cs

@@ -8,6 +8,7 @@ using Compdfkit_Tools.Helper;
 using System;
 using System.Collections.Generic;
 using System.Drawing;
+using System.IO;
 using System.Reflection;
 using System.Runtime.Remoting.Messaging;
 using System.Windows;
@@ -29,6 +30,10 @@ namespace Compdfkit_Tools.PDFControl
     /// </summary>
     public partial class FillDigitalSignatureControl : UserControl
     {
+
+        private readonly string logoPath = "Logo.png";
+        private string imagePath = string.Empty;
+        private string Text = string.Empty;
         private Dictionary<string, Border> TabDict { get; set; }
 
         private CPDFSignatureConfig tempSignatureConfig = new CPDFSignatureConfig();
@@ -37,13 +42,15 @@ namespace Compdfkit_Tools.PDFControl
 
         public CPDFDocument Document;
 
+        private string signatureName = string.Empty;
+
         private string location = string.Empty;
 
         private string reason = string.Empty;
 
         private string _signaturePath = string.Empty;
         public string SignaturePath
-        { 
+        {
             get => _signaturePath;
             set
             {
@@ -59,16 +66,15 @@ namespace Compdfkit_Tools.PDFControl
             {
                 _password = value;
                 signatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path(SignaturePath, Password);
-                tempSignatureConfig.Text = DictionaryValueConverter.GetGrantorFormDictionary(signatureCertificate.SubjectDict);
+                signatureName = DictionaryValueConverter.GetGrantorFormDictionary(signatureCertificate.SubjectDict);
+                tempSignatureConfig.Text = signatureName;
                 CreateTempSignature();
             }
         }
 
         public CPDFSignatureWidget signatureWidget { get; set; }
 
-        private readonly string logoPath = "Logo.png";
-        private string imagePath = string.Empty;
-        private string Text = string.Empty;
+        public event EventHandler<string> AfterFillSignature;
 
         public FillDigitalSignatureControl()
         {
@@ -170,23 +176,26 @@ namespace Compdfkit_Tools.PDFControl
             {
                 tempSignatureConfig.IsDrawOnlyContent = false;
                 if (clickBorder == KeyboardBorder)
-                { 
+                {
+                    tempSignatureConfig.Text = signatureName;
                     tempSignatureConfig.ImageBitmap = null;
                 }
                 else
-                { 
+                {
+                    tempSignatureConfig.Text = string.Empty;
                     if (clickBorder == TrackpadBorder)
                     {
                         CanvaDrawPopup.Visibility = Visibility.Visible;
                     }
                     else if (clickBorder == ImageBorder)
                     {
+                        ImagePickPanel.Visibility = Visibility.Visible;
                         if (!string.IsNullOrEmpty(imagePath))
                         {
                             tempSignatureConfig.ImageBitmap = new Bitmap(imagePath);
                         }
                     }
-                } 
+                }
             }
             SetProperty();
             CreateTempSignature();
@@ -221,9 +230,18 @@ namespace Compdfkit_Tools.PDFControl
         private void CanvasClearBtn_Click(object sender, RoutedEventArgs e)
         {
             DrawInkCanvas.Strokes.Clear();
+
         }
 
-        public void GetDrawInk()
+        private void CanvasPopupConfirm_Click(object sender, RoutedEventArgs e)
+        {
+            tempSignatureConfig.ImageBitmap = GetDrawInk();
+            CanvaDrawPopup.Visibility = Visibility.Collapsed;
+            SetProperty();
+            CreateTempSignature();
+        }
+
+        public Bitmap GetDrawInk()
         {
             if (DrawInkCanvas != null && DrawInkCanvas.Strokes != null && DrawInkCanvas.Strokes.Count > 0)
             {
@@ -263,6 +281,18 @@ namespace Compdfkit_Tools.PDFControl
 
                 RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bound.Width, (int)bound.Height, 96, 96, PixelFormats.Pbgra32);
                 renderBitmap.Render(drawVisual);
+                BitmapFrame newFrame = BitmapFrame.Create(renderBitmap);
+                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
+                pngEncoder.Frames.Add(newFrame);
+                using (MemoryStream newStream = new MemoryStream())
+                {
+                    pngEncoder.Save(newStream);
+                    return new Bitmap(newStream);
+                }
+            }
+            else
+            {
+                return null;
             }
         }
 
@@ -357,13 +387,19 @@ namespace Compdfkit_Tools.PDFControl
             string pngPath = CommonHelper.GetExistedPathOrEmpty("PNG files (*.png)|*.png");
             if (!string.IsNullOrEmpty(pngPath))
             {
-                imagePath = CommonHelper.GetExistedPathOrEmpty(pngPath);
+                imagePath = pngPath;
+                tempSignatureConfig.ImageBitmap = new Bitmap(imagePath);
+                SetProperty();
+                CreateTempSignature();
             }
         }
 
         private void ClearTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             imagePath = string.Empty;
+            tempSignatureConfig.ImageBitmap = null;
+            SetProperty();
+            CreateTempSignature();
         }
 
         private void NameChk_Click(object sender, RoutedEventArgs e)
@@ -451,8 +487,8 @@ namespace Compdfkit_Tools.PDFControl
         }
 
         private void ContinueBtn_Click(object sender, RoutedEventArgs e)
-        { 
-            string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", Document.FileName+ "_Signed.pdf");
+        {
+            string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", Document.FileName + "_Signed.pdf");
 
             if (string.IsNullOrEmpty(filePath))
             {
@@ -479,7 +515,11 @@ namespace Compdfkit_Tools.PDFControl
 
             signatureWidget.UpdataApWithSignature(tempSignatureConfig);
 
-            Document.WriteSignatureToFilePath(signatureWidget, filePath, SignaturePath, Password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone);
+            if (Document.WriteSignatureToFilePath(signatureWidget, filePath, SignaturePath, Password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
+            {
+                AfterFillSignature?.Invoke(sender, filePath);
+            }
+
             CloseWindow(sender);
         }
 

+ 9 - 0
Demo/Examples/Compdfkit_Tools/DigitalSignature/FillDigitalSignatureControl/FillDigitalSignatureDialog.xaml.cs

@@ -65,9 +65,18 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
 
+        public event EventHandler<string> AfterFillSignature;
+
         public FillDigitalSignatureDialog()
         {
             InitializeComponent();
+            FillDigitalSignatureControl.AfterFillSignature -= ReloadAfterFillSignature;
+            FillDigitalSignatureControl.AfterFillSignature += ReloadAfterFillSignature;
+        }
+
+        private void ReloadAfterFillSignature(object sender, string e)
+        {
+            AfterFillSignature?.Invoke(sender, e);
         }
     }
 }

+ 3 - 22
Demo/Examples/ContentEditorViewControl/App.xaml.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.NativeMethod;
+using Compdfkit_Tools.Helper;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
@@ -8,28 +9,10 @@ using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Xml;
+using static ComPDFKit.NativeMethod.CPDFSDKVerifier;
 
 namespace ContentEditorViewControl
 {
-    public class SDKLicenseHelper
-    {
-        public string key = string.Empty;
-        public string secret = string.Empty;
-        public SDKLicenseHelper()
-        {
-
-            string sdkLicensePath = "license_key_windows.xml";
-            Assembly assembly = Assembly.GetExecutingAssembly();
-            XmlDocument xmlDocument = new XmlDocument();
-            xmlDocument.Load(sdkLicensePath);
-            var node = xmlDocument.SelectSingleNode("License");
-            if (node != null)
-            {
-                key = node.Attributes["key"].Value;
-                secret = node.Attributes["secret"].Value;
-            }
-        }
-    }
      
     public partial class App : Application
     {
@@ -42,9 +25,7 @@ namespace ContentEditorViewControl
 
         private static bool LicenseVerify()
         {
-            bool result = false;
-
-            result = CPDFSDKVerifier.LoadNativeLibrary();
+            bool result = LoadNativeLibrary();
             if (!result)
                 return false;
 

+ 1 - 1
Demo/Examples/ContentEditorViewControl/ContentEditorViewControl.csproj

@@ -120,7 +120,7 @@
   <ItemGroup>
     <None Include="..\license_key_windows.xml">
       <Link>license_key_windows.xml</Link>
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 1 - 1
Demo/Examples/DigitalSignature/DigitalSignature.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{DD286D3B-0690-43D7-A3BA-AF8680FAD301}</ProjectGuid>
     <OutputType>WinExe</OutputType>
     <RootNamespace>DigitalSignature</RootNamespace>
-    <AssemblyName>Forms_ComPDFKit</AssemblyName>
+    <AssemblyName>Digital Signature_ComPDFKit</AssemblyName>
     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

+ 12 - 2
Demo/Examples/DigitalSignature/MainWindow.xaml.cs

@@ -100,13 +100,23 @@ namespace DigitalSignature
         {
             InitializeComponent();
             DataContext = this;
+            digitalSignatureControl.AfterFillSignature -= DigitalSignatureControl_AfterFillSignature;
+            digitalSignatureControl.AfterFillSignature += DigitalSignatureControl_AfterFillSignature;
+        }
+
+        private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
+        {
+            OpenFile(e);
         }
 
         #region Load Document
 
-        private void OpenFile()
+        private void OpenFile(string filePath = "")
         {
-            string filePath = CommonHelper.GetExistedPathOrEmpty();
+            if (string.IsNullOrEmpty(filePath))
+            {
+                filePath = CommonHelper.GetExistedPathOrEmpty();
+            }
             string oldFilePath = pdfViewer.PDFView.Document.FilePath;
 
             if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)

+ 4 - 22
Demo/Examples/DocsEditControl/App.xaml.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.NativeMethod;
+using Compdfkit_Tools.Helper;
 using System;
 using System.Collections.Generic;
 using System.Configuration;
@@ -8,29 +9,11 @@ using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Xml;
+using static ComPDFKit.NativeMethod.CPDFSDKVerifier;
+
 
 namespace DocsEditControl
 {
-    public class SDKLicenseHelper
-    {
-        public string key = string.Empty;
-        public string secret = string.Empty;
-        public SDKLicenseHelper()
-        {
-
-            string sdkLicensePath = "license_key_windows.xml";
-            Assembly assembly = Assembly.GetExecutingAssembly();
-            XmlDocument xmlDocument = new XmlDocument();
-            xmlDocument.Load(sdkLicensePath);
-            var node = xmlDocument.SelectSingleNode("License");
-            if (node != null)
-            {
-                key = node.Attributes["key"].Value;
-                secret = node.Attributes["secret"].Value;
-            }
-        }
-    }
-
     /// <summary>
     /// App.xaml 的交互逻辑
     /// </summary>
@@ -45,8 +28,7 @@ namespace DocsEditControl
 
         private static bool LicenseVerify()
         {
-            bool result = false;
-            result = CPDFSDKVerifier.LoadNativeLibrary();
+            bool result = LoadNativeLibrary();
             if (!result)
                 return false;
 

+ 2 - 2
Demo/Examples/DocsEditControl/DocsEditControl.csproj

@@ -117,10 +117,10 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <None Include="..\license_key_windows.xml">
+    <Content Include="..\license_key_windows.xml">
       <Link>license_key_windows.xml</Link>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
+    </Content>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="..\packages\ComPDFKit.NetFramework.1.9.1\build\ComPDFKit.NetFramework.targets" Condition="Exists('..\packages\ComPDFKit.NetFramework.1.9.1\build\ComPDFKit.NetFramework.targets')" />

+ 1 - 1
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -310,7 +310,7 @@ namespace PDFViewer
 
             if(pdfViewer!=null && pdfViewer.PDFView!=null)
             {
-                pdfViewer.PDFView.ToolManager.EnableClickCreate = false;
+               // pdfViewer.PDFView.ToolManager.EnableClickCreate = false;
             }
 
             if (currentMode == "Viewer")

+ 1 - 3
Demo/Examples/Viewer/App.xaml.cs

@@ -23,9 +23,7 @@ namespace Viewer
 
         private static bool LicenseVerify()
         {
-            bool result = false;
-
-            result = CPDFSDKVerifier.LoadNativeLibrary();
+            bool result = LoadNativeLibrary();
             if (!result)
                 return false;
 

+ 8 - 6
Demo/Examples/Viewer/Viewer.csproj

@@ -41,12 +41,6 @@
     <ApplicationIcon>ComPDFKit_Logo.ico</ApplicationIcon>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="ComPDFKit.Desk, Version=1.9.1.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\ComPDFKit.NetFramework.1.9.1\lib\ComPDFKit.Desk.dll</HintPath>
-    </Reference>
-    <Reference Include="ComPDFKit.Viewer, Version=1.9.1.0, Culture=neutral, processorArchitecture=MSIL">
-      <HintPath>..\packages\ComPDFKit.NetFramework.1.9.1\lib\ComPDFKit.Viewer.dll</HintPath>
-    </Reference>
     <Reference Include="PresentationFramework.Aero2, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <HintPath>..\packages\PresentationFramework.Aero2.1.0.1\lib\PresentationFramework.Aero2.dll</HintPath>
     </Reference>
@@ -122,6 +116,14 @@
     <Resource Include="ComPDFKit_Logo.ico" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\..\..\..\compdfkit\ComPDFKit\ComPDFKitCSharp\ComPDFKit.Desk.csproj">
+      <Project>{56e518ad-c126-4b48-9a09-0a64c87020e4}</Project>
+      <Name>ComPDFKit.Desk</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\..\..\compdfkit\ComPDFKit\ComPDFKitDesktop\ComPDFKit.Viewer\ComPDFKit.Viewer.csproj">
+      <Project>{18ec356d-8130-49d4-b4e6-ac290e1065b7}</Project>
+      <Name>ComPDFKit.Viewer</Name>
+    </ProjectReference>
     <ProjectReference Include="..\Compdfkit_Tools\Compdfkit_Tools.csproj">
       <Project>{9363bcb1-3a67-446a-8093-5708b86bf418}</Project>
       <Name>Compdfkit_Tools</Name>

Fichier diff supprimé car celui-ci est trop grand
+ 5 - 5
Demo/Examples/license_key_windows.xml