|
@@ -21,12 +21,19 @@ using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
+using static Dropbox.Api.TeamLog.PaperDownloadFormat;
|
|
|
using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
|
|
|
|
|
|
namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
{
|
|
|
class MergeDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
+ // Fix:存储当前程序加载的文档的路径和tag,
|
|
|
+ //如果路径相同则用tag里的密码解锁,
|
|
|
+ //解锁失败再另行提权
|
|
|
+ private string CurrentFilePath = string.Empty;
|
|
|
+ private string currentLoadedPassword = string.Empty;
|
|
|
+
|
|
|
enum PageSizeType
|
|
|
{
|
|
|
kDefault = 0,
|
|
@@ -36,7 +43,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
Legal = 4,
|
|
|
Customized = 5,
|
|
|
}
|
|
|
- string CurrentFilePath = "";
|
|
|
|
|
|
#region 框架内容
|
|
|
|
|
@@ -57,7 +63,22 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
CPDFViewer pdfViewer = null;
|
|
|
- parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
|
|
|
+ if (parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer))
|
|
|
+ {
|
|
|
+ VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(pdfViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
|
|
|
+ if (condition.IsDiscryptied)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(condition.Password))
|
|
|
+ {
|
|
|
+ if (pdfViewer.Document.UnlockWithPassword(condition.Password))
|
|
|
+ {
|
|
|
+ pdfViewer.Document.CheckOwnerPassword(condition.Password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currentLoadedPassword = pdfViewer.Document.Password;
|
|
|
+ }
|
|
|
+
|
|
|
if (pdfViewer != null)
|
|
|
{
|
|
|
CurrentFilePath = pdfViewer.Document.FilePath;
|
|
@@ -111,7 +132,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
SetProperty(ref inputHeight, value);
|
|
|
}
|
|
|
}
|
|
|
- private int comboBoxSelectedIndex=0;
|
|
|
+ private int comboBoxSelectedIndex = 0;
|
|
|
|
|
|
public int ComboBoxSelectedIndex
|
|
|
{
|
|
@@ -202,7 +223,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
{
|
|
|
OpenFileDialog openFile = new OpenFileDialog();
|
|
|
openFile.Multiselect = true;
|
|
|
- openFile.Filter = Properties.Resources.imageex.ToLower()+"|*";
|
|
|
+ openFile.Filter = Properties.Resources.imageex.ToLower() + "|*";
|
|
|
if (openFile.ShowDialog() == false)
|
|
|
{
|
|
|
return null;
|
|
@@ -261,9 +282,9 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
//下拉框控件传出来的list是页面索引集合,
|
|
|
//此处传给SDK的合并接口的是页码集合,因此需要将集合项遍历+1,只有合并接口是接收页码集合,其余接口是接受页面索引集合
|
|
|
List<int> pageIndexs = new List<int>();
|
|
|
- for(int j=0;j< MergeObjectlist[i].SetPageRange.Count; j++)
|
|
|
+ for (int j = 0; j < MergeObjectlist[i].SetPageRange.Count; j++)
|
|
|
{
|
|
|
- pageIndexs.Add(MergeObjectlist[i].SetPageRange[j]+1);
|
|
|
+ pageIndexs.Add(MergeObjectlist[i].SetPageRange[j] + 1);
|
|
|
}
|
|
|
result = SaveDoc.ImportPages(tempDoc, CommonHelper.GetPageParmFromList(pageIndexs));
|
|
|
}
|
|
@@ -459,51 +480,63 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
|
//PDF打开失败
|
|
|
continue;
|
|
|
}
|
|
|
- VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
|
|
|
- if (condition.IsDiscryptied)
|
|
|
+
|
|
|
+ ///Fix:当前情况下,即带着当前文档进入合并,此时可以先行鉴权
|
|
|
+ ///鉴权完毕后如果有提权行为,还要给原文档提权
|
|
|
+ if (CurrentFilePath == doc.FilePath && !string.IsNullOrEmpty(currentLoadedPassword) && doc.UnlockWithPassword(currentLoadedPassword)&&doc.CheckOwnerPassword(currentLoadedPassword))
|
|
|
{
|
|
|
- if (condition.Password != null)
|
|
|
- {
|
|
|
- mergeObject.Password = condition.Password;
|
|
|
- doc.UnlockWithPassword(condition.Password);
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- doc.Release();
|
|
|
- continue;
|
|
|
+ VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
|
|
|
+ if (condition.IsDiscryptied)
|
|
|
+ {
|
|
|
+ if (condition.Password != null)
|
|
|
+ {
|
|
|
+ mergeObject.Password = condition.Password;
|
|
|
+ doc.UnlockWithPassword(condition.Password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ doc.Release();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
- mergeObject.DocName = doc.FileName;
|
|
|
- mergeObject.DocPageCount = doc.PageCount.ToString() +" "+ App.MainPageLoader.GetString("Merge_ItemPages");
|
|
|
- mergeObject.SDKPageCount = doc.PageCount;
|
|
|
- mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
|
|
|
-
|
|
|
- //获取第一页缩略图
|
|
|
- CPDFPage page = doc.PageAtIndex(0);
|
|
|
- Size size = doc.GetPageSize(0);
|
|
|
-
|
|
|
- byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
|
|
|
- WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
|
|
|
- page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
|
|
|
- WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
|
|
|
- WirteBitmap.Freeze();
|
|
|
- mergeObject.DocThumbnail = WirteBitmap;
|
|
|
-
|
|
|
- doc.Release();
|
|
|
- }
|
|
|
- MergeObjectlist.Add(mergeObject);
|
|
|
- UpDataMergeObjectIndex();
|
|
|
+
|
|
|
+
|
|
|
+ mergeObject.DocName = doc.FileName;
|
|
|
+ mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
|
|
|
+ mergeObject.SDKPageCount = doc.PageCount;
|
|
|
+ mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
|
|
|
+
|
|
|
+ //获取第一页缩略图
|
|
|
+ CPDFPage page = doc.PageAtIndex(0);
|
|
|
+ Size size = doc.GetPageSize(0);
|
|
|
+
|
|
|
+ byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
|
|
|
+ WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
|
|
|
+ page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
|
|
|
+ WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
|
|
|
+ WirteBitmap.Freeze();
|
|
|
+ mergeObject.DocThumbnail = WirteBitmap;
|
|
|
+
|
|
|
+ doc.Release();
|
|
|
}
|
|
|
+ MergeObjectlist.Add(mergeObject);
|
|
|
+ UpDataMergeObjectIndex();
|
|
|
+ }
|
|
|
|
|
|
if (showDialog)
|
|
|
{
|
|
|
AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
- alertsMessage.ShowDialog("", "The file was not added successfully, please select the file again.", "OK");
|
|
|
+ alertsMessage.ShowDialog("", "The file was not added successfully, please select the file again.", "OK");
|
|
|
if (alertsMessage.result == ContentResult.Ok)
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|