瀏覽代碼

打印 - 高保真 安全 - 部分(保存崩溃)

liuaoran 2 年之前
父節點
當前提交
8919bb09b2

二進制
PDF Office/ComPDFKit.Desk.dll


+ 34 - 23
PDF Office/Helper/SecurityHelper.cs

@@ -2,17 +2,28 @@
 using PDF_Office.Model;
 using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Management;
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
 
 namespace PDF_Office.Helper
 {
-    public  class SecurityHelper
+    public class SecurityHelper
     {
+        /// <summary>
+        /// 由全局变量储存是否修改过密码
+        /// </summary>
+        public static bool IsPasswordChanged = false;
+        /// <summary>
+        /// 全局变量储存修改后的密码
+        /// </summary>
+        public static class PasswordInfo
+        {
+            public static string OpenPassword = null;
+            public static string PermissionsPassword = null;
+            public static CPDFPermissionsInfo CPDFPermissionsInfo = CreateDefaultPermissionsInfo();
+        }
+
         public static bool CheckHaveAllPermissions(CPDFDocument document)
         {
             CPDFPermissionsInfo permissionsInfo = document.GetPermissionsInfo();
@@ -36,31 +47,31 @@ namespace PDF_Office.Helper
         {
             CPDFPermissionsInfo permissionsInfo = document.GetPermissionsInfo();
             ///如果需求这个权限
-           if(((enumPermissionsSet & EnumPermissionsSet.StatusAllowsDocumentChanges) == EnumPermissionsSet.StatusAllowsDocumentChanges ) && (!permissionsInfo.AllowsDocumentChanges))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsDocumentChanges) == EnumPermissionsSet.StatusAllowsDocumentChanges) && (!permissionsInfo.AllowsDocumentChanges))
             {
-                    return false;
+                return false;
             }
-           if(((enumPermissionsSet& EnumPermissionsSet.StatusAllowsPrinting) == EnumPermissionsSet.StatusAllowsPrinting) && (!permissionsInfo.AllowsPrinting))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsPrinting) == EnumPermissionsSet.StatusAllowsPrinting) && (!permissionsInfo.AllowsPrinting))
             {
                 return false;
             }
-           if(((enumPermissionsSet&EnumPermissionsSet.StatusAllowsHighQualityPrinting) == EnumPermissionsSet.StatusAllowsHighQualityPrinting) && (!permissionsInfo.AllowsHighQualityPrinting))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsHighQualityPrinting) == EnumPermissionsSet.StatusAllowsHighQualityPrinting) && (!permissionsInfo.AllowsHighQualityPrinting))
             {
                 return false;
             }
-            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsCopying) == EnumPermissionsSet.StatusAllowsCopying)&& (!permissionsInfo.AllowsCopying))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsCopying) == EnumPermissionsSet.StatusAllowsCopying) && (!permissionsInfo.AllowsCopying))
             {
                 return false;
             }
-            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsDocumentAssembly) == EnumPermissionsSet.StatusAllowsDocumentAssembly) && (!permissionsInfo.AllowsDocumentAssembly))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsDocumentAssembly) == EnumPermissionsSet.StatusAllowsDocumentAssembly) && (!permissionsInfo.AllowsDocumentAssembly))
             {
                 return false;
             }
-            if(((enumPermissionsSet&EnumPermissionsSet.StatusAllowsFormFieldEntry) == EnumPermissionsSet.StatusAllowsFormFieldEntry) && (!permissionsInfo.AllowsDocumentAssembly))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsFormFieldEntry) == EnumPermissionsSet.StatusAllowsFormFieldEntry) && (!permissionsInfo.AllowsDocumentAssembly))
             {
                 return false;
             }
-            if (((enumPermissionsSet&EnumPermissionsSet.StatusAllowsCommenting) == EnumPermissionsSet.StatusAllowsCommenting) && (!permissionsInfo.AllowsCommenting))
+            if (((enumPermissionsSet & EnumPermissionsSet.StatusAllowsCommenting) == EnumPermissionsSet.StatusAllowsCommenting) && (!permissionsInfo.AllowsCommenting))
             {
                 return false;
             }
@@ -94,10 +105,10 @@ namespace PDF_Office.Helper
         /// </returns>
         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 verifyPasswordResult = new VerifyPasswordResult();
+            if ((!document.IsLocked) &&
+                ((enumPasswordKind == EnumPasswordKind.StatusOpenPassword) ||
+                (enumPasswordKind == EnumPasswordKind.StatusPermissionsPassword) && CheckHaveAllPermissions(document)))
             {
                 verifyPasswordResult.IsDiscryptied = true;
                 verifyPasswordResult.Password = null;
@@ -107,7 +118,8 @@ namespace PDF_Office.Helper
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PasswordKind, enumPasswordKind);
             value.Add(ParameterNames.PDFDocument, document);
-            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
+            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e =>
+            {
                 verifyPasswordResult.IsDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
                 verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password);
             });
@@ -142,7 +154,7 @@ namespace PDF_Office.Helper
         public static VerifyPasswordResult VerifyPasswordForSelectedPermissions(CPDFDocument document, EnumPermissionsSet enumPermissionsSet, IDialogService dialogService)
         {
             VerifyPasswordResult verifyPasswordResult = new VerifyPasswordResult();
-            if ((!document.IsLocked) &&CheckHaveSelectedPermissions(document, enumPermissionsSet))
+            if ((!document.IsLocked) && CheckHaveSelectedPermissions(document, enumPermissionsSet))
             {
                 verifyPasswordResult.IsDiscryptied = true;
                 verifyPasswordResult.Password = null;
@@ -160,7 +172,8 @@ namespace PDF_Office.Helper
                 value.Add(ParameterNames.PasswordKind, EnumPasswordKind.StatusPermissionsPassword);
             }
             value.Add(ParameterNames.PDFDocument, document);
-            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
+            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e =>
+            {
                 verifyPasswordResult.IsDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
                 verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password);
             });
@@ -168,8 +181,6 @@ namespace PDF_Office.Helper
         }
     }
 
-
-
     public class VerifyPasswordResult
     {
         public bool IsDiscryptied;

+ 11 - 4
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogModel.cs

@@ -7,13 +7,12 @@ using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 
+
 namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
 {
     public class SetPasswordDialogModel
     {
-
-
-
+         
         public enum EnumNeedPassword
         {
             StatusNeedOpenPassword = 1 << 0,
@@ -55,10 +54,18 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
             }
             return permissionsInfo;
         }
-
         ///<returns>
         ///生成带有指定权限的CPDFPermissionsInfo对象
         ///</returns>
+    }
 
+    public class SecurityInfo
+    {
+        public bool IsPasswordChanged = false;
+        public bool NeedOpenPassword = false;
+        public bool NeedPermissionsPassword = false;
+        public string OpenPassword = null;
+        public string PermissionsPassword = null;
+        public CPDFPermissionsInfo CPDFPermissionsInfo = SetPasswordDialogModel.CreateDefaultPermissionsInfo();
     }
 }

+ 23 - 0
PDF Office/Styles/TextBoxStyle.xaml

@@ -77,4 +77,27 @@
             </MultiTrigger>
         </Style.Triggers>
     </Style>
+    
+    <Style x:Key="Print_normalTxtStyle" TargetType="TextBox">
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate>
+                    <Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
+                        <Border BorderBrush="{StaticResource color.field.border.norm}" Background="{StaticResource color.field.bg.def}" BorderThickness="1" CornerRadius="4">
+                            <ScrollViewer x:Name="PART_ContentHost" Focusable="false"
+                                                  HorizontalScrollBarVisibility="Hidden" 
+                                                  VerticalScrollBarVisibility="Hidden"
+                                                  VerticalAlignment="Center" MinHeight="22" Margin="8,0,0,0" Opacity="1"/>
+                        </Border>
+                    </Grid>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsEnabled" Value="False">
+                            <Setter Property="Opacity" Value="0.6"></Setter>
+                         </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
+
 </ResourceDictionary>

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

@@ -397,9 +397,12 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             {
                 PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
                 pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
+                pageSetupDialog.Document.DefaultPageSettings.Margins = new Margins((int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Left * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Right * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Top * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Bottom * 2.54));
+
                 if (pageSetupDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
+
                     if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
                     {
                         PrintOrientationIndex = 0;

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

@@ -109,7 +109,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         public DocumentSettingsInfo documentSettingsInfo = new DocumentSettingsInfo();
 
         /// <summary>
-        /// 用于判断是否需要跳转第一页
+        /// 记录打印设置改变前的总页数,用于判断是否需要跳转第一页,仅当总页数改变时跳转
         /// </summary>
         int PreviousPrintedPageCount = 0;
 

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

@@ -25,14 +25,14 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
             get { return _password; }
             set
             {
-                SetProperty(ref _password, value);
+                SetProperty(ref _password, value); 
                 IsRightValue = "unknow";
                 if (!string.IsNullOrEmpty(value)){
                     ClearPasswordButtonVisibility = Visibility.Visible;
                 }
                 else
                 {
-                    ClearPasswordButtonVisibility = Visibility.Collapsed;
+                    ClearPasswordButtonVisibility = Visibility.Hidden;
                 }
             }
         }
@@ -70,19 +70,19 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
                 }
                 else
                 {
-                    ErrorPasswordMsgVisibility = Visibility.Collapsed;
+                    ErrorPasswordMsgVisibility = Visibility.Hidden;
                 }
             }
         }
 
-        private Visibility _clearPasswordButtonVisibility = Visibility.Collapsed;
+        private Visibility _clearPasswordButtonVisibility = Visibility.Hidden;
         public Visibility ClearPasswordButtonVisibility
         {
             get { return _clearPasswordButtonVisibility; }
             set { SetProperty(ref _clearPasswordButtonVisibility, value); }
         }
 
-        private Visibility _errorPasswordMsgVisibility = Visibility.Collapsed;
+        private Visibility _errorPasswordMsgVisibility = Visibility.Hidden;
         public Visibility ErrorPasswordMsgVisibility
         {
             get { return _errorPasswordMsgVisibility; }

+ 67 - 25
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs

@@ -327,46 +327,88 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
             dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, setPasswordpdf, e => { });
         }
 
-
         public void Encrypt()
         {
-
-            string openPassword = "";
-            string permissionsPassword = "";
-
-            CPDFPermissionsInfo permissionsInfo = null;
-
-            if (NeedOpenPassword)
-            {
-                if (!string.IsNullOrEmpty(OpenPassword))
-                {
-                    openPassword = OpenPassword;
-                }
-            }
-            if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
+            viewContentViewModel.SecurityInfo.IsPasswordChanged = true;
+            if (NeedOpenPassword && (!string.IsNullOrEmpty(OpenPassword)))
             {
-                permissionsPassword = PermissionsPassword;
-                permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
+                this.viewContentViewModel.SecurityInfo.NeedOpenPassword = true;
+                this.viewContentViewModel.SecurityInfo.OpenPassword = OpenPassword;
             }
             else
             {
-                permissionsInfo = CreateDefaultPermissionsInfo();
+                this.viewContentViewModel.SecurityInfo.NeedOpenPassword = false;
+                viewContentViewModel.SecurityInfo.OpenPassword = null;
             }
-            cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
-           //cPDFViewer.ReloadDocument();
-            if (!string.IsNullOrEmpty(permissionsPassword) )
+
+            if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
             {
-                cPDFViewer.Document.UnlockWithPassword(permissionsPassword);
-                SecurityHelper.CheckHaveAllPermissions(cPDFViewer.Document);
+                this.viewContentViewModel.SecurityInfo.NeedPermissionsPassword = true;
+                viewContentViewModel.SecurityInfo.PermissionsPassword = PermissionsPassword;
+                viewContentViewModel.SecurityInfo.CPDFPermissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
             }
             else
             {
-                cPDFViewer.Document.UnlockWithPassword(openPassword);
+                this.viewContentViewModel.SecurityInfo.NeedPermissionsPassword = false;
+                viewContentViewModel.SecurityInfo.PermissionsPassword = null;
+                viewContentViewModel.SecurityInfo.CPDFPermissionsInfo = CreateDefaultPermissionsInfo();
             }
-            viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
             RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
         }
 
+        //public void Encrypt()
+        //{
+
+        //    string openPassword = "";
+        //    string permissionsPassword = "";
+
+        //    CPDFPermissionsInfo permissionsInfo = null;
+
+        //    if (NeedOpenPassword)
+        //    {
+        //        if (!string.IsNullOrEmpty(OpenPassword))
+        //        {
+        //            openPassword = OpenPassword;
+        //        }
+        //    }
+        //    if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
+        //    {
+        //        permissionsPassword = PermissionsPassword;
+        //        permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
+        //    }
+        //    else
+        //    {
+        //        permissionsInfo = CreateDefaultPermissionsInfo();
+        //    }
+
+        //    System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
+        //    /*
+        //     *设置这个对话框的起始保存路径
+        //     */
+        //    sfd.InitialDirectory = cPDFViewer.Document.FilePath;
+        //    /*
+        //     *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
+        //     */
+        //    sfd.Filter = "PDF|*.pdf;";
+        //    /*
+        //     *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
+        //     */
+        //    sfd.FileName = cPDFViewer.Document.FileName + "_EncryptedFile.pdf";
+        //    /*
+        //     * 做一些工作
+        //     */
+        //    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+        //    {
+        //        cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
+        //        cPDFViewer.Document.WriteToFilePath(sfd.FileName);
+        //        MessageBoxEx.Show("保存成功");
+        //        RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+        //    }
+        //    else
+        //    {
+        //    }
+        //}
+
 
         public void CancelEncrypt() => RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
 

+ 3 - 9
PDF Office/ViewModels/TipContent/FileRestrictedTipViewModel.cs

@@ -6,14 +6,7 @@ using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using static Dropbox.Api.Files.ThumbnailMode;
+using Prism.Services.Dialogs; 
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
 
 namespace PDF_Office.ViewModels.TipContent
@@ -50,7 +43,8 @@ namespace PDF_Office.ViewModels.TipContent
                 if (result.Password != null)
                 {
                     string filePath = PDFViewer.Document.FilePath;
-                    PDFViewer.ReloadDocument();
+                    PDFViewer.Document.Release();
+                    PDFViewer.InitDocument(filePath);
                     PDFViewer.Document.UnlockWithPassword(result.Password);
                 }
                 ///TODO:

+ 29 - 20
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -106,7 +106,8 @@ namespace PDF_Office.ViewModels.Tools
         {
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PDFViewer, PDFViewer);
-            dialogs.ShowDialog(DialogNames.CompressDialog, value, e => {
+            dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
+            {
 
                 OnOpened((Prism.Services.Dialogs.DialogResult)e);
             });
@@ -114,9 +115,9 @@ namespace PDF_Office.ViewModels.Tools
 
         private int GetIndex(int pageindex)
         {
-            PageIndex = (pageindex+1).ToString();
+            PageIndex = (pageindex + 1).ToString();
             App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
-            if (PageIndex == PageNumber) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;}
+            if (PageIndex == PageNumber) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
             return 0;
         }
         private void CompressClear()
@@ -131,8 +132,8 @@ namespace PDF_Office.ViewModels.Tools
             string filepath = "";
             string password = "";
             int compressquality = 45;
-           doc=e.Parameters.GetValue<CPDFDocument>(ParameterNames.PDFDocument);
-            filepath= e.Parameters.GetValue<string>(ParameterNames.FilePath);
+            doc = e.Parameters.GetValue<CPDFDocument>(ParameterNames.PDFDocument);
+            filepath = e.Parameters.GetValue<string>(ParameterNames.FilePath);
             password = e.Parameters.GetValue<string>(ParameterNames.PassWord);
             compressquality = e.Parameters.GetValue<int>("compressDialogModel.CompressQuality");
             if (doc != null)
@@ -160,28 +161,36 @@ namespace PDF_Office.ViewModels.Tools
 
         private void OpenSetPasswordDialog()
         {
-            PDFViewer.ReloadDocument();
-            bool a =  PDFViewer.Document.UnlockWithPassword("321");
-            VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
-            if (result.IsDiscryptied)
+            if (!viewContentViewModel.SecurityInfo.IsPasswordChanged)
             {
-                if (result.Password != null)
+                VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+                if (result.IsDiscryptied)
                 {
-                    PDFViewer.ReloadDocument();
-                    PDFViewer.Document.UnlockWithPassword(result.Password);
+                    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.PDFViewer,  this.PDFViewer);
-                value.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
+            }
 
-                dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.PDFViewer, this.PDFViewer);
+            value.Add(ParameterNames.ViewContentViewModel, this.viewContentViewModel);
+            dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
+            {
+                if (e.Result == ButtonResult.OK)
                 {
-                    if(e.Result == ButtonResult.OK)
+                    SecurityHelper.IsPasswordChanged = true;
+                    if (viewContentViewModel.SecurityInfo.IsPasswordChanged)
                     {
-                        this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully,  Unicode = unicode})  ;
+                        viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
                     }
-                });
-            }
+                    this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
+                }
+            });
         }
 
         private void OpenCancelPasswordDialog()

+ 35 - 13
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -3,32 +3,25 @@ using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 using ComPDFKitViewer.PdfViewer;
 using Prism.Regions;
-using DryIoc;
-using System.Diagnostics;
 using Prism.Services.Dialogs;
 using PDF_Office.CustomControl;
 using PDF_Office.Model;
 using System.Windows;
 using System.Windows.Controls;
 using System.IO;
-using PDFSettings;
 using ComPDFKitViewer.AnnotEvent;
 using PDF_Office.ViewModels.Tools;
-using PDF_Office.Views;
 using Prism.Events;
 using PDF_Office.EventAggregators;
-using PDF_Office.Views.EditTools.Background;
-using PDF_Office.Views.Dialog;
 using PDF_Office.Helper;
-using System.Security.Policy;
-using System.Windows.Documents;
 using ComPDFKit.PDFDocument;
 using PDFSettings.Settings;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
+
 
 namespace PDF_Office.ViewModels
 {
@@ -78,11 +71,12 @@ namespace PDF_Office.ViewModels
         public string ReadModeRegionName { get; set; }
 
         public string ConverterBarContentRegionName { get; set; }
+
         public string TextEditContentRegionName { get; set; }
 
         public string BackgroundContentRegionName { get; set; }
 
-        public List<Point>FillAndSign=new List<Point>();
+        public List<Point> FillAndSign = new List<Point>();
 
         /// <summary>
         /// 文档的密码
@@ -434,6 +428,8 @@ namespace PDF_Office.ViewModels
             }
         }
 
+        public SecurityInfo SecurityInfo = new SecurityInfo();
+
         private Dictionary<string, string> regionNameByTabItem;
 
         private Dictionary<string, string> barContentByTabItem;
@@ -620,7 +616,7 @@ namespace PDF_Office.ViewModels
                 region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
             }
         }
-        public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)  
+        public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
         {
             switch (showTipEventArgs.enumTipKind)
             {
@@ -1000,7 +996,7 @@ namespace PDF_Office.ViewModels
             if (pdfview != null)
             {
                 PDFViewer = pdfview;
-                if(pdfview.Tag!=null)
+                if (pdfview.Tag != null)
                 {
                     //保存密码
                     PassWord = pdfview.Tag.ToString();
@@ -1152,6 +1148,32 @@ namespace PDF_Office.ViewModels
                         return false;
                 }
 
+                if (SecurityInfo.IsPasswordChanged)
+                {
+                    string currentFilePath = PDFViewer.Document.FilePath;
+                    string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
+                    string openPassword = null;
+                    string permissionsPassword = null;
+                    CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
+                    if (SecurityInfo.NeedOpenPassword)
+                    {
+                        openPassword = SecurityInfo.OpenPassword;
+                    }
+
+                    if (SecurityInfo.NeedPermissionsPassword)
+                    {
+                        permissionsPassword = SecurityInfo.PermissionsPassword;
+                        cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
+                    }
+                    PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
+                    if (alertsMessage.result == ContentResult.Ok)
+                        return saveAsFile();
+                    else
+                        return false;
+                }
+
                 bool result = PDFViewer.Document.WriteToLoadedPath();
                 if (result)
                 {

File diff suppressed because it is too large
+ 105 - 26
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialog.xaml


+ 58 - 6
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContent.xaml

@@ -3,8 +3,62 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:prism="http://prismlibrary.com/" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              prism:ViewModelLocator.AutoWireViewModel="True" >
+    <UserControl.Resources>
+        <Style TargetType="Button" x:Key="PrePageBtnStyle">
+            <Setter Property="Height" Value="24"></Setter>
+            <Setter Property="Width" Value="24"></Setter>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type Button}">
+                        <Grid  x:Name="UserfulRegion">
+                            <Border BorderBrush="{StaticResource color.field.border.norm}" BorderThickness="1" CornerRadius="4" >
+                                <Grid>
+                                    <Rectangle Width="24" Height="24" Fill="Transparent"></Rectangle>
+                                    <Path x:Name="Path" Fill="{StaticResource color.icon.base.neutral.norm.lv1}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M3.11071 4.24945L5.43035 1.9298L4.36969 0.869141L0.769719 4.46912C0.476825 4.76201 0.476826 5.23688 0.769719 5.52978L4.36969 9.12975L5.43035 8.06909L3.11071 5.74945H14.5V4.24945H3.11071Z"></Path>
+                                </Grid>
+                            </Border>
+                        </Grid>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <Style TargetType="Button" x:Key="NextPageBtnStyle">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type Button}">
+                        <Grid  x:Name="UserfulRegion">
+                            <Border BorderBrush="{StaticResource color.field.border.norm}" BorderThickness="1" CornerRadius="4" >
+                                <Grid>
+                                    
+                                <Rectangle Width="24" Height="24" Fill="Transparent"></Rectangle>
+                                <Path x:Name="Path" Fill="{StaticResource color.icon.base.neutral.norm.lv1}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M11.8893 4.24992L0.5 4.24992V5.74992L11.8893 5.74992L9.56967 8.06958L10.6303 9.13024L14.2303 5.53026C14.5232 5.23737 14.5232 4.7625 14.2303 4.4696L10.6303 0.869629L9.56967 1.93029L11.8893 4.24992Z"></Path>
+                                </Grid>
+
+                            </Border>
+                        </Grid>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <Style TargetType="TextBox" x:Key="PageTxtStyle">
+            <Setter Property="Height" Value="24"></Setter>
+            <Setter Property="Width" Value="57"></Setter>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="TextBox">
+                        <Border BorderBrush="{StaticResource color.field.border.norm}" BorderThickness="1" Background="{StaticResource color.field.bg.def}" CornerRadius="4">
+                                    <ScrollViewer x:Name="PART_ContentHost" Focusable="false"
+                                                  HorizontalScrollBarVisibility="Hidden" 
+                                                  VerticalScrollBarVisibility="Hidden"
+                                                  VerticalAlignment="Center" MinHeight="20"/>
+                            </Border>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
     <Grid  Height="356" Width="212">
-        <Border Height="356" Width="212"  Background="#F7F8FA" HorizontalAlignment="Center" VerticalAlignment="Top">
+        <Border Height="356" Width="212"  Background="{StaticResource color.sys.layout.mg}" HorizontalAlignment="Center" VerticalAlignment="Top" CornerRadius="8">
             <Grid>
                 <Grid.RowDefinitions>
                     <RowDefinition Height="52"></RowDefinition>
@@ -29,10 +83,9 @@
                 </Border>
                 <Grid Grid.Row="2">
                     <StackPanel Orientation="Horizontal"   HorizontalAlignment="Center" VerticalAlignment="Center">
-                        <Button Name="PrePageBtn"   Width="20" Height="20" HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Command="{Binding TurnPageCommand}" CommandParameter="{Binding ElementName=PrePageBtn}">
-                            <TextBlock Text="&lt;" VerticalAlignment="Center"></TextBlock>
+                        <Button Name="PrePageBtn" Tag="PrePage" Style="{StaticResource PrePageBtnStyle}" Height="24" Width="24"  HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Command="{Binding TurnPageCommand}" CommandParameter="{Binding ElementName=PrePageBtn}">
                         </Button>
-                        <TextBox x:Name="CurrentPageIndexTxt" Width="30" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="{Binding TargetPaperIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"  >
+                        <TextBox x:Name="CurrentPageIndexTxt" Style="{StaticResource PageTxtStyle}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="{Binding TargetPaperIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"  >
                             <i:Interaction.Triggers>
                                 <i:EventTrigger x:Name="PropertyChanged">
                                     <i:InvokeCommandAction Command="{Binding JumpPageCommand}" CommandParameter="{Binding ElementName=CurrentPageIndexTxt}"></i:InvokeCommandAction>
@@ -41,8 +94,7 @@
                         </TextBox>
                         <TextBlock  Text="of"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0" FontFamily="Segoe UI" FontSize="14"></TextBlock>
                         <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" Text="{Binding PrintedPageCount}"></TextBlock>
-                        <Button Name="NextPageBtn"  Width="20" Height="20" HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Command="{Binding TurnPageCommand}" CommandParameter="{Binding ElementName=NextPageBtn}">
-                            <TextBlock Text=">" VerticalAlignment="Center"></TextBlock>
+                        <Button Name="NextPageBtn"  Tag="NextPage" Style="{StaticResource NextPageBtnStyle}"  Height="24" Width="24"  HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Command="{Binding TurnPageCommand}" CommandParameter="{Binding ElementName=NextPageBtn}">
                         </Button>
                     </StackPanel>
                 </Grid>

+ 2 - 2
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModBookletContent.xaml

@@ -26,13 +26,13 @@
                 </StackPanel>
                 <StackPanel Grid.Row="1" Orientation="Horizontal">
                     <TextBlock Text="Sheets from:" FontFamily="Segoe UI" FontSize="14"  Width="94" Margin="0,0,16,0"   VerticalAlignment="Center" ></TextBlock>
-                    <TextBox Name="PaperFromTxt" Height="32" Width="50"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Text="{Binding PaperFrom,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
+                    <TextBox    Style="{StaticResource Print_normalTxtStyle}" Name="PaperFromTxt" Height="32" Width="50"  VerticalContentAlignment="Center" Text="{Binding PaperFrom,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
                         <TextBox.InputBindings>
                             <KeyBinding Command="{Binding SetSheetCommand}"  CommandParameter="{Binding ElementName=PaperFromTxt}"  Key="Return"></KeyBinding>
                         </TextBox.InputBindings>
                     </TextBox>
                     <TextBlock FontFamily="Segoe UI" FontSize="14" Text="to"  VerticalAlignment="Center" Margin="8,0,8,0" ></TextBlock>
-                    <TextBox Name="PaperToTxt" Height="32" Width="50"   HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Text="{Binding PaperTo,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
+                    <TextBox   Style="{StaticResource Print_normalTxtStyle}" Name="PaperToTxt" Height="32" Width="50"  VerticalContentAlignment="Center" Text="{Binding PaperTo,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
                         <TextBox.InputBindings>
                             <KeyBinding Command="{Binding SetSheetCommand}"  CommandParameter="{Binding ElementName=PaperToTxt}"  Key="Return"></KeyBinding>
                         </TextBox.InputBindings>

+ 3 - 3
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModMultipleContent.xaml

@@ -33,14 +33,14 @@
                         </i:Interaction.Triggers>
                     </ComboBox>
                     <StackPanel Grid.Row="0" Orientation="Horizontal" IsEnabled="{Binding EnableCustomiseMatrix,UpdateSourceTrigger=PropertyChanged, Mode=OneWay}">
-                        <TextBox Height="32" Width="53" Margin="16,0,8,0" Text="{Binding HorizontalPageNumber, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
+                        <TextBox   Style="{StaticResource Print_normalTxtStyle}" VerticalContentAlignment="Center" Height="32" Width="53" Margin="16,0,8,0" Text="{Binding HorizontalPageNumber, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
                             <TextBox.InputBindings>
                                 <KeyBinding  Command="{Binding SetCustomMatrixCommand}" Key="Return"></KeyBinding>
                             </TextBox.InputBindings>
 
                         </TextBox>
-                        <TextBlock Text="X" VerticalAlignment="Center"></TextBlock>
-                        <TextBox Height="32" Width="53"  Margin="8,0,0,0" Text="{Binding  VerticalPageNumber, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
+                        <TextBlock Text="X" VerticalAlignment="Center" Foreground="{StaticResource color.sys.text.neutral.lv3}"></TextBlock>
+                        <TextBox   Style="{StaticResource Print_normalTxtStyle}" VerticalContentAlignment="Center" Height="32" Width="53"  Margin="8,0,0,0" Text="{Binding  VerticalPageNumber, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
                             <TextBox.InputBindings>
                                 <KeyBinding  Command="{Binding SetCustomMatrixCommand}" Key="Return"></KeyBinding>
                             </TextBox.InputBindings>

+ 26 - 28
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModPosterContent.xaml

@@ -8,6 +8,24 @@
              d:DesignHeight="180"
              d:DesignWidth="466"
              prism:ViewModelLocator.AutoWireViewModel="True">
+    <UserControl.Resources>
+        <Style x:Key="LabelTxtStyle" TargetType="TextBox">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate>
+                        <Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
+                            <Border BorderBrush="{StaticResource color.field.border.dis}" Background="{StaticResource color.field.bg.dis}" CornerRadius="4">
+                                <Grid>
+                                    <TextBlock Text="{Binding DefaultLabel, Mode=OneWay}" Grid.Column="1" VerticalAlignment="Center" Foreground="#BBB"
+                                           Name="markText" Visibility="Visible" FontSize="14" Margin="8,0,0,0" FontFamily="Segoe UI"/>
+                                </Grid>
+                            </Border>
+                        </Grid>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
     <Border Background="#F7F8FA" CornerRadius="4"  Height="188">
         <Grid VerticalAlignment="Top">
             <Grid.RowDefinitions>
@@ -31,8 +49,8 @@
 
                 <StackPanel Orientation="Horizontal" Visibility="{Binding PageRangeSettingVisibility, Mode=TwoWay}" Margin="8,8,0,0">
                     <TextBlock Text="Page range:" VerticalAlignment="Center" FontSize="14" Width="80"></TextBlock>
-                    <cus:NumericUpDown x:Name="CustomRatioUpDown" Loaded="CustomRatioUpDown_Loaded" Width="90" Height="32" Margin="16,0,16,0" Text="{Binding TileRatio, Mode=TwoWay}" IsEnabled="{Binding ElementName=CustomRatioBtn, Path=IsChecked}" Minimum="20" Maximum="400"></cus:NumericUpDown>
-                    <TextBlock Text="%" VerticalAlignment="Center" FontSize="14"></TextBlock>
+                    <cus:NumericUpDown x:Name="CustomRatioUpDown" Loaded="CustomRatioUpDown_Loaded" Width="90" Height="32" Margin="16,0,16,0" Text="{Binding TileRatio, Mode=TwoWay}" IsEnabled="{Binding ElementName=CustomRatioBtn, Path=IsChecked}" Minimum="1" Maximum="400"></cus:NumericUpDown>
+                    <TextBlock Text="%" VerticalAlignment="Center" FontSize="14"  FontFamily="Segoe UI" Foreground="{StaticResource color.sys.text.neutral.lv3}"></TextBlock>
                 </StackPanel>
                 <StackPanel Orientation="Horizontal" Visibility="{Binding PagesPerSheetVisibility , Mode=TwoWay}"  Margin="8,8,0,0">
                     <TextBlock Text="Pages per sheet:" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" ></TextBlock>
@@ -44,13 +62,13 @@
                         </i:Interaction.Triggers>
                     </ComboBox>
                     <StackPanel Orientation="Horizontal" IsEnabled="{Binding EnableCustomSheet, Mode=TwoWay}">
-                        <TextBox Height="32" Width="48" Text="{Binding HorizontalSheetNumber}">
+                        <TextBox  Style="{StaticResource Print_normalTxtStyle}" Height="32" Width="48" VerticalContentAlignment="Center" Text="{Binding HorizontalSheetNumber}">
                             <TextBox.InputBindings>
                                 <KeyBinding Command="{Binding SetCustomSheetCommand}" Key="Return"></KeyBinding>
                             </TextBox.InputBindings>
                         </TextBox>
-                        <TextBlock Text="x" VerticalAlignment="Center" Margin="8,0,8,0"></TextBlock>
-                        <TextBox  Height="32" Width="48" Text="{Binding VerticalSheetNumber}">
+                        <TextBlock  Text="x" VerticalAlignment="Center" Margin="8,0,8,0"></TextBlock>
+                        <TextBox  Style="{StaticResource Print_normalTxtStyle}" Height="32" Width="48" VerticalContentAlignment="Center" Text="{Binding VerticalSheetNumber}">
                             <TextBox.InputBindings>
                                 <KeyBinding Command="{Binding SetCustomSheetCommand}" Key="Return"></KeyBinding>
                             </TextBox.InputBindings>
@@ -61,12 +79,12 @@
             <Grid Grid.Row="2"  Margin="8,8,0,0">
                 <StackPanel Orientation="Horizontal" >
                     <TextBlock Text="Overlap:" VerticalAlignment="Center" FontSize="14" Width="80"></TextBlock>
-                    <TextBox Height="32" Width="88" Margin="16,0,16,0" Text="{Binding OverlapNumber,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
+                    <TextBox Style="{StaticResource Print_normalTxtStyle}" VerticalContentAlignment="Center" Height="32" Width="88" Margin="16,0,16,0" Text="{Binding OverlapNumber,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
                         <TextBox.InputBindings>
                             <KeyBinding Command="{Binding SetOverlapCommand}" Key="Return"></KeyBinding>
                         </TextBox.InputBindings>
                     </TextBox>
-                    <TextBlock Text="mm" VerticalAlignment="Center" FontSize="14"></TextBlock>
+                    <TextBlock Text="mm" VerticalAlignment="Center" FontSize="14" FontFamily="Segoe UI" Foreground="{StaticResource color.sys.text.neutral.lv3}"></TextBlock>
                 </StackPanel>
             </Grid>
             <Grid Grid.Row="3"  Margin="8,8,0,0">
@@ -79,27 +97,7 @@
                 <StackPanel Orientation="Horizontal">
                     <CheckBox  Name="SetLabelChk" Margin="0,0,11,0" VerticalAlignment="Center" Command="{Binding SetLabelCommand}" CommandParameter="{Binding ElementName=SetLabelChk}"></CheckBox>
                     <TextBlock Text="Label" VerticalAlignment="Center" Margin="0,0,16,0" FontSize="14"></TextBlock>
-                    <TextBox Height="32" Width="361" Text="{Binding LabelString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="{Binding ElementName=SetLabelChk, Path=IsChecked}" IsReadOnly="True">
-                        <TextBox.Resources>
-                            <VisualBrush x:Key="HelpBrush" TileMode ="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
-                                <VisualBrush.Visual>
-                                    <TextBlock Text="{Binding DefaultLabel, Mode=OneWay}"></TextBlock>
-                                </VisualBrush.Visual>
-                            </VisualBrush>
-                        </TextBox.Resources>
-                        <TextBox.Style>
-                            <Style TargetType="TextBox">
-                                <Style.Triggers>
-                                    <Trigger Property="Text" Value="{x:Null}">
-                                        <Setter Property="Background" Value="{StaticResource HelpBrush}"></Setter>
-                                    </Trigger>
-                                    <Trigger Property="Text" Value="">
-                                        <Setter Property="Background" Value="{StaticResource HelpBrush}"></Setter>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </TextBox.Style>
-                    </TextBox>
+                    <TextBox Style="{StaticResource LabelTxtStyle}" Height="32" Width="361" Text="{Binding LabelString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="{Binding ElementName=SetLabelChk, Path=IsChecked}" IsReadOnly="True"></TextBox>
                 </StackPanel>
             </Grid>
         </Grid>