Browse Source

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng 2 years ago
parent
commit
0ec61f5530
25 changed files with 352 additions and 131 deletions
  1. 95 1
      PDF Office/Helper/SecurityHelper.cs
  2. 12 1
      PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogModel.cs
  3. 1 0
      PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/DeleteSafetySettintgsModel.cs
  4. 32 1
      PDF Office/StyleAndTemplateList.txt
  5. 19 12
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundTemplateListColorContentViewModel.cs
  6. 16 13
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundTemplateListFileContentViewModel.cs
  7. 12 7
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBates/HomePageBatesTemplateListContentViewModel.cs
  8. 12 7
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageHeaderFooter/HomePageHeaderFooterTemplateListContentViewModel.cs
  9. 10 6
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkTemplateListFileContentViewModel.cs
  10. 17 9
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkTemplateListTextContentViewModel.cs
  11. 3 1
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs
  12. 4 2
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContentViewModel.cs
  13. 3 2
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModPosterContentViewModel.cs
  14. 2 1
      PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogViewModel.cs
  15. 1 1
      PDF Office/ViewModels/EditTools/Background/BackgroundContentViewModel.cs
  16. 18 12
      PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListColorContentViewModel.cs
  17. 26 23
      PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListFileContentViewModel.cs
  18. 1 1
      PDF Office/ViewModels/EditTools/Bates/BatesContentViewModel.cs
  19. 13 7
      PDF Office/ViewModels/EditTools/Bates/BatesTemplateListContentViewModel.cs
  20. 1 1
      PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterContentViewModel.cs
  21. 11 7
      PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterTemplateListContentViewModel.cs
  22. 1 1
      PDF Office/ViewModels/EditTools/Watermark/WatermarkContentViewModel.cs
  23. 10 6
      PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListFileContentViewModel.cs
  24. 13 7
      PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListTextContentViewModel.cs
  25. 19 2
      PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

+ 95 - 1
PDF Office/Helper/SecurityHelper.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using PDF_Office.Model;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
@@ -31,7 +32,42 @@ namespace PDF_Office.Helper
             }
         }
 
-        public static bool VerifyPassword(CPDFDocument document ,EnumPasswordKind enumPasswordKind, IDialogService dialogService)
+        public static bool CheckHaveSelectedPermissions(CPDFDocument document, EnumPermissionsSet enumPermissionsSet)
+        {
+            CPDFPermissionsInfo permissionsInfo = document.GetPermissionsInfo();
+            ///如果需求这个权限
+           if(((enumPermissionsSet & EnumPermissionsSet.StatusAllowsDocumentChanges) == EnumPermissionsSet.StatusAllowsDocumentChanges ) && (!permissionsInfo.AllowsDocumentChanges))
+            {
+                    return false;
+            }
+           if(((enumPermissionsSet& EnumPermissionsSet.StatusAllowsPrinting) == EnumPermissionsSet.StatusAllowsPrinting) && (!permissionsInfo.AllowsPrinting))
+            {
+                return false;
+            }
+           if(((enumPermissionsSet&EnumPermissionsSet.StatusAllowsHighQualityPrinting) == EnumPermissionsSet.StatusAllowsHighQualityPrinting) && (!permissionsInfo.AllowsHighQualityPrinting))
+            {
+                return false;
+            }
+            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsCopying) == EnumPermissionsSet.StatusAllowsCopying)&& (!permissionsInfo.AllowsCopying))
+            {
+                return false;
+            }
+            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsDocumentAssembly) == EnumPermissionsSet.StatusAllowsDocumentAssembly) && (!permissionsInfo.AllowsDocumentAssembly))
+            {
+                return false;
+            }
+            if(((enumPermissionsSet&EnumPermissionsSet.StatusAllowsFormFieldEntry) == EnumPermissionsSet.StatusAllowsFormFieldEntry) && (!permissionsInfo.AllowsDocumentAssembly))
+            {
+                return false;
+            }
+            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsCommenting) == EnumPermissionsSet.StatusAllowsCommenting) && (!permissionsInfo.AllowsCommenting))
+            {
+                return false;
+            }
+            return true;
+        }
+
+        public static bool VerifyPasswordOnlyBool(CPDFDocument document ,EnumPasswordKind enumPasswordKind, IDialogService dialogService)
         {
             if (enumPasswordKind == EnumPasswordKind.StatusOpenPassword)
             {
@@ -61,5 +97,63 @@ namespace PDF_Office.Helper
             });
             return isDiscryptied;
         }
+
+        public static VerifyPasswordResult VerifyPasswordByPasswordKind(CPDFDocument document, EnumPasswordKind enumPasswordKind, IDialogService dialogService)
+        {
+            VerifyPasswordResult verifyPasswordResult  = new VerifyPasswordResult();
+            if ((!document.IsLocked)&&
+                ((enumPasswordKind == EnumPasswordKind.StatusOpenPassword)||
+                (enumPasswordKind == EnumPasswordKind.StatusPermissionsPassword)&& CheckHaveAllPermissions(document)))
+            {
+                verifyPasswordResult.IsDiscryptied = true;
+                verifyPasswordResult.Password = null;
+                return verifyPasswordResult;
+            }
+
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.PasswordKind, EnumPasswordKind.StatusPermissionsPassword);
+            value.Add(ParameterNames.PDFDocument, document);
+            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
+                verifyPasswordResult.IsDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
+                verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password);
+            });
+            return verifyPasswordResult;
+        }
+
+        public static VerifyPasswordResult VerifyPasswordForSelectedPermissions(CPDFDocument document, EnumPermissionsSet enumPermissionsSet, IDialogService dialogService)
+        {
+            VerifyPasswordResult verifyPasswordResult = new VerifyPasswordResult();
+            if ((!document.IsLocked) &&CheckHaveSelectedPermissions(document, enumPermissionsSet))
+            {
+                verifyPasswordResult.IsDiscryptied = true;
+                verifyPasswordResult.Password = null;
+                return verifyPasswordResult;
+            }
+
+            DialogParameters value = new DialogParameters();
+            if (enumPermissionsSet == EnumPermissionsSet.None)
+            {
+                value.Add(ParameterNames.PasswordKind, EnumPasswordKind.StatusOpenPassword);
+
+            }
+            else
+            {
+                value.Add(ParameterNames.PasswordKind, EnumPasswordKind.StatusPermissionsPassword);
+            }
+            value.Add(ParameterNames.PDFDocument, document);
+            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
+                verifyPasswordResult.IsDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
+                verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password);
+            });
+            return verifyPasswordResult;
+        }
+    }
+
+
+
+    public class VerifyPasswordResult
+    {
+        public bool IsDiscryptied;
+        public string Password;
     }
 }

+ 12 - 1
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogModel.cs

@@ -9,5 +9,16 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
     public class CheckPasswordDialogModel
     {
     }
-
+    public enum EnumPermissionsSet
+    {
+        None = 0,
+        StatusAllowsDocumentChanges = 1<<1,
+        StatusAllowsPrinting = 1 <<2,
+        StatusAllowsHighQualityPrinting = 1<<3,
+        StatusAllowsCopying = 1<<4,
+        StatusAllowsDocumentAssembly = 1<<5,
+        StatusAllowsFormFieldEntry  = 1<<6,
+        StatusAllowsCommenting = 1<<7
+    }
+    
 }

+ 1 - 0
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/DeleteSafetySettintgsModel.cs

@@ -20,5 +20,6 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
             StatusOpenPassword,
             StatusPermissionsPassword
         }
+
     }
 }

+ 32 - 1
PDF Office/StyleAndTemplateList.txt

@@ -55,4 +55,35 @@
 位置:PDF Office\CustomControl\BatchStatus.xaml
 用途:批量处理进度显示
 使用方法:StatusValue{设置等于,"complete"(显示绿色背景勾形符号)、"error"(显示红色背景感叹符号)、
-"wait"(显示等待闹钟)、"为数字时"(显示进度条)}
+"wait"(显示等待闹钟)、"为数字时"(显示进度条)}
+
+8.CheckPasswordDialog
+位置:PDF Office\Views\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialog.xaml
+用途:  密码校验
+使用方法
+```C# 
+  VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+  //或 VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, PermissionsSubset, dialogs);
+                if (result.IsDiscryptied)
+                {
+                    if (result.Password != null)
+                    {
+                        string filePath = PDFViewer.Document.FilePath;
+                        PDFViewer.Document.Release();
+                        PDFViewer.InitDocument(filePath);
+                        PDFViewer.Document.UnlockWithPassword(result.Password);
+                    }
+                   ///TODO:
+                   ///此处填入需要执行的代码
+                }
+```
+备注:  
+SecurityHelper.VerifyPasswordByPasswordKind需要传入的参数:PDFViewer.Document,需要验证的密码类型(开启密码/权限密码),当前ViewModel的IDialogService对象
+ecurityHelper.VerifyPasswordForSelectedPermissions需要传入的参数:PDFViewer.Document, 需要验证的权限子集(形如 枚举1|枚举2|枚举3),当前ViewModel的IDialogService对象。
+返回值result对象包含两个成员:IsDiscryptied标志是否可以解锁/提权,Password对象标志当前正确的密码,当密码为空时表示当前无需输入。
+IsDiscryptied == false  解锁/提权失败,拒绝下一步
+IsDiscryptied == true password == null; 当前无需解锁/提权,不会显示输入密码弹窗,直接进行下一步
+IsDiscryptied == true  password != null; 提权/解锁成功,共用当前PDFView的同权限级别操作全部开放,不再需要校验
+* 下一步 *指解锁后的具体业务操作,例如唤起需求复制权限的弹窗等
+
+

+ 19 - 12
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundTemplateListColorContentViewModel.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.PDFDocument;
+using Microsoft.Office.Interop.Word;
 using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
@@ -169,22 +170,28 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.BackgroundTemplateList.Count != 0)
+            List<BackgroundItem> removebackgroundItems = new List<BackgroundItem>();
+            for (int i = 0; i < Settings.Default.BackgroundTemplateList.Count;i++)
             {
-                int temp = 0;
-                var template = Settings.Default.BackgroundTemplateList[temp];
-                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
+                var template = Settings.Default.BackgroundTemplateList[i];
+                
+                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR)
                 {
-                    if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
-                    {
-                        Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
-                    }
+                    removebackgroundItems.Add(template);
+                    
+                }
+            }
+            foreach (var removetemplate in removebackgroundItems)
+            {
+                if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
+                {
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
+                }
 
-                    Settings.Default.BackgroundTemplateList.Remove(template);
-                    Settings.Default.Save();
+                Settings.Default.BackgroundTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
 
-                    BackgroundModColorCollection.Remove(template);
-                }
+                BackgroundModColorCollection.Remove(removetemplate);
             }
             GetBackgroundSource();
         }

+ 16 - 13
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundTemplateListFileContentViewModel.cs

@@ -175,26 +175,29 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.BackgroundTemplateList.Count != 0)
+            List<BackgroundItem> removebackgroundItems = new List<BackgroundItem>();
+            for (int i = 0; i < Settings.Default.BackgroundTemplateList.Count; i++)
             {
-                int temp = 0;
+                var template = Settings.Default.BackgroundTemplateList[i];
 
-                var template = Settings.Default.BackgroundTemplateList[temp];
-                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR)
+                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
                 {
+                    removebackgroundItems.Add(template);
 
-                    if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath))
-                    {
-                        Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
-                    }
-
-                    Settings.Default.BackgroundTemplateList.Remove(template);
-                    Settings.Default.Save();
-
-                    BackgroundModFileCollection.Remove(template);
                 }
             }
+            foreach (var removetemplate in removebackgroundItems)
+            {
+                if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
+                {
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
+                }
+
+                Settings.Default.BackgroundTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
 
+                BackgroundModFileCollection.Remove(removetemplate);
+            }
             GetBackgroundSource();
         }
 

+ 12 - 7
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBates/HomePageBatesTemplateListContentViewModel.cs

@@ -128,7 +128,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteTemplateItem(object e)
         {
-            var btn = e as System.Windows.Controls.Button;
+            var btn = e as System.Windows.Controls.Control;
             if (btn == null)
             {
                 return;
@@ -147,16 +147,21 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.BatesTemplateList.Count != 0)
+            List<BatesHeaderFooterItem> removebatesItems = new List<BatesHeaderFooterItem>();
+            for (int i = 0; i < Settings.Default.BatesTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.BatesTemplateList[temp];
 
-                Settings.Default.BatesTemplateList.Remove(template);
-                Settings.Default.Save();
+                var template = Settings.Default.BatesTemplateList[i];
+                removebatesItems.Add(template);
+
 
-                BatesModCollection.Remove(template);
+            }
+            foreach (var removetemplate in removebatesItems)
+            {
+                Settings.Default.BatesTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
 
+                BatesModCollection.Remove(removetemplate);
             }
             GetBatesSource();
         }

+ 12 - 7
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageHeaderFooter/HomePageHeaderFooterTemplateListContentViewModel.cs

@@ -20,6 +20,7 @@ using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.
 using ComPDFKit.PDFDocument;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
 using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark;
+using Microsoft.Office.Interop.Word;
 
 namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter
 {
@@ -127,7 +128,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteTemplateItem(object e)
         {
-            var btn = e as System.Windows.Controls.Button;
+            var btn = e as System.Windows.Controls.Control;
             if (btn == null)
             {
                 return;
@@ -146,16 +147,20 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.HeaderFooterTemplateList.Count != 0)
+            List<BatesHeaderFooterItem> removeheaderfooterItems = new List<BatesHeaderFooterItem>();
+            for (int i = 0; i < Settings.Default.HeaderFooterTemplateList.Count;i++)
             {
-                int temp = 0;
-                var template = Settings.Default.HeaderFooterTemplateList[temp];
+                var template = Settings.Default.HeaderFooterTemplateList[i];
+                removeheaderfooterItems.Add(template);
+                
 
-                Settings.Default.HeaderFooterTemplateList.Remove(template);
+            }
+            foreach (var removetemplate in removeheaderfooterItems)
+            {
+                Settings.Default.HeaderFooterTemplateList.Remove(removetemplate);
                 Settings.Default.Save();
 
-                HeaderFooterModCollection.Remove(template);
-
+                HeaderFooterModCollection.Remove(removetemplate);
             }
             GetHeaderFooterSource();
         }

+ 10 - 6
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkTemplateListFileContentViewModel.cs

@@ -160,17 +160,21 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            List<WatermarkItem> removewatermarkItems = new List<WatermarkItem>();
+            for (int i = 0; i < Settings.Default.WatermarkTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.WatermarkTemplateList[temp];
+                var template = Settings.Default.WatermarkTemplateList[i];
                 if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
                 {
-                    Settings.Default.WatermarkTemplateList.Remove(template);
-                    Settings.Default.Save();
-                    WatermarkModFileCollection.Remove(template);
+                    removewatermarkItems.Add(template);
                 }
             }
+            foreach (var removetemplate in removewatermarkItems)
+            {
+                Settings.Default.WatermarkTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
+                WatermarkModFileCollection.Remove(removetemplate);
+            }
             GetWatermarkSource();
         }
 

+ 17 - 9
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkTemplateListTextContentViewModel.cs

@@ -149,22 +149,29 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         }
 
+
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            List<WatermarkItem> removewatermarkItems = new List<WatermarkItem>();
+            for (int i = 0; i < Settings.Default.WatermarkTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.WatermarkTemplateList[temp];
-                if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
+
+                var template = Settings.Default.WatermarkTemplateList[i];
+                if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_TEXT)
                 {
-                    Settings.Default.WatermarkTemplateList.Remove(template);
-                    Settings.Default.Save();
-                    WatermarkModTextCollection.Remove(template);
+                    removewatermarkItems.Add(template);
                 }
             }
+            foreach (var removetemplate in removewatermarkItems)
+            {
+                Settings.Default.WatermarkTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
+                WatermarkModTextCollection.Remove(removetemplate);
+            }
             GetWatermarkSource();
         }
 
+
         public void RequestEditTemplateItem(object e)
         {
             var control = e as Control;
@@ -251,8 +258,9 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public void SendTemplateItemToDocument(WatermarkItem WatermarkItem)
         {
-            if (WatermarkItem != null) {
-                homePageWatermarkDialogViewModel.CreateBtnIsEnabled=true;
+            if (WatermarkItem != null)
+            {
+                homePageWatermarkDialogViewModel.CreateBtnIsEnabled = true;
                 ConvertItemToInfo(WatermarkItem, ref WatermarkInfo);
                 homePageWatermarkDialogViewModel.WatermarkInfo = WatermarkInfo;
                 for (int i = 0; homePageWatermarkDialogViewModel.PDFDataTable.Rows.Count > i; i++)

+ 3 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs

@@ -394,7 +394,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     {
                         PrintOrientationIndex = 1;
                     }
-                    this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode }); 
+                    this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
                 }
             }
             else
@@ -897,6 +897,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 {
                     isCurrentPage = false;
                 }
+                System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
+
                 NavigationParameters param = new NavigationParameters();
                 NavigateDocumentRegion();
                 NavigateModRegion();

+ 4 - 2
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContentViewModel.cs

@@ -335,7 +335,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 }
                 catch
                 {
-                    MessageBoxEx.Show("另一个进程正在占用该打印机");
+                    MessageBoxEx.Show("另一个进程正在占用该打印机或发生未知错误");
                 }
             }
         }
@@ -654,7 +654,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                             string sign = null;
                             if (posterInfo.Label == null || posterInfo.Label == "")
                             {
-                                sign = string.Format("({0},{1}){2}.pdf {3} {4}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PrintIndex + 1, System.DateTime.Today.ToString("yyyy-MM-dd"), System.DateTime.Now.ToString("HH:mm:ss"));
+                                sign = string.Format("({0},{1})  -{2} -{3}.pdf {4} {5}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PrintIndex + 1, PDFViewer.Document.FileName, System.DateTime.Today.ToString("yyyy/MM/dd"), System.DateTime.Now.ToString("HH:mm:ss"));
                             }
                             else
                             {
@@ -716,6 +716,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     }
                     else
                     {
+                        HorizonPaperIndex = 0;
+                        VerticalPaperIndex = 0;
                         e.HasMorePages = false;
                     }
                 }

+ 3 - 2
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModPosterContentViewModel.cs

@@ -1,4 +1,5 @@
-using Microsoft.Office.Interop.Word;
+using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Interop.Word;
 using PDF_Office.EventAggregators;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
 using Prism.Commands;
@@ -343,7 +344,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            DefaultLabel = "(column, row) 1.pdf "+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            DefaultLabel = "(Column, Row) -Page -xxx.pdf - yyyy/mm/dd hh-mm-ss";
             navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
             SendPosterInfo();
         }

+ 2 - 1
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogViewModel.cs

@@ -147,7 +147,8 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
         private void Cancel()
         {
             var dialogResult = new DialogResult(ButtonResult.Cancel);
-            dialogResult.Parameters.Add("CheckPassword", false);
+            dialogResult.Parameters.Add(ParameterNames.Password, null);
+            dialogResult.Parameters.Add(ParameterNames.PasswordResult, false);
             RequestClose.Invoke(dialogResult);
         }
 

+ 1 - 1
PDF Office/ViewModels/EditTools/Background/BackgroundContentViewModel.cs

@@ -235,7 +235,7 @@ namespace PDF_Office.ViewModels.EditTools.Background
             HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
             HomePageBatchProcessingDialogModel.BatchProcessingIndex = 4;
             backgroundpdf.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
-            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, backgroundpdf, e => { });
+            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, backgroundpdf, e => { EnterSelectedContent(TemplateListBaseName); });
         }
 
         public void EnterDocumentContent()

+ 18 - 12
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListColorContentViewModel.cs

@@ -172,23 +172,29 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.BackgroundTemplateList.Count != 0)
+            List<BackgroundItem> removebackgroundItems = new List<BackgroundItem>();
+            for (int i = 0; i < Settings.Default.BackgroundTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.BackgroundTemplateList[temp];
-                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
-                {
-                    if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
-                    {
-                        Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
-                    }
+                var template = Settings.Default.BackgroundTemplateList[i];
 
-                    Settings.Default.BackgroundTemplateList.Remove(template);
-                    Settings.Default.Save();
+                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR)
+                {
+                    removebackgroundItems.Add(template);
 
-                    BackgroundModColorCollection.Remove(template);
                 }
             }
+            foreach (var removetemplate in removebackgroundItems)
+            {
+                if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
+                {
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
+                }
+
+                Settings.Default.BackgroundTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
+
+                BackgroundModColorCollection.Remove(removetemplate);
+            }
             GetBackgroundSource();
         }
 

+ 26 - 23
PDF Office/ViewModels/EditTools/Background/BackgroundTemplateListFileContentViewModel.cs

@@ -170,29 +170,32 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         }
 
-        public void DeleteAllTemplateItem()
-        {
-            while (Settings.Default.BackgroundTemplateList.Count != 0)
-            {
-                int temp = 0;
-
-                var template = Settings.Default.BackgroundTemplateList[temp];
-                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_COLOR)
-                {
-
-                    if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath))
-                    {
-                        Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
-                    }
-
-                    Settings.Default.BackgroundTemplateList.Remove(template);
-                    Settings.Default.Save();
-
-                    BackgroundModFileCollection.Remove(template);
-                }
-            }
-
-            GetBackgroundSource();
+        public void DeleteAllTemplateItem()
+        {
+            List<BackgroundItem> removebackgroundItems = new List<BackgroundItem>();
+            for (int i = 0; i < Settings.Default.BackgroundTemplateList.Count; i++)
+            {
+                var template = Settings.Default.BackgroundTemplateList[i];
+
+                if (template.type == ComPDFKit.PDFDocument.C_Background_Type.BG_TYPE_IMAGE)
+                {
+                    removebackgroundItems.Add(template);
+
+                }
+            }
+            foreach (var removetemplate in removebackgroundItems)
+            {
+                if (!string.IsNullOrEmpty(BackgroundItem.previewImagePath) && File.Exists(BackgroundItem.previewImagePath))
+                {
+                    Settings.Default.AppProperties.NeedToDeletePath.Add(BackgroundItem.previewImagePath);
+                }
+
+                Settings.Default.BackgroundTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
+
+                BackgroundModFileCollection.Remove(removetemplate);
+            }
+            GetBackgroundSource();
         }
 
         public void ConvertItemToInfo(BackgroundItem backgroundItem, ref BackgroundInfo backgroundInfo)

+ 1 - 1
PDF Office/ViewModels/EditTools/Bates/BatesContentViewModel.cs

@@ -137,7 +137,7 @@ namespace PDF_Office.ViewModels.EditTools.Bates
             HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
             HomePageBatchProcessingDialogModel.BatchProcessingIndex = 6;
             bates.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
-            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, bates, e => { });
+            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, bates, e => { EnterSelectedContent(TemplateListName); });
         }
 
         public void EnterSelectedContent(string SelectedContentName)

+ 13 - 7
PDF Office/ViewModels/EditTools/Bates/BatesTemplateListContentViewModel.cs

@@ -1,4 +1,5 @@
 using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Interop.Word;
 using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model;
@@ -126,7 +127,7 @@ namespace PDF_Office.ViewModels.EditTools.Bates
 
         public void DeleteTemplateItem(object e)
         {
-            var btn = e as System.Windows.Controls.Button;
+            var btn = e as System.Windows.Controls.Control;
             if (btn == null)
             {
                 return;
@@ -145,16 +146,21 @@ namespace PDF_Office.ViewModels.EditTools.Bates
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.BatesTemplateList.Count != 0)
+            List<BatesHeaderFooterItem> removebatesItems = new List<BatesHeaderFooterItem>();
+            for (int i = 0; i < Settings.Default.BatesTemplateList.Count;i++)
             {
-                int temp = 0;
-                var template = Settings.Default.BatesTemplateList[temp];
+         
+                var template = Settings.Default.BatesTemplateList[i];
+                removebatesItems.Add(template);
+                
 
-                Settings.Default.BatesTemplateList.Remove(template);
+            }
+            foreach (var removetemplate in removebatesItems)
+            {
+                Settings.Default.BatesTemplateList.Remove(removetemplate);
                 Settings.Default.Save();
 
-                BatesModCollection.Remove(template);
-
+                BatesModCollection.Remove(removetemplate);
             }
             GetBatesSource();
         }

+ 1 - 1
PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterContentViewModel.cs

@@ -138,7 +138,7 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
             HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
             HomePageBatchProcessingDialogModel.BatchProcessingIndex = 5;
             headerFooterpdf.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
-            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, headerFooterpdf, e => { });
+            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, headerFooterpdf, e => { EnterSelectedContent(TemplateListName); });
         }
 
         public void EnterSelectedContent(string SelectedContentName)

+ 11 - 7
PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterTemplateListContentViewModel.cs

@@ -123,7 +123,7 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
 
         public void DeleteTemplateItem(object e)
         {
-            var btn = e as System.Windows.Controls.Button;
+            var btn = e as System.Windows.Controls.Control;
             if (btn == null)
             {
                 return;
@@ -142,16 +142,20 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.HeaderFooterTemplateList.Count != 0)
+            List<BatesHeaderFooterItem> removeheaderfooterItems = new List<BatesHeaderFooterItem>();
+            for (int i = 0; i < Settings.Default.HeaderFooterTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.HeaderFooterTemplateList[temp];
+                var template = Settings.Default.HeaderFooterTemplateList[i];
+                removeheaderfooterItems.Add(template);
 
-                Settings.Default.HeaderFooterTemplateList.Remove(template);
-                Settings.Default.Save();
 
-                HeaderFooterModCollection.Remove(template);
+            }
+            foreach (var removetemplate in removeheaderfooterItems)
+            {
+                Settings.Default.HeaderFooterTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
 
+                HeaderFooterModCollection.Remove(removetemplate);
             }
             GetHeaderFooterSource();
         }

+ 1 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkContentViewModel.cs

@@ -246,7 +246,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             HomePageBatchProcessingDialogModel.FilePaths = new List<string> { PDFViewer.Document.FilePath.ToString() };
             HomePageBatchProcessingDialogModel.BatchProcessingIndex = 3;
             watermarkpdf.Add(ParameterNames.FilePath, new string[] { PDFViewer.Document.FilePath.ToString() });
-            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, watermarkpdf, e => { });
+            dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, watermarkpdf, e => { EnterSelectedContent(TemplateListName); });
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)

+ 10 - 6
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListFileContentViewModel.cs

@@ -167,17 +167,21 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            List<WatermarkItem> removewatermarkItems = new List<WatermarkItem>();
+            for (int i = 0; i < Settings.Default.WatermarkTemplateList.Count; i++)
             {
-                int temp = 0;
-                var template = Settings.Default.WatermarkTemplateList[temp];
+                var template = Settings.Default.WatermarkTemplateList[i];
                 if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
                 {
-                    Settings.Default.WatermarkTemplateList.Remove(template);
-                    Settings.Default.Save();
-                    WatermarkModFileCollection.Remove(template);
+                    removewatermarkItems.Add(template);
                 }
             }
+            foreach (var removetemplate in removewatermarkItems)
+            {
+                Settings.Default.WatermarkTemplateList.Remove(removetemplate);
+                Settings.Default.Save();
+                WatermarkModFileCollection.Remove(removetemplate);
+            }
             GetWatermarkSource();
         }
 

+ 13 - 7
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListTextContentViewModel.cs

@@ -18,6 +18,7 @@ using PDF_Office.Model;
 using PDF_Office.Helper;
 using PDF_Office.Model.EditTools.Background;
 using PDF_Office.ViewModels.Tools;
+using Microsoft.Office.Interop.Word;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
@@ -149,17 +150,22 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
 
         public void DeleteAllTemplateItem()
         {
-            while (Settings.Default.WatermarkTemplateList.Count != 0)
+            List<WatermarkItem> removewatermarkItems=new List<WatermarkItem>();
+            for (int i=0; i<Settings.Default.WatermarkTemplateList.Count;i++)
             {
-                int temp = 0;
-                var template = Settings.Default.WatermarkTemplateList[temp];
-                if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
+               
+                var template = Settings.Default.WatermarkTemplateList[i];
+                if (template.type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_TEXT)
                 {
-                    Settings.Default.WatermarkTemplateList.Remove(template);
-                    Settings.Default.Save();
-                    WatermarkModTextCollection.Remove(template);
+                    removewatermarkItems.Add(template);
                 }
             }
+            foreach (var removetemplate in removewatermarkItems)
+            {
+                Settings.Default.WatermarkTemplateList.Remove(removetemplate);
+                Settings.Default.Save(); 
+                WatermarkModTextCollection.Remove(removetemplate); 
+            }
             GetWatermarkSource();
         }
 

+ 19 - 2
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -3,6 +3,7 @@ using PDF_Office.CustomControl;
 using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
@@ -77,8 +78,16 @@ namespace PDF_Office.ViewModels.Tools
 
         private void OpenSetPasswordDialog()
         {
-            if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs))
+            VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsPrinting|EnumPermissionsSet.StatusAllowsHighQualityPrinting, dialogs);
+            if (result.IsDiscryptied)
             {
+                if (result.Password != null)
+                {
+                    string filePath = PDFViewer.Document.FilePath;
+                    PDFViewer.Document.Release();
+                    PDFViewer.InitDocument(filePath);
+                    PDFViewer.Document.UnlockWithPassword(result.Password);
+                }
                 DialogParameters value = new DialogParameters();
                 value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
                 dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
@@ -93,8 +102,16 @@ namespace PDF_Office.ViewModels.Tools
             }
             else
             {
-                if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs))
+                VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+                if (result.IsDiscryptied)
                 {
+                    if (result.Password != null)
+                    {
+                        string filePath = PDFViewer.Document.FilePath;
+                        PDFViewer.Document.Release();
+                        PDFViewer.InitDocument(filePath);
+                        PDFViewer.Document.UnlockWithPassword(result.Password);
+                    }
                     DialogParameters value = new DialogParameters();
                     value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
                     dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });