|
@@ -52,6 +52,9 @@ using System.Windows.Documents;
|
|
|
using ComPDFKit.PDFPage;
|
|
|
using ComPDFKitViewer;
|
|
|
using SplitMode = PDF_Master.EventAggregators.SplitMode;
|
|
|
+using System.Windows.Resources;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
+using ComPDFKit.PDFWatermark;
|
|
|
|
|
|
namespace PDF_Master.ViewModels
|
|
|
{
|
|
@@ -238,6 +241,8 @@ namespace PDF_Master.ViewModels
|
|
|
|
|
|
public BOTAContentViewModel botaViewModel { get; set; }
|
|
|
|
|
|
+ private CPDFWatermark watermark;
|
|
|
+
|
|
|
public bool IsSettingOut = false;
|
|
|
public IRegionManager region;
|
|
|
|
|
@@ -2717,7 +2722,6 @@ namespace PDF_Master.ViewModels
|
|
|
/// </summary>
|
|
|
public bool saveFile(bool autosave = false)
|
|
|
{
|
|
|
- bool flg = false;
|
|
|
try
|
|
|
{
|
|
|
//删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
|
|
@@ -2727,16 +2731,12 @@ namespace PDF_Master.ViewModels
|
|
|
value.Add(ParameterNames.ViewContentViewModel, this);
|
|
|
dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
|
|
|
{
|
|
|
- if (dialogResult.Result == ButtonResult.Cancel)
|
|
|
- {
|
|
|
- flg = true;
|
|
|
- }
|
|
|
+
|
|
|
});
|
|
|
|
|
|
- if (flg == false)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
|
|
@@ -2984,29 +2984,10 @@ namespace PDF_Master.ViewModels
|
|
|
/// <summary>
|
|
|
/// 另存为或新文档保存逻辑
|
|
|
/// </summary>
|
|
|
- public bool saveAsFile(Action RedactionAction = null, CPDFViewer cPDFViewer = null)
|
|
|
+ public bool saveAsFile(Action RedactionAction = null, String IsFormSave=null)
|
|
|
{
|
|
|
- if (cPDFViewer == null)
|
|
|
+ if(IsFormSave=="FormSave")
|
|
|
{
|
|
|
- bool flg = false;
|
|
|
- //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
|
|
|
- if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && App.IsUsedVIP == true)
|
|
|
- {
|
|
|
- DialogParameters value = new DialogParameters();
|
|
|
- value.Add(ParameterNames.ViewContentViewModel, this);
|
|
|
- dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
|
|
|
- {
|
|
|
- if (dialogResult.Result == ButtonResult.Cancel)
|
|
|
- {
|
|
|
- flg = true;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (flg == false)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
var dlg = new Microsoft.Win32.SaveFileDialog();
|
|
|
dlg.Filter = Properties.Resources.OpenDialogFilter;
|
|
|
dlg.FileName = PDFViewer.Document.FileName;
|
|
@@ -3044,6 +3025,52 @@ namespace PDF_Master.ViewModels
|
|
|
}
|
|
|
|
|
|
PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
|
|
|
+ Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
|
|
|
+ StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
|
|
|
+ if (resourceInfo != null)
|
|
|
+ {
|
|
|
+ using (Stream stream = resourceInfo.Stream)
|
|
|
+ {
|
|
|
+ BitmapFrame frame = null;
|
|
|
+ int width = 0;
|
|
|
+ int height = 0;
|
|
|
+ BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
|
|
|
+ if (decoder != null && decoder.Frames.Count > 0)
|
|
|
+ {
|
|
|
+ frame = decoder.Frames[0];
|
|
|
+ }
|
|
|
+ if (frame != null)
|
|
|
+ {
|
|
|
+ var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
+ width = frame.PixelWidth;
|
|
|
+ height = frame.PixelHeight;
|
|
|
+ frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
|
|
|
+ watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
|
|
|
+ watermark.SetImage(ImageArray, width, height);
|
|
|
+ watermark.SetScale(1);
|
|
|
+ watermark.SetRotation(0);
|
|
|
+ watermark.SetOpacity(255);
|
|
|
+ watermark.SetFront(true);
|
|
|
+ watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
|
|
|
+ watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
|
|
|
+ watermark.SetFullScreen(false);
|
|
|
+ watermark.SetVertOffset(0);
|
|
|
+ watermark.SetHorizOffset(0);
|
|
|
+ watermark.SetHorizontalSpacing(0);
|
|
|
+ watermark.SetVerticalSpacing(0);
|
|
|
+ string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
|
|
|
+ watermark.SetPages(setpages);
|
|
|
+ watermark.UpdateWatermark();
|
|
|
+ PDFViewer.Document.ReleasePages();
|
|
|
+ PDFViewer.ReloadDocument();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
|
|
|
if (result)
|
|
|
{
|
|
@@ -3065,9 +3092,30 @@ namespace PDF_Master.ViewModels
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
+ bool flg = false;
|
|
|
+ //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
|
|
|
+ if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && App.IsUsedVIP == true)
|
|
|
+ {
|
|
|
+ DialogParameters value = new DialogParameters();
|
|
|
+ value.Add(ParameterNames.ViewContentViewModel, this);
|
|
|
+ value.Add(ParameterNames.Open, "saveAs");
|
|
|
+ dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
|
|
|
+ {
|
|
|
+ if (dialogResult.Result == ButtonResult.Cancel)
|
|
|
+ {
|
|
|
+ flg = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (flg == false)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
var dlg = new Microsoft.Win32.SaveFileDialog();
|
|
|
dlg.Filter = Properties.Resources.OpenDialogFilter;
|
|
|
- dlg.FileName = cPDFViewer.Document.FileName;
|
|
|
+ dlg.FileName = PDFViewer.Document.FileName;
|
|
|
if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
|
|
|
{
|
|
|
bool result = false;
|
|
@@ -3083,7 +3131,7 @@ namespace PDF_Master.ViewModels
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string oldpath = cPDFViewer.Document.FilePath;
|
|
|
+ string oldpath = PDFViewer.Document.FilePath;
|
|
|
string openPassword = string.Empty;
|
|
|
string permissionsPassword = string.Empty;
|
|
|
CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
|
|
@@ -3101,8 +3149,58 @@ namespace PDF_Master.ViewModels
|
|
|
passwordInfo.PermissionsPassword = permissionsPassword;
|
|
|
}
|
|
|
|
|
|
- cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
|
|
|
- result = cPDFViewer.Document.WriteToFilePath(dlg.FileName);
|
|
|
+ PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
|
|
|
+ if(flg==true)
|
|
|
+ {
|
|
|
+ Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
|
|
|
+ StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
|
|
|
+ if (resourceInfo != null)
|
|
|
+ {
|
|
|
+ using (Stream stream = resourceInfo.Stream)
|
|
|
+ {
|
|
|
+ BitmapFrame frame = null;
|
|
|
+ int width = 0;
|
|
|
+ int height = 0;
|
|
|
+ BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
|
|
|
+ if (decoder != null && decoder.Frames.Count > 0)
|
|
|
+ {
|
|
|
+ frame = decoder.Frames[0];
|
|
|
+ }
|
|
|
+ if (frame != null)
|
|
|
+ {
|
|
|
+ var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
+ width = frame.PixelWidth;
|
|
|
+ height = frame.PixelHeight;
|
|
|
+ frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
|
|
|
+ watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
|
|
|
+ watermark.SetImage(ImageArray, width, height);
|
|
|
+ watermark.SetScale(1);
|
|
|
+ watermark.SetRotation(0);
|
|
|
+ watermark.SetOpacity(255);
|
|
|
+ watermark.SetFront(true);
|
|
|
+ watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
|
|
|
+ watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
|
|
|
+ watermark.SetFullScreen(false);
|
|
|
+ watermark.SetVertOffset(0);
|
|
|
+ watermark.SetHorizOffset(0);
|
|
|
+ watermark.SetHorizontalSpacing(0);
|
|
|
+ watermark.SetVerticalSpacing(0);
|
|
|
+ string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
|
|
|
+ watermark.SetPages(setpages);
|
|
|
+ watermark.UpdateWatermark();
|
|
|
+ PDFViewer.Document.ReleasePages();
|
|
|
+ PDFViewer.ReloadDocument();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
|
|
|
if (result)
|
|
|
{
|
|
|
mainViewModel.NewFile = false;
|
|
@@ -3120,7 +3218,9 @@ namespace PDF_Master.ViewModels
|
|
|
}
|
|
|
else
|
|
|
return false;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|