|
@@ -8,6 +8,7 @@ using System.Runtime.CompilerServices;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Forms;
|
|
|
+using Compdfkit_Tools.Common;
|
|
|
using ComPDFKit.PDFDocument;
|
|
|
|
|
|
namespace Compdfkit_Tools.PDFControl
|
|
@@ -42,27 +43,39 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
var dialog = new FolderBrowserDialog();
|
|
|
dialog.ShowDialog();
|
|
|
var savePath = dialog.SelectedPath;
|
|
|
+ if (string.IsNullOrEmpty(savePath)) return;
|
|
|
+
|
|
|
var permissionsInfo = new CPDFPermissionsInfo();
|
|
|
+ string userPassword = string.Empty;
|
|
|
+ string ownerPassword = string.Empty;
|
|
|
|
|
|
- if (!SetEncryptionControl.IsOwnerPasswordEnabled || string.IsNullOrEmpty(SetEncryptionControl.OwnerPassword))
|
|
|
- {
|
|
|
- foreach (var fileInfoData in FileListControl.FileInfoDataList)
|
|
|
- {
|
|
|
- document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
|
|
|
- document.Encrypt(SetEncryptionControl.UserPassword, null, permissionsInfo);
|
|
|
- document.WriteToFilePath(savePath + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fileInfoData.FileName) + "_Encrypted.pdf");
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ if (SetEncryptionControl.IsOwnerPasswordEnabled && !string.IsNullOrEmpty(SetEncryptionControl.OwnerPassword))
|
|
|
{
|
|
|
permissionsInfo.AllowsPrinting = SetEncryptionControl.IsAllowPrint;
|
|
|
permissionsInfo.AllowsCopying = SetEncryptionControl.IsAllowCopy;
|
|
|
- foreach (var fileInfoData in FileListControl.FileInfoDataList)
|
|
|
+ ownerPassword = SetEncryptionControl.OwnerPassword;
|
|
|
+ }
|
|
|
+ if(SetEncryptionControl.IsUserPasswordEnabled && !string.IsNullOrEmpty(SetEncryptionControl.UserPassword))
|
|
|
+ {
|
|
|
+ userPassword = SetEncryptionControl.UserPassword;
|
|
|
+ }
|
|
|
+ foreach (var fileInfoData in FileListControl.FileInfoDataList)
|
|
|
+ {
|
|
|
+ document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
|
|
|
+ if (document.IsLocked)
|
|
|
{
|
|
|
- document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
|
|
|
- document.Encrypt(SetEncryptionControl.UserPassword, SetEncryptionControl.OwnerPassword, permissionsInfo);
|
|
|
- document.WriteToFilePath(savePath + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fileInfoData.FileName) + "_Encrypted.pdf");
|
|
|
+ PasswordWindow window = new PasswordWindow();
|
|
|
+ window.InitWithDocument(document);
|
|
|
+ window.Owner = this;
|
|
|
+ window.ShowDialog();
|
|
|
+ if (document.IsLocked)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
+ document.Encrypt(userPassword, ownerPassword, permissionsInfo);
|
|
|
+ document.WriteToFilePath(savePath + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fileInfoData.FileName) + "_Encrypted.pdf");
|
|
|
+ document.Release();
|
|
|
}
|
|
|
}
|
|
|
|