|
@@ -2,6 +2,7 @@
|
|
using ComPDFKit.PDFPage;
|
|
using ComPDFKit.PDFPage;
|
|
using ComPDFKitViewer.PdfViewer;
|
|
using ComPDFKitViewer.PdfViewer;
|
|
using Dropbox.Api.TeamLog;
|
|
using Dropbox.Api.TeamLog;
|
|
|
|
+using Microsoft.Office.Interop.Word;
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
using PDF_Master.CustomControl;
|
|
using PDF_Master.CustomControl;
|
|
using PDF_Master.EventAggregators;
|
|
using PDF_Master.EventAggregators;
|
|
@@ -19,6 +20,7 @@ using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Reflection;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
@@ -67,7 +69,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
{
|
|
CPDFViewer pdfViewer = null;
|
|
CPDFViewer pdfViewer = null;
|
|
- if (parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer)&&pdfViewer!=null&&pdfViewer.Document!=null)
|
|
|
|
|
|
+ if (parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer) && pdfViewer != null && pdfViewer.Document != null)
|
|
{
|
|
{
|
|
VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(pdfViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
|
|
VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(pdfViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
|
|
if (condition.IsDiscryptied)
|
|
if (condition.IsDiscryptied)
|
|
@@ -83,12 +85,12 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
if (parameters.TryGetValue<string>(ParameterNames.Unicode, out unicode))
|
|
if (parameters.TryGetValue<string>(ParameterNames.Unicode, out unicode))
|
|
{
|
|
{
|
|
this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
|
|
this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
currentLoadedPassword = pdfViewer.Document.Password;
|
|
currentLoadedPassword = pdfViewer.Document.Password;
|
|
}
|
|
}
|
|
|
|
|
|
- if (pdfViewer != null&&pdfViewer.Document!=null)
|
|
|
|
|
|
+ if (pdfViewer != null && pdfViewer.Document != null)
|
|
{
|
|
{
|
|
CurrentFilePath = pdfViewer.Document.FilePath;
|
|
CurrentFilePath = pdfViewer.Document.FilePath;
|
|
|
|
|
|
@@ -219,8 +221,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
{
|
|
{
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- DirectoryInfo tempfolder = new DirectoryInfo(openFile.SelectedPath);
|
|
|
|
-
|
|
|
|
|
|
+ DirectoryInfo tempfolder = new DirectoryInfo(openFile.SelectedPath);
|
|
|
|
+
|
|
FileInfo[] fileInfos = tempfolder.GetFiles();
|
|
FileInfo[] fileInfos = tempfolder.GetFiles();
|
|
List<string> list = new List<string>();
|
|
List<string> list = new List<string>();
|
|
foreach (FileInfo item in fileInfos)
|
|
foreach (FileInfo item in fileInfos)
|
|
@@ -228,7 +230,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
list.Add(item.FullName);
|
|
list.Add(item.FullName);
|
|
}
|
|
}
|
|
|
|
|
|
- DirectoryInfo[] directoryInfos= tempfolder.GetDirectories();
|
|
|
|
|
|
+ DirectoryInfo[] directoryInfos = tempfolder.GetDirectories();
|
|
foreach (DirectoryInfo fileInfo in directoryInfos)
|
|
foreach (DirectoryInfo fileInfo in directoryInfos)
|
|
{
|
|
{
|
|
FileInfo[] fileinfo = fileInfo.GetFiles();
|
|
FileInfo[] fileinfo = fileInfo.GetFiles();
|
|
@@ -259,27 +261,49 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
for (int i = 0; i < MergeObjectlist.Count; i++)
|
|
for (int i = 0; i < MergeObjectlist.Count; i++)
|
|
{
|
|
{
|
|
//图片
|
|
//图片
|
|
- if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() != ".pdf")
|
|
|
|
- {
|
|
|
|
- BitmapSource frame = MergeObjectlist[i].DocThumbnail;
|
|
|
|
- byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
|
- if (frame.Format != PixelFormats.Bgra32)
|
|
|
|
- {
|
|
|
|
- FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
|
|
|
|
- covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
- }
|
|
|
|
- frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
- result = SaveDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
|
|
|
|
- if (!result)
|
|
|
|
- {
|
|
|
|
- SaveDoc.Release();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
|
|
+ if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() != ".pdf")
|
|
|
|
+ {
|
|
|
|
+ if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() == ".gif")
|
|
|
|
+ {//GIF下面方法产生虚影改成与图片转PDF一致
|
|
|
|
+ System.Drawing.Image img = System.Drawing.Image.FromFile(MergeObjectlist[i].FilePath);
|
|
|
|
+ string tempFileName = Path.GetTempPath() + "pngtemp.jpg";
|
|
|
|
+ if (!PictureConverter.SaveJpeg(MergeObjectlist[i].FilePath, tempFileName))
|
|
|
|
+ {
|
|
|
|
+ MessageBoxEx.Show("图片格式有问题");
|
|
|
|
+ }
|
|
|
|
+ result = SaveDoc.InsertPage(0, img.Width, img.Height, tempFileName);
|
|
|
|
+ try { if (File.Exists(tempFileName)) File.Delete(tempFileName); }
|
|
|
|
+ catch
|
|
|
|
+ { }
|
|
|
|
+ if (!result)
|
|
|
|
+ {
|
|
|
|
+ SaveDoc.Release();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ BitmapSource frame = MergeObjectlist[i].DocThumbnail;
|
|
|
|
+ byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
|
+ if (frame.Format != PixelFormats.Bgra32)
|
|
|
|
+ {
|
|
|
|
+ FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
|
|
|
|
+ covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
+ }
|
|
|
|
+ frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
+ result = SaveDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
|
|
|
|
+ if (!result)
|
|
|
|
+ {
|
|
|
|
+ SaveDoc.Release();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -506,13 +530,13 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
///解锁或取消->
|
|
///解锁或取消->
|
|
///
|
|
///
|
|
|
|
|
|
- if(CurrentFilePath == doc.FilePath)
|
|
|
|
|
|
+ if (CurrentFilePath == doc.FilePath)
|
|
{
|
|
{
|
|
|
|
|
|
- if ((!(!doc.IsLocked&&(SecurityHelper.CheckHaveAllPermissions(doc)))) &&
|
|
|
|
- (!(!string.IsNullOrEmpty(currentLoadedPassword) &&
|
|
|
|
- doc.UnlockWithPassword(currentLoadedPassword) &&
|
|
|
|
- (doc.CheckOwnerPassword(currentLoadedPassword)||SecurityHelper.CheckHaveAllPermissions(doc)))))
|
|
|
|
|
|
+ if ((!(!doc.IsLocked && (SecurityHelper.CheckHaveAllPermissions(doc)))) &&
|
|
|
|
+ (!(!string.IsNullOrEmpty(currentLoadedPassword) &&
|
|
|
|
+ doc.UnlockWithPassword(currentLoadedPassword) &&
|
|
|
|
+ (doc.CheckOwnerPassword(currentLoadedPassword) || SecurityHelper.CheckHaveAllPermissions(doc)))))
|
|
{
|
|
{
|
|
doc.Release();
|
|
doc.Release();
|
|
continue;
|
|
continue;
|
|
@@ -531,10 +555,10 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
{
|
|
{
|
|
if (condition.Password != null)
|
|
if (condition.Password != null)
|
|
{
|
|
{
|
|
- mergeObject.Password = condition.Password;
|
|
|
|
- if(doc.UnlockWithPassword(condition.Password)&& doc.CheckOwnerPassword(condition.Password))
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
|
|
+ mergeObject.Password = condition.Password;
|
|
|
|
+ if (doc.UnlockWithPassword(condition.Password) && doc.CheckOwnerPassword(condition.Password))
|
|
|
|
+ {
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -543,37 +567,37 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
doc.Release();
|
|
doc.Release();
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- mergeObject.DocName = doc.FileName;
|
|
|
|
- mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
|
|
|
|
- if (doc.PageCount > 1)
|
|
|
|
- {
|
|
|
|
- mergeObject.IsEvenPageIsEnabled = true;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- mergeObject.IsEvenPageIsEnabled=false;
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mergeObject.DocName = doc.FileName;
|
|
|
|
+ mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
|
|
|
|
+ if (doc.PageCount > 1)
|
|
|
|
+ {
|
|
|
|
+ mergeObject.IsEvenPageIsEnabled = true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ mergeObject.IsEvenPageIsEnabled = false;
|
|
|
|
+ }
|
|
|
|
+ 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();
|
|
}
|
|
}
|
|
- 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();
|
|
}
|
|
}
|
|
- MergeObjectlist.Add(mergeObject);
|
|
|
|
- UpDataMergeObjectIndex();
|
|
|
|
- }
|
|
|
|
|
|
|
|
if (showDialog)
|
|
if (showDialog)
|
|
{
|
|
{
|
|
@@ -582,8 +606,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
|
|
if (alertsMessage.result == ContentResult.Ok)
|
|
if (alertsMessage.result == ContentResult.Ok)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
}
|