Browse Source

ComPDFKit.Tool(win) - 优化加密文档搜索验证密码逻辑

TangJinZhou 8 months ago
parent
commit
88400cf4a5
1 changed files with 4 additions and 6 deletions
  1. 4 6
      Demo/Examples/ComPDFKit.Tool/PDFTextSearch.cs

+ 4 - 6
Demo/Examples/ComPDFKit.Tool/PDFTextSearch.cs

@@ -5,11 +5,8 @@ using ComPDFKit.PDFPage;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
-using System.Threading.Tasks;
 using System.Windows.Media;
 using System.Windows;
 
@@ -152,18 +149,17 @@ namespace ComPDFKit.Tool
             double searchPercent = 100;
             try
             {
-
                 mSearchDocument = CPDFDocument.InitWithFilePath(TextSearchDocument.FilePath);
-                if (password != null && password != string.Empty)
+                if (mSearchDocument.IsLocked && !string.IsNullOrEmpty(password))
                 {
                     mSearchDocument.UnlockWithPassword(password);
                 }
-                password = string.Empty;
             }
             catch (Exception ex)
             {
 
             }
+
             if (mSearchDocument != null)
             {
                 try
@@ -232,6 +228,7 @@ namespace ComPDFKit.Tool
                 }
                 mSearchDocument.Release();
             }
+
             try
             {
                 if (SearchCompletedHandler != null && !isCancel)
@@ -248,6 +245,7 @@ namespace ComPDFKit.Tool
             {
 
             }
+
             CanDoSearch = true;
             isCancel = false;
         }