Browse Source

安全 - 保存文件

liuaoran 2 years ago
parent
commit
e49742761e

+ 258 - 0
PDF Office/ComPDFKit.Viewer.csproj

@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{18EC356D-8130-49D4-B4E6-AC290E1065B7}</ProjectGuid>
+    <OutputType>library</OutputType>
+    <RootNamespace>ComPDFKitViewer</RootNamespace>
+    <AssemblyName>ComPDFKit.Viewer</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <WarningLevel>4</WarningLevel>
+    <Deterministic>true</Deterministic>
+    <TargetFrameworkProfile />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>TRACE;DEBUG;PDF_OFFICE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
+    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
+    <DocumentationFile>bin\Release\ComPDFKit.Viewer.xml</DocumentationFile>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xaml">
+      <RequiredTargetFramework>4.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="WindowsBase" />
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="AnnotEdit\AreaSelectTool.cs" />
+    <Compile Include="AnnotEdit\CircleCreate.cs" />
+    <Compile Include="AnnotEdit\EraseCreate.cs" />
+    <Compile Include="AnnotEdit\FreehandCreate.cs" />
+    <Compile Include="AnnotEdit\FreeTextCreate.cs" />
+    <Compile Include="AnnotEdit\ImageEditTool.cs" />
+    <Compile Include="AnnotEdit\LineCreate.cs" />
+    <Compile Include="AnnotEdit\LinkAnnotCreate.cs" />
+    <Compile Include="AnnotEdit\RedactionCreate.cs" />
+    <Compile Include="AnnotEdit\RedactionEraseCreate.cs" />
+    <Compile Include="AnnotEdit\SelectAnnotTool.cs" />
+    <Compile Include="AnnotEdit\SelectEditTool.cs" />
+    <Compile Include="AnnotEdit\SelectTool.cs" />
+    <Compile Include="AnnotEdit\SimpleShapeCreate.cs" />
+    <Compile Include="AnnotEdit\SnapshotTool.cs" />
+    <Compile Include="AnnotEdit\SnapshotWithEditTool.cs" />
+    <Compile Include="AnnotEdit\SoundCreate.cs" />
+    <Compile Include="AnnotEdit\SquareCreate.cs" />
+    <Compile Include="AnnotEdit\StampCreate.cs" />
+    <Compile Include="AnnotEdit\StickyNoteCreate.cs" />
+    <Compile Include="AnnotEdit\TextEditManager.cs" />
+    <Compile Include="AnnotEdit\TextEditTool.cs" />
+    <Compile Include="AnnotEdit\TextHighlightCreate.cs" />
+    <Compile Include="AnnotEdit\TextSquigglyCreate.cs" />
+    <Compile Include="AnnotEdit\TextStrikeoutCreate.cs" />
+    <Compile Include="AnnotEdit\TextUnderlineCreate.cs" />
+    <Compile Include="AnnotEdit\Tool.cs" />
+    <Compile Include="AnnotEdit\ToolManager.cs" />
+    <Compile Include="AnnotEdit\UndoHistoryItem.cs" />
+    <Compile Include="AnnotEdit\UndoManager.cs" />
+    <Compile Include="AnnotEdit\UndoManager.Internal.cs" />
+    <Compile Include="AnnotEdit\WidgetCreate.cs" />
+    <Compile Include="AnnotEdit\WidgetCreate.Function.cs" />
+    <Compile Include="AnnotEvent\AnnotCommandArgs.cs" />
+    <Compile Include="AnnotEvent\CircleAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\EraseArgs.cs" />
+    <Compile Include="AnnotEvent\FreehandAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\FreeTextAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\LineAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\LinkAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\RedactionAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\RedactionEraseArgs.cs" />
+    <Compile Include="AnnotEvent\SelectAnnotToolArgs.cs" />
+    <Compile Include="AnnotEvent\SnapshotCommandArgs.cs" />
+    <Compile Include="AnnotEvent\SnapshotEditToolArgs.cs" />
+    <Compile Include="AnnotEvent\SnapshotToolArgs.cs" />
+    <Compile Include="AnnotEvent\SoundAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\SquareAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\StampAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\StickyAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\TextHighlightAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\TextSquigglyAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\TextStrikeoutAnnotArgs.cs" />
+    <Compile Include="AnnotEvent\TextUnderlineAnnotArgs.cs" />
+    <Compile Include="AnnotEdit\AnnotToolManager.cs" />
+    <Compile Include="AnnotEvent\WidgetViewCommandArgs.cs" />
+    <Compile Include="AnnotView\AnnotAttrib.cs" />
+    <Compile Include="AnnotView\AnnotHoverData.cs" />
+    <Compile Include="AnnotView\AnnotVisualText.cs" />
+    <Compile Include="AnnotView\CommonDrawData.cs" />
+    <Compile Include="AnnotView\CustomTextSource.cs" />
+    <Compile Include="AnnotView\Form\WidgetArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetCheckBoxArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetComboBoxArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetListBoxArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetPushButtonArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetRadioButtonArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetSignArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetTextBoxArgs.cs" />
+    <Compile Include="AnnotView\Form\WidgetView.Function.cs" />
+    <Compile Include="AnnotView\Form\WidgetView.Internal.cs" />
+    <Compile Include="AnnotView\LinkAnnotView.cs" />
+    <Compile Include="AnnotView\MovieAnnotView.cs" />
+    <Compile Include="AnnotView\MultiActiveVisual.cs" />
+    <Compile Include="AnnotView\RedactionAnnot.cs" />
+    <Compile Include="AnnotView\SoundAnnotView.cs" />
+    <Compile Include="AnnotView\StickyPopupControl.xaml.cs">
+      <DependentUpon>StickyPopupControl.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="AnnotView\StickyPopupExt.cs" />
+    <Compile Include="Arrow\ArrowHelper.cs" />
+    <Compile Include="PdfViewer\AdornerDrawing.cs" />
+    <Compile Include="PdfViewer\OrderList.cs" />
+    <Compile Include="PdfViewer\PageImageItem.cs" />
+    <Compile Include="PdfViewer\PagesViewer.Data.cs" />
+    <Compile Include="PdfViewer\PagesViewer.Event.cs" />
+    <Compile Include="PdfViewer\PagesViewer.Internal.cs" />
+    <Compile Include="TextEdit\BaseEditVisual.cs" />
+    <Compile Include="TextEdit\BaseEditVisual.Data.cs" />
+    <Compile Include="TextEdit\BaseEditVisual.Draw.cs" />
+    <Compile Include="TextEdit\CaretVisual.cs" />
+    <Compile Include="AnnotView\FontRendering.cs" />
+    <Compile Include="AnnotView\Form\WidgetView.cs" />
+    <Compile Include="AnnotView\FreehandAnnot.cs" />
+    <Compile Include="AnnotView\FreeTextAnnot.cs" />
+    <Compile Include="AnnotView\GenericTextProperties.cs" />
+    <Compile Include="AnnotView\StickyPopWindow.cs" />
+    <Compile Include="AnnotView\StampAnnot.cs" />
+    <Compile Include="AnnotView\StickyNoteAnnot.cs" />
+    <Compile Include="AnnotView\TextHightlightAnnot.cs" />
+    <Compile Include="AnnotView\TextSquigglyAnnot.cs" />
+    <Compile Include="AnnotView\TextStrikeoutAnnot.cs" />
+    <Compile Include="AnnotView\TextUnderlineAnnot.cs" />
+    <Compile Include="CPDFWrapper.cs" />
+    <Compile Include="AnnotEvent\AnnotHandlerEventArgs.cs" />
+    <Compile Include="AnnotView\AnnotVisualRect.cs" />
+    <Compile Include="AnnotView\CircleAnnotVisual.cs" />
+    <Compile Include="PdfViewer\AdornerContentPresenter.cs" />
+    <Compile Include="PdfViewer\CommandArgs.cs" />
+    <Compile Include="PdfViewer\Helpers.cs" />
+    <Compile Include="AnnotView\LineAnnotVisual.cs" />
+    <Compile Include="PdfViewer\PageElement.cs" />
+    <Compile Include="PdfViewer\PagesViewer.Command.cs" />
+    <Compile Include="PdfViewer\PagesViewer.cs" />
+    <Compile Include="PdfViewer\PagesViewer.Method.cs" />
+    <Compile Include="PdfViewer\PoistionNotify.cs" />
+    <Compile Include="PdfViewer\RenderElement.cs" />
+    <Compile Include="PdfViewer\RenderJobThread.cs" />
+    <Compile Include="PdfViewer\CPDFViewer.Method.cs" />
+    <Compile Include="AnnotView\SquareAnnotVisual.cs" />
+    <Compile Include="PdfViewer\PDFTextSearch.cs" />
+    <Compile Include="PdfViewer\TextSelectInfo.cs" />
+    <Compile Include="PdfViewer\ViewMode.cs" />
+    <Compile Include="AnnotView\VisualElement.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+    <Compile Include="PdfViewer\RenderViewer.cs" />
+    <Compile Include="PdfViewer\CPDFViewer.cs" />
+    <Compile Include="TextEdit\ImageEditVisual.cs" />
+    <Compile Include="TextEdit\ImageEditVisual.Draw.cs" />
+    <Compile Include="TextEdit\ImageEditVisual.Function.cs" />
+    <Compile Include="TextEdit\IME.cs" />
+    <Compile Include="TextEdit\PDFEditEvent.cs" />
+    <Compile Include="TextEdit\PDFEditCommand.cs" />
+    <Compile Include="TextEdit\TextEditVisual.cs" />
+    <Compile Include="TextEdit\TextEditVisual.Draw.cs" />
+    <Compile Include="TextEdit\TextEditVisual.Function.cs" />
+    <Compile Include="Tools\Tools.cs" />
+    <Compile Include="AnnotEdit\WidgetToolManager.cs" />
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+    </EmbeddedResource>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+  </ItemGroup>
+  <ItemGroup />
+  <ItemGroup>
+    <EmbeddedResource Include="Resource\PanTool2.cur" />
+    <EmbeddedResource Include="Resource\PanTool.cur" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Resource\AnnotEdit.cur" />
+  </ItemGroup>
+  <ItemGroup>
+    <Page Include="AnnotView\StickyPopupControl.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\ComPDFKitCSharp\ComPDFKit.Desk.csproj">
+      <Project>{56e518ad-c126-4b48-9a09-0a64c87020e4}</Project>
+      <Name>ComPDFKit.Desk</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 32 - 25
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -32,11 +32,11 @@ namespace PDF_Office.ViewModels.Tools
         private ViewContentViewModel viewContentViewModel;
 
         public IDialogService dialogs;
-        public CropPageUndoManager UndoManager=new CropPageUndoManager();
+        public CropPageUndoManager UndoManager = new CropPageUndoManager();
         public IEventAggregator eventAggregator;
         List<int> cropCurrentPageList = new List<int>();
-        
-       
+
+
         private CPDFDocument.GetPageIndexDelegate indexDelegate = null;
 
 
@@ -173,31 +173,34 @@ namespace PDF_Office.ViewModels.Tools
                 VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
                 if (result.IsDiscryptied)
                 {
+
                     if (result.Password != null)
                     {
                         string filePath = PDFViewer.Document.FilePath;
                         PDFViewer.Document.Release();
                         PDFViewer.InitDocument(filePath);
+                        PDFViewer.Load();
                         PDFViewer.Document.UnlockWithPassword(result.Password);
                     }
-                }
-            }
 
-            DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PDFViewer, this.PDFViewer);
-            value.Add(ParameterNames.ViewContentViewModel, this.viewContentViewModel);
-            dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
-            {
-                if (e.Result == ButtonResult.OK)
-                {
-                    SecurityHelper.IsPasswordChanged = true;
-                    if (viewContentViewModel.SecurityInfo.IsPasswordChanged)
+
+                    DialogParameters value = new DialogParameters();
+                    value.Add(ParameterNames.PDFViewer, this.PDFViewer);
+                    value.Add(ParameterNames.ViewContentViewModel, this.viewContentViewModel);
+                    dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
                     {
-                        viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
-                    }
-                    this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
+                        if (e.Result == ButtonResult.OK)
+                        {
+                            SecurityHelper.IsPasswordChanged = true;
+                            if (viewContentViewModel.SecurityInfo.IsPasswordChanged)
+                            {
+                                viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
+                            }
+                            this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
+                        }
+                    });
                 }
-            });
+            }
         }
 
         private void OpenCancelPasswordDialog()
@@ -228,10 +231,10 @@ namespace PDF_Office.ViewModels.Tools
         private async void CropCurrentPageWM()
         {
             viewContentViewModel.IsLoading = Visibility.Visible;
-           await WaitCropCurrentPageWM();
+            await WaitCropCurrentPageWM();
             viewContentViewModel.IsLoading = Visibility.Collapsed;
         }
-        private async void  CropAllPagesWM()
+        private async void CropAllPagesWM()
         {
             viewContentViewModel.IsLoading = Visibility.Visible;
             await WaitCropAllPagesWM();
@@ -240,8 +243,10 @@ namespace PDF_Office.ViewModels.Tools
             //PDFViewer.UndoManager.AddHistory();
         }
 
-        private async Task WaitCropCurrentPageWM() {
-            await Task.Run(() => {
+        private async Task WaitCropCurrentPageWM()
+        {
+            await Task.Run(() =>
+            {
                 if (PDFViewer.CurrentIndex > 0)
                 {
                     UndoManager.cropPageList.Add(PDFViewer.CurrentIndex);
@@ -251,11 +256,13 @@ namespace PDF_Office.ViewModels.Tools
                 PDFViewer.UndoManager.AddHistory(UndoManager);
                 PDFViewer.UndoManager.CanSave = true;
             });
-            
+
         }
 
-        private async Task WaitCropAllPagesWM() {
-            await Task.Run(() => {
+        private async Task WaitCropAllPagesWM()
+        {
+            await Task.Run(() =>
+            {
                 List<int> cropPagesList = new List<int>();
                 for (int i = 0; i < PDFViewer.Document.PageCount; i++)
                 {

+ 36 - 58
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -650,7 +650,7 @@ namespace PDF_Office.ViewModels
                     break;
             }
 
-            if(!string.IsNullOrEmpty(url))
+            if (!string.IsNullOrEmpty(url))
             {
                 //需要跳转网页的情况
                 System.Diagnostics.Process.Start(url);
@@ -1541,6 +1541,12 @@ namespace PDF_Office.ViewModels
                         return false;
                 }
 
+                //Security Fixed:
+                //修改密码后原文档保存的步骤:
+                //在设置密码窗口传出“已修改”信号,并允许延迟保存
+                //延迟保存方式:
+                //
+                //
                 if (SecurityInfo.IsPasswordChanged)
                 {
                     string currentFilePath = PDFViewer.Document.FilePath;
@@ -1558,80 +1564,52 @@ namespace PDF_Office.ViewModels
                         permissionsPassword = SecurityInfo.PermissionsPassword;
                         cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
                     }
-                    //方案一
-                    if (false)
+
+                    try
                     {
+                        string currentPath = PDFViewer.Document.FilePath;
+                        string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
                         PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                        AlertsMessage alertsMessage = new AlertsMessage();
-                        alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
-                        if (alertsMessage.result == ContentResult.Ok)
-                            return saveAsFile();
-                        else
-                            return false;
-                    }
-                    else if (false)
-                    {
-                        //方案二
-                        try
+
+                        PDFViewer.Document.WriteToFilePath(tempPath);
+                        PDFViewer.CloseDocument();
+                        PDFViewer.InitDocument(tempPath);
+                        if (!string.IsNullOrEmpty(permissionsPassword))
                         {
-                            string currentPath = PDFViewer.Document.FilePath;
-                            string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
-                            //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                            PDFViewer.Document.WriteToFilePath(tempPath);
-                            PDFViewer.CloseDocument();
-                            PDFViewer.InitDocument(tempPath);
                             PDFViewer.Document.UnlockWithPassword(permissionsPassword);
-                            PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                            PDFViewer.Document.WriteToFilePath(currentPath);
-                            PDFViewer.CloseDocument();
-                            PDFViewer.InitDocument(currentPath);
-                            System.IO.File.Delete(tempPath);
-                            PDFViewer.Document.UnlockWithPassword(permissionsPassword);
-                            CanSave = false;
-                            return true;
                         }
-                        catch
+                        else if (!string.IsNullOrEmpty(openPassword))
                         {
-                            return false;
+                            PDFViewer.Document.UnlockWithPassword(openPassword);
                         }
-
-                    }
-                    else if(false)
-                    {
-                        //方案三
                         PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                        if (PDFViewer.Document.WriteToFilePath(PDFViewer.Document.FilePath))
+
+                        PDFViewer.Document.WriteToFilePath(currentPath);
+                        PDFViewer.CloseDocument();
+                        PDFViewer.InitDocument(currentPath);
+                        //System.IO.File.Delete(tempPath);
+
+                        if (!string.IsNullOrEmpty(permissionsPassword))
                         {
-                            DoAfterSaveAs(PDFViewer.Document.FilePath);
-                            return true;
+                            PDFViewer.Document.UnlockWithPassword(permissionsPassword);
                         }
-                        else
+                        else if (!string.IsNullOrEmpty(openPassword))
                         {
-                            return false;
+                            PDFViewer.Document.UnlockWithPassword(openPassword);
                         }
-                    }
-                }
 
-                bool result;
-                if (SecurityInfo.IsPasswordChanged)
-                {
-                    string openPassword = null;
-                    string permissionsPassword = null;
-                    CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
-                    if (SecurityInfo.NeedOpenPassword)
-                    {
-                        openPassword = SecurityInfo.OpenPassword;
+                        PDFViewer.Load();
+                        PDFViewer.UndoManager.CanSave = false;
+                        SecurityInfo.IsPasswordChanged = false;
+                        return true;
                     }
-
-                    if (SecurityInfo.NeedPermissionsPassword)
+                    catch
                     {
-                        permissionsPassword = SecurityInfo.PermissionsPassword;
-                        cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
+                        return false;
                     }
-                    PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
                 }
-                //result = PDFViewer.Document.WriteToLoadedPath();
-                result = PDFViewer.Document.WriteToFilePath(PDFViewer.Document.FilePath);
+
+                bool  result = PDFViewer.Document.WriteToLoadedPath();
                 if (result)
                 {
                     PDFViewer.UndoManager.CanSave = false;