|
@@ -16,6 +16,7 @@ using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Regions;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
@@ -35,6 +36,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
|
|
|
private CPDFViewer PDFViewer;
|
|
|
|
|
|
+ public IDialogService dialogs;
|
|
|
+
|
|
|
IEventAggregator eventAggregator;
|
|
|
|
|
|
private List<string> _opacityList = new List<string>();
|
|
@@ -183,7 +186,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
set
|
|
|
{
|
|
|
SetProperty(ref _relativeScaleValue, value);
|
|
|
- WatermarkInfo.ImageSize=RelativeScaleValue;
|
|
|
+ WatermarkInfo.ImageSize = RelativeScaleValue;
|
|
|
eventAggregator.GetEvent<SetWatermarkEvent>().Publish(new WatermarkInfoUnicode
|
|
|
{
|
|
|
Unicode = Unicode,
|
|
@@ -378,9 +381,10 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
|
|
|
public string Unicode = null;
|
|
|
|
|
|
- public WatermarkCreateFileContentViewModel(IEventAggregator eventAggregator)
|
|
|
+ public WatermarkCreateFileContentViewModel(IEventAggregator eventAggregator, IDialogService dialog)
|
|
|
{
|
|
|
this.eventAggregator = eventAggregator;
|
|
|
+ this.dialogs = dialog;
|
|
|
Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
|
|
|
WatermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_IMG;
|
|
|
ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
|
|
@@ -431,7 +435,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
{
|
|
|
if (watermarkItem != null)
|
|
|
{
|
|
|
- watermarkInfo.WatermarkType=C_Watermark_Type.WATERMARK_TYPE_IMG;
|
|
|
+ watermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_IMG;
|
|
|
if (watermarkItem.imagepath != "")
|
|
|
{
|
|
|
FileInfo file = new FileInfo(watermarkItem.imagepath);
|
|
@@ -439,7 +443,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
{
|
|
|
if (file.Extension == ".pdf")
|
|
|
{
|
|
|
- GetBitmapFromDocment(watermarkItem.imagepath);
|
|
|
+ GetBitmapFromDocment(null, watermarkItem.imagepath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -518,7 +522,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
{
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
|
|
|
{
|
|
|
Unicode = Unicode,
|
|
@@ -550,8 +554,8 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
{
|
|
|
|
|
|
WatermarkInfo.Rotation = RotationValue;
|
|
|
- WatermarkInfo.ImageSize=RelativeScaleValue;
|
|
|
- WatermarkInfo.Opacity = (byte)OpacityValue ;
|
|
|
+ WatermarkInfo.ImageSize = RelativeScaleValue;
|
|
|
+ WatermarkInfo.Opacity = (byte)OpacityValue;
|
|
|
WatermarkInfo.VertOffset = float.Parse(VertOffsetValue);
|
|
|
WatermarkInfo.HorizOffset = float.Parse(HorizOffsetValue);
|
|
|
WatermarkInfo.VerticalSpacing = float.Parse(VerticalSpacingValue);
|
|
@@ -628,7 +632,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
{
|
|
|
watermark.SetImage(watermarkInfo.ImageArray, watermarkInfo.ImageWidth, watermarkInfo.ImageHeight);
|
|
|
}
|
|
|
- watermark.SetScale(watermarkInfo.ImageSize/100);
|
|
|
+ watermark.SetScale(watermarkInfo.ImageSize / 100);
|
|
|
}
|
|
|
watermark.SetRotation((float)((watermarkInfo.Rotation / 180) * Math.PI));
|
|
|
watermark.SetOpacity((byte)(((float)watermarkInfo.Opacity / 100) * 255));
|
|
@@ -677,7 +681,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
CPDFDocument tempDocument = CPDFDocument.CreateDocument();
|
|
|
if (tempDocument != null)
|
|
|
{
|
|
|
- tempDocument.InsertPage(0, pageSize.Width/4, pageSize.Height, null);
|
|
|
+ tempDocument.InsertPage(0, pageSize.Width / 4, pageSize.Height, null);
|
|
|
CreateWatermark(tempDocument, WatermarkInfo);
|
|
|
//获取透明背景的图片
|
|
|
var bitmap = ToolMethod.RenderPageBitmapNoWait(tempDocument, (int)pageSize.Width, (int)pageSize.Height, 0, false, false, 0x00FFFFFF);
|
|
@@ -724,7 +728,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
OpacityText = WatermarkInfo.Opacity.ToString() + " %";
|
|
|
RelativeScaleText = WatermarkInfo.TextSize.ToString() + " %";
|
|
|
InitLocationButtonMatrix();
|
|
|
- CreateFileVisible=Visibility.Visible;
|
|
|
+ CreateFileVisible = Visibility.Visible;
|
|
|
IsRelativeScaleValue = WatermarkInfo.IsRelativeScale;
|
|
|
IsFullValue = WatermarkInfo.Isfull;
|
|
|
RelativeScaleText = WatermarkInfo.ImageSize.ToString() + " %";
|
|
@@ -741,7 +745,28 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
FileInfo file = new FileInfo(dlg.FileName);
|
|
|
if (file.Extension == ".pdf")
|
|
|
{
|
|
|
- GetBitmapFromDocment(dlg.FileName);
|
|
|
+ CPDFDocument document = CPDFDocument.InitWithFilePath(dlg.FileName);
|
|
|
+ if (document.IsLocked)
|
|
|
+ {
|
|
|
+ //DialogParameters value = new DialogParameters();
|
|
|
+ //value.Add(ParameterNames.PDFDocument, document);
|
|
|
+ //dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
|
|
|
+ //{
|
|
|
+ // if (e.Result == ButtonResult.OK)
|
|
|
+ // {
|
|
|
+ // if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
|
|
|
+ // {
|
|
|
+ // document.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //});
|
|
|
+ //if (document.IsLocked)
|
|
|
+ //{
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GetBitmapFromDocment(document);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -749,17 +774,22 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
|
|
|
}
|
|
|
WatermarkInfo.ImagePath = dlg.FileName;
|
|
|
CreateFileVisible = Visibility.Visible;
|
|
|
- eventAggregator.GetEvent<SetWatermarkEvent>().Publish(new WatermarkInfoUnicode
|
|
|
- {
|
|
|
- Unicode = Unicode,
|
|
|
- Status = WatermarkInfo
|
|
|
- });
|
|
|
+
|
|
|
}
|
|
|
+ else { return; }
|
|
|
+ eventAggregator.GetEvent<SetWatermarkEvent>().Publish(new WatermarkInfoUnicode
|
|
|
+ {
|
|
|
+ Unicode = Unicode,
|
|
|
+ Status = WatermarkInfo
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- public async void GetBitmapFromDocment(string filePath)
|
|
|
+ public async void GetBitmapFromDocment(CPDFDocument document = null, string filePath = "")
|
|
|
{
|
|
|
- CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
|
|
|
+ if (document == null)
|
|
|
+ {
|
|
|
+ document = CPDFDocument.InitWithFilePath(filePath);
|
|
|
+ }
|
|
|
CPDFPage page = document.PageAtIndex(0);
|
|
|
byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
|
|
|
await Task.Run(delegate
|