liyijie преди 2 години
родител
ревизия
54abfd8c86

+ 6 - 3
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageBackground/HomePageBackgroundCreateFileContentViewModel.cs

@@ -334,7 +334,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 FileInfo file = new FileInfo(dlg.FileName);
                 if (file.Extension == ".pdf")
                 {
-                    GetBitmapFromDocment(dlg.FileName);
+                    GetBitmapFromDocment(null,dlg.FileName);
                 }
                 else
                 {
@@ -346,9 +346,12 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             }
         }
 
-        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

+ 33 - 5
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkCreateFileContentViewModel.cs

@@ -22,6 +22,7 @@ using System.Windows;
 using System.Threading.Tasks;
 using PDF_Office.Model.EditTools.Background;
 using PDF_Office.Model.EditTools.HeaderFooter;
+using Prism.Services.Dialogs;
 
 namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark
 {
@@ -34,6 +35,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
         private CPDFViewer PDFViewer;
 
         IEventAggregator eventAggregator;
+        public IDialogService dialogs;
 
         private List<string> _opacityList = new List<string>();
         public List<string> OpacityList
@@ -320,7 +322,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
 
         public string Unicode = null;
 
-        public HomePageWatermarkCreateFileContentViewModel(IEventAggregator eventAggregator)
+        public HomePageWatermarkCreateFileContentViewModel(IEventAggregator eventAggregator, IDialogService dialogs)
         {
             this.eventAggregator = eventAggregator;
             WatermarkInfo.WatermarkType = C_Watermark_Type.WATERMARK_TYPE_IMG;
@@ -331,6 +333,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             InitLocationButtonMatrix();
             eventAggregator.GetEvent<SaveWatermarkTemplateEvent>().Subscribe(SaveWatermarkTemplate, e => e.Unicode == Unicode);
             eventAggregator.GetEvent<ConfirmEditWatermarkTemplateItemEvent>().Subscribe(ConfirmEditWatermarkTemplateItem, e => e.Unicode == Unicode);
+            this.dialogs = dialogs;
         }
 
         public void SaveWatermarkTemplate(EnumTextOrFileUnicode enumTextOrFileunicode)
@@ -387,7 +390,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                     {
                         if (file.Extension == ".pdf")
                         {
-                            GetBitmapFromDocment(watermarkItem.imagepath);
+                            GetBitmapFromDocment(null,watermarkItem.imagepath);
                         }
                         else
                         {
@@ -681,7 +684,28 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
                 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
                 {
@@ -692,9 +716,13 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             }
         }
 
-        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

+ 4 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkCreateTextContentViewModel.cs

@@ -320,7 +320,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
             {
                 SetProperty(ref _isFullValue, value);
                 WatermarkInfo.Isfull = IsFullValue;
-                
+                if (IsRelativeScaleValue == true) { IsRelativeScaleValue = false; }
+               
+
+
             }
         }
 

+ 22 - 6
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageInsertDialogViewModel.cs

@@ -22,6 +22,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
 
         private HomePageInsertDialogModel insertModel = new HomePageInsertDialogModel();
 
+        public IDialogService dialogs;
+
         private string selectFilePath = "选择文件";
         public string SelectFilePath
         {
@@ -101,7 +103,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
         public DelegateCommand CustomPageCommand { get; set; }
         #endregion
 
-        public HomePageInsertDialogViewModel()
+        public HomePageInsertDialogViewModel(IDialogService dialogs)
         {
             CancelCommand = new DelegateCommand(cancel);
             InsertCommand = new DelegateCommand(insert);
@@ -109,6 +111,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
             FirstPageCommand = new DelegateCommand(firstPage);
             LastPageCommand = new DelegateCommand(lastPage);
             CustomPageCommand = new DelegateCommand(customPage);
+            this.dialogs = dialogs;
         }
         #region 逻辑函数
         private void cancel()
@@ -127,12 +130,25 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
                 MessageBoxEx.Show("文档为空");
                 return;
             }
-            if (insertdocument.IsEncrypted)
+            if (insertdocument.IsLocked)
             {
-                Trace.WriteLine("youmima");
-                MessageBoxEx.Show("文档加密");
-                //TODO
-                return;
+                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 (insertdocument.IsLocked)
+                {
+
+                    return;
+                }
             }
 
             insertModel.InsertIndex = int.Parse(PageInsertIndex);

+ 48 - 18
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateFileContentViewModel.cs

@@ -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

+ 2 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateTextContentViewModel.cs

@@ -367,11 +367,13 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 SetProperty(ref _isFullValue, value);
                 WatermarkInfo.Isfull = IsFullValue;
+                if (IsRelativeScaleValue == true) {  IsRelativeScaleValue = false;}
                 eventAggregator.GetEvent<SetWatermarkEvent>().Publish(new WatermarkInfoUnicode
                 {
                     Unicode = Unicode,
                     Status = WatermarkInfo
                 });
+               
             }
         }
 

+ 1 - 1
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageBatchProcessing/HomePageWatermark/HomePageWatermarkCreateTextContent.xaml

@@ -66,7 +66,7 @@
                     </StackPanel>
                 </StackPanel>
                 <ComboBox Height="32" Margin="0,8,0,0" ItemsSource="{Binding IsFrontList}" SelectedIndex="{Binding IsFrontSelectedIndex}"></ComboBox>
-                <CheckBox Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,11,0,0" Name="RelativeScaleCheckBox" IsChecked="{Binding IsRelativeScaleValue}">
+                <CheckBox Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,11,0,0" Name="RelativeScaleCheckBox" IsChecked="{Binding IsRelativeScaleValue}"  IsEnabled = "{Binding ElementName=IsFullCheckBox,Path=IsChecked,Converter={StaticResource InvertBoolConvert}}">
                 </CheckBox>
                 <cus:CommonWritableComboBox Width="66" Height="32" HorizontalAlignment="Left" Margin="0,9,0,0" TypeSouce="{Binding ScaleList,Mode=TwoWay}" IsEnabled="{Binding ElementName=RelativeScaleCheckBox,Path=IsChecked}" Text="{Binding RelativeScaleText,Mode=TwoWay}" Value="{Binding RelativeScaleValue,Mode=TwoWay}"></cus:CommonWritableComboBox>
             </StackPanel>

+ 1 - 1
PDF Office/Views/EditTools/Watermark/WatermarkCreateTextContent.xaml

@@ -66,7 +66,7 @@
                     </StackPanel>
                 </StackPanel>
                 <ComboBox Height="32" Margin="0,8,0,0" ItemsSource="{Binding IsFrontList}" SelectedIndex="{Binding IsFrontSelectedIndex}"></ComboBox>
-                <CheckBox Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,11,0,0" Name="RelativeScaleCheckBox" IsChecked="{Binding IsRelativeScaleValue}">
+                <CheckBox Style="{StaticResource EditToolsCheckBoxStyle}" Content="相对目标页面的比例" Margin="0,11,0,0" Name="RelativeScaleCheckBox" IsChecked="{Binding IsRelativeScaleValue}" IsEnabled="{Binding ElementName=IsFullCheckBox,Path=IsChecked,Converter={StaticResource InvertBoolConvert}}">
                 </CheckBox>
                 <cus:CommonWritableComboBox Width="66" Height="32" HorizontalAlignment="Left" Margin="0,9,0,0" TypeSouce="{Binding ScaleList,Mode=TwoWay}" IsEnabled="{Binding ElementName=RelativeScaleCheckBox,Path=IsChecked}" Text="{Binding RelativeScaleText,Mode=TwoWay}" Value="{Binding RelativeScaleValue,Mode=TwoWay}"></cus:CommonWritableComboBox>
             </StackPanel>