|
@@ -16,6 +16,9 @@ using CheckBox = System.Windows.Controls.CheckBox;
|
|
using System.Drawing.Printing;
|
|
using System.Drawing.Printing;
|
|
using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
|
|
using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
|
|
using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
|
|
using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
|
|
|
|
+using ComPDFKitViewer.PdfViewer;
|
|
|
|
+using Prism.Regions;
|
|
|
|
+using PDF_Office.Helper;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
{
|
|
{
|
|
@@ -23,9 +26,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
{
|
|
{
|
|
#region 参数和属性
|
|
#region 参数和属性
|
|
private SetPasswordDialogModel setPasswordDialogModel = new SetPasswordDialogModel();
|
|
private SetPasswordDialogModel setPasswordDialogModel = new SetPasswordDialogModel();
|
|
- private CPDFDocument document;
|
|
|
|
|
|
+ private CPDFViewer cPDFViewer;
|
|
public IDialogService dialogs;
|
|
public IDialogService dialogs;
|
|
-
|
|
|
|
|
|
+ private ViewContentViewModel viewContentViewModel;
|
|
private EnumPermissionsMod enumPermissionsMod = EnumPermissionsMod.StatusUnknown | EnumPermissionsMod.StatusRestrictPrinting | EnumPermissionsMod.StatusRestrictCopying;
|
|
private EnumPermissionsMod enumPermissionsMod = EnumPermissionsMod.StatusUnknown | EnumPermissionsMod.StatusRestrictPrinting | EnumPermissionsMod.StatusRestrictCopying;
|
|
|
|
|
|
private bool _enableConfirm = false;
|
|
private bool _enableConfirm = false;
|
|
@@ -318,9 +321,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
{
|
|
{
|
|
DialogParameters setPasswordpdf = new DialogParameters();
|
|
DialogParameters setPasswordpdf = new DialogParameters();
|
|
setPasswordpdf.Add(ParameterNames.BatchProcessing_Name, "2");
|
|
setPasswordpdf.Add(ParameterNames.BatchProcessing_Name, "2");
|
|
- HomePageBatchProcessingDialogModel.FilePaths = new List<string> { document.FilePath.ToString() };
|
|
|
|
|
|
+ HomePageBatchProcessingDialogModel.FilePaths = new List<string> { cPDFViewer.Document.FilePath.ToString() };
|
|
HomePageBatchProcessingDialogModel.BatchProcessingIndex = 2;
|
|
HomePageBatchProcessingDialogModel.BatchProcessingIndex = 2;
|
|
- setPasswordpdf.Add(ParameterNames.FilePath, new string[] { document.FilePath.ToString() });
|
|
|
|
|
|
+ setPasswordpdf.Add(ParameterNames.FilePath, new string[] { cPDFViewer.Document.FilePath.ToString() });
|
|
dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, setPasswordpdf, e => { });
|
|
dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, setPasswordpdf, e => { });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -330,48 +333,41 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
|
|
|
string openPassword = "";
|
|
string openPassword = "";
|
|
string permissionsPassword = "";
|
|
string permissionsPassword = "";
|
|
- FolderBrowserDialog folderDialog = new FolderBrowserDialog();
|
|
|
|
- System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
|
|
|
|
- /*
|
|
|
|
- *设置这个对话框的起始保存路径
|
|
|
|
- */
|
|
|
|
- sfd.InitialDirectory = document.FilePath;
|
|
|
|
- /*
|
|
|
|
- *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
|
|
|
|
- */
|
|
|
|
- sfd.Filter = "PDF|*.pdf;";
|
|
|
|
- /*
|
|
|
|
- *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
|
|
|
|
- **/
|
|
|
|
- sfd.FileName = document.FileName + "_SetPassword.pdf";
|
|
|
|
- if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
- {
|
|
|
|
- CPDFPermissionsInfo permissionsInfo = null;
|
|
|
|
|
|
|
|
- if (NeedOpenPassword)
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrEmpty(OpenPassword))
|
|
|
|
- {
|
|
|
|
- openPassword = OpenPassword;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
|
|
|
|
- {
|
|
|
|
- permissionsPassword = PermissionsPassword;
|
|
|
|
- permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ CPDFPermissionsInfo permissionsInfo = null;
|
|
|
|
+
|
|
|
|
+ if (NeedOpenPassword)
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrEmpty(OpenPassword))
|
|
{
|
|
{
|
|
- permissionsInfo = CreateDefaultPermissionsInfo();
|
|
|
|
|
|
+ openPassword = OpenPassword;
|
|
}
|
|
}
|
|
-
|
|
|
|
- document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
|
|
|
|
- document.WriteToFilePath(sfd.FileName);
|
|
|
|
- MessageBoxEx.Show(sfd.FileName + " 保存成功");
|
|
|
|
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
|
|
}
|
|
}
|
|
|
|
+ if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
|
|
|
|
+ {
|
|
|
|
+ permissionsPassword = PermissionsPassword;
|
|
|
|
+ permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ permissionsInfo = CreateDefaultPermissionsInfo();
|
|
|
|
+ }
|
|
|
|
+ cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
|
|
|
|
+ //cPDFViewer.ReloadDocument();
|
|
|
|
+ if (!string.IsNullOrEmpty(permissionsPassword) )
|
|
|
|
+ {
|
|
|
|
+ cPDFViewer.Document.UnlockWithPassword(permissionsPassword);
|
|
|
|
+ SecurityHelper.CheckHaveAllPermissions(cPDFViewer.Document);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ cPDFViewer.Document.UnlockWithPassword(openPassword);
|
|
|
|
+ }
|
|
|
|
+ viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
|
|
|
|
+ RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public void CancelEncrypt() => RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
public void CancelEncrypt() => RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -390,12 +386,8 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
|
|
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
{
|
|
- CPDFDocument doc = null;
|
|
|
|
- parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
|
|
|
|
- if (doc != null)
|
|
|
|
- {
|
|
|
|
- document = doc;
|
|
|
|
- }
|
|
|
|
|
|
+ parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out cPDFViewer);
|
|
|
|
+ parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|