Explorar el Código

拆解,提取,插入

liyijie hace 2 años
padre
commit
51a62600dc
Se han modificado 24 ficheros con 1601 adiciones y 416 borrados
  1. 1 1
      PDF Office/CustomControl/NumericUpDown.xaml
  2. 16 5
      PDF Office/CustomControl/NumericUpDown.xaml.cs
  3. 27 0
      PDF Office/CustomControl/PageTurningPreview.xaml
  4. 103 0
      PDF Office/CustomControl/PageTurningPreview.xaml.cs
  5. 6 4
      PDF Office/CustomControl/WritableComboBox.xaml
  6. 33 2
      PDF Office/CustomControl/WritableComboBox.xaml.cs
  7. 108 0
      PDF Office/Helper/HomePageEditHelper.cs
  8. 85 85
      PDF Office/Model/DialogNames.cs
  9. 7 7
      PDF Office/Model/MainPageToolsDialogs/MainPageExtractDialogModel.cs
  10. 22 0
      PDF Office/Model/HomePageToolsDialogs/HomePageInsertDialogModel.cs
  11. 58 0
      PDF Office/Model/HomePageToolsDialogs/HomePageSplitDialogModel.cs
  12. 0 26
      PDF Office/Model/MainPageToolsDialogs/MainPageInsertDialogModel.cs
  13. 0 44
      PDF Office/Model/MainPageToolsDialogs/MainPageSplitDialogModel.cs
  14. 11 3
      PDF Office/PDF Office.csproj
  15. 186 34
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageExtractDialogViewModel.cs
  16. 233 34
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageInsertDialogViewModel.cs
  17. 45 35
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs
  18. 494 33
      PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageSplitDialogViewModel.cs
  19. 54 25
      PDF Office/ViewModels/HomePanel/HomeGuidContentViewModel.cs
  20. 22 21
      PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageExtractDialog.xaml
  21. 30 25
      PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageInsertDialog.xaml
  22. 30 29
      PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageSplitDialog.xaml
  23. 29 2
      PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageSplitDialog.xaml.cs
  24. 1 1
      PDF Office/Views/Dialog/PageEditDialogs/InsertDialog.xaml

+ 1 - 1
PDF Office/CustomControl/NumericUpDown.xaml

@@ -11,7 +11,7 @@
             <ColumnDefinition Width="4*"/>
             <ColumnDefinition Width="1*"/>
         </Grid.ColumnDefinitions>
-        <TextBox Name="TextBox_Num" Grid.Column="0" Text="1" FontSize="20" TextAlignment="Center" MinWidth="80" MinHeight="20" VerticalContentAlignment="Center" />
+        <TextBox Name="TextBox_Num" Grid.Column="0" Text="1" FontSize="20" TextAlignment="Center" MinWidth="80" MinHeight="20" VerticalContentAlignment="Center" TextChanged="TextBox_Num_TextChanged" InputMethod.IsInputMethodEnabled="False"  PreviewTextInput="CountTextBox_PreviewTextInput" />
         <Grid Grid.Column="1">
             <Grid.RowDefinitions>
                 <RowDefinition/>

+ 16 - 5
PDF Office/CustomControl/NumericUpDown.xaml.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
@@ -49,6 +50,7 @@ namespace PDF_Office.CustomControl
             if (num > 0)
             {
                 this.TextBox_Num.Text = (num + 1).ToString();
+                Text = this.TextBox_Num.Text;
             }
         }
 
@@ -60,21 +62,30 @@ namespace PDF_Office.CustomControl
                 if ((num - 1) == 0)
                     return;
                 this.TextBox_Num.Text = (num - 1).ToString();
+                Text = this.TextBox_Num.Text;
             }
         }
         
         
 
-        public int MyProperty
+        public string Text
         {
-            get { return (int)GetValue(MyPropertyProperty); }
-            set { SetValue(MyPropertyProperty, value); }
+            get { return (string)GetValue(TextProperty); }
+            set { SetValue(TextProperty, value); }
         }
 
         // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MyPropertyProperty =
-            DependencyProperty.Register("MyProperty", typeof(int), typeof(NumericUpDown), new PropertyMetadata(0));
+        public static readonly DependencyProperty TextProperty =
+            DependencyProperty.Register("Text", typeof(string), typeof(NumericUpDown), new PropertyMetadata(""));
 
+        private void TextBox_Num_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            Text = this.TextBox_Num.Text;
+        }
 
+        private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
+        }
     }
 }

+ 27 - 0
PDF Office/CustomControl/PageTurningPreview.xaml

@@ -0,0 +1,27 @@
+<UserControl x:Class="PDF_Office.CustomControl.PageTurningPreview"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PDF_Office.CustomControl"
+             mc:Ignorable="d" 
+             d:DesignHeight="350" d:DesignWidth="300">
+    <Grid>
+        <Border  Margin="10,40,10,40" Background="LightGray"  Height="218" Width="176">
+            <Viewbox>
+                <Image Name="Image"></Image>
+            </Viewbox>
+        </Border>
+        <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">
+            <Button Name="PrePage" Width="20" Click="PrePage_Click" Height="20" HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+                <TextBlock Text="&lt;" VerticalAlignment="Center" ></TextBlock>
+            </Button>
+            <TextBox x:Name="CurrentPage" Width="30" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="1" InputMethod.IsInputMethodEnabled="False"   PreviewTextInput="CountTextBox_PreviewTextInput" KeyDown="CurrentPage_KeyDown"></TextBox>
+            <TextBlock  Text="of"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0"></TextBlock>
+            <TextBlock x:Name="PageIndex"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"></TextBlock>
+            <Button Name="NextPage" Click="NextPage_Click" Width="20" Height="20" HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+                <TextBlock Text=">" VerticalAlignment="Center"></TextBlock>
+            </Button>
+        </StackPanel>
+    </Grid>
+</UserControl>

+ 103 - 0
PDF Office/CustomControl/PageTurningPreview.xaml.cs

@@ -0,0 +1,103 @@
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.Xml.Linq;
+
+namespace PDF_Office.CustomControl
+{
+    /// <summary>
+    /// PageTurningPreview.xaml 的交互逻辑
+    /// </summary>
+    public partial class PageTurningPreview : UserControl
+    {
+        public static CPDFDocument document;
+        public PageTurningPreview()
+        {
+            InitializeComponent();
+            if (document!=null) {
+                AwaitRenderBitmap(document);
+                this.PageIndex.Text = document.PageCount.ToString();
+            }
+            
+        }
+
+        public async Task RenderBitmap(CPDFDocument doc)
+        {
+            CPDFPage page = new CPDFPage(doc, int.Parse(this.CurrentPage.Text) - 1, true);
+            byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
+            await Task.Run(delegate
+            {
+                page.RenderPageBitmap(0, 0, (int)page.PageSize.Width, (int)page.PageSize.Height, 0xffffffff, bmp_data, 1);
+            });
+            PixelFormat fmt = PixelFormats.Bgra32;
+            BitmapSource bps = BitmapSource.Create((int)page.PageSize.Width, (int)page.PageSize.Height, 96.0, 96.0, fmt, null, bmp_data, ((int)page.PageSize.Width * fmt.BitsPerPixel + 7) / 8);
+            this.Image.Source = bps;
+        }
+        public async void AwaitRenderBitmap(CPDFDocument doc)
+        {
+            await RenderBitmap(doc);
+        }
+
+        private void PrePage_Click(object sender, RoutedEventArgs e)
+        {
+            if (int.Parse(this.CurrentPage.Text) > 1)
+            {
+                int Page = int.Parse(this.CurrentPage.Text);
+                this.CurrentPage.Text = (--Page).ToString();
+                if (document != null)
+                {
+                    AwaitRenderBitmap(document);
+                }
+            }
+        }
+
+        private void NextPage_Click(object sender, RoutedEventArgs e)
+        {
+            if (int.Parse(this.CurrentPage.Text) < document.PageCount)
+            {
+                int Page = int.Parse(this.CurrentPage.Text);
+                this.CurrentPage.Text = (++Page).ToString();
+                if (document != null)
+                {
+                    AwaitRenderBitmap(document);
+                }
+            }
+        }
+
+        private async void CurrentPage_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.Key == Key.Enter)
+            {
+                if (int.Parse(this.CurrentPage.Text) <= document.PageCount && int.Parse(this.CurrentPage.Text) > 0)
+                {
+                    AwaitRenderBitmap(document);
+                }
+                else
+                {
+                    MessageBox.Show("超出页面范围");
+                }
+            }
+        }
+
+        private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
+        }
+    }
+}
+
+

+ 6 - 4
PDF Office/CustomControl/WritableComboBox.xaml

@@ -10,11 +10,13 @@
 
 
         <ComboBox x:Name="writableComboBox" Grid.Column="1"  Visibility="Visible" MinHeight="32"  MinWidth="58"
-                                      SelectionChanged="writableComboBox_SelectionChanged">
-            <ComboBoxItem Tag="0">关</ComboBoxItem>
-            <ComboBoxItem Tag="1">开</ComboBoxItem>
+                                      SelectionChanged="writableComboBox_SelectionChanged" SelectedIndex="0">
+            <ComboBoxItem Tag="0">全部页面</ComboBoxItem>
+            <ComboBoxItem Tag="0">奇数页</ComboBoxItem>
+            <ComboBoxItem Tag="1">偶数页</ComboBoxItem>
+            <ComboBoxItem Tag="1">自定义页面</ComboBoxItem>
         </ComboBox>
-        <TextBox  x:Name="writableTextBox" VerticalContentAlignment="Center"  Visibility="Hidden" MinHeight="{Binding ElementName=EnterableComboBox, Path=MinHeight}" Grid.Column="0" HorizontalAlignment="Left" >
+        <TextBox  x:Name="writableTextBox" VerticalContentAlignment="Center"  Visibility="Hidden" MinHeight="{Binding ElementName=EnterableComboBox, Path=MinHeight}" Grid.Column="0" HorizontalAlignment="Left" TextChanged="writableTextBox_TextChange">
         </TextBox>
     </Grid>
 </UserControl>

+ 33 - 2
PDF Office/CustomControl/WritableComboBox.xaml.cs

@@ -32,13 +32,44 @@ namespace PDF_Office.CustomControl
                 this.writableTextBox.Width = this.writableComboBox.ActualWidth - 18;
                 Trace.WriteLine(this.writableComboBox.ActualWidth);
                 this.writableTextBox.Visibility = Visibility.Visible;
+                
             }
             else
-            { 
-                this.writableTextBox.Visibility = Visibility.Collapsed;
+            {
+                if (this.writableTextBox != null) { 
+                this.writableTextBox.Visibility = Visibility.Hidden;
+                }
+           this.SelectedIndex=this.writableComboBox.SelectedIndex.ToString();
             }
         }
 
+        public string SelectedIndex
+        {
+            get { return (string)GetValue(SelectedIndexProperty); }
+            set { SetValue(SelectedIndexProperty, value); }
+        }
 
+        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty SelectedIndexProperty =
+            DependencyProperty.Register("SelectedIndex", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
+
+        public string Text
+        {
+            get { return (string)GetValue(TextProperty); }
+            set { SetValue(TextProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty TextProperty =
+            DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
+
+        private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
+        {
+            if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
+            {
+                Text = this.writableTextBox.Text;
+            }
+            else { Text = ""; }
+        }
     }
 }

+ 108 - 0
PDF Office/Helper/HomePageEditHelper.cs

@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using ComPDFKitViewer.PdfViewer;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Documents;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
+namespace PDF_Office.Helper
+{
+    public static class HomePageEditHelper
+    {
+        /// <summary>
+        /// 获取所需要分文档份数
+        /// </summary>
+        /// <param name="pagecontent">文档总页数</param>
+        /// <param name="averagepage">平均几页分为一个文档</param>
+        /// <param name="remainder">最后文档的页数的引用 例如11页文档每3页为一份PDF,3,3,3,2,remainder=2</param>
+        /// <returns></returns>
+        public static int AverageSplitPages(int pagecontent, int averagepage, ref int remainder)
+        {
+            if (pagecontent <= 0)
+            {
+                remainder = 0;
+                return 0;
+            }
+            if (pagecontent <= averagepage)
+            {
+                remainder = pagecontent;
+
+                return 1;
+            }
+            if (pagecontent > averagepage)
+            {
+                if (pagecontent % averagepage == 0)
+                {
+                    remainder = 0;
+                    return pagecontent / averagepage;
+                }
+                remainder = pagecontent % averagepage;
+                return (pagecontent / averagepage) + 1;
+
+            }
+            remainder = 0;
+            return -1;
+        }
+        /// <summary>
+        /// 获取平均每个文档的页数
+        /// </summary>
+        /// <param name="pagecontent">文档总页数</param>
+        /// <param name="averagedoc">平均几页分为一个文档</param>
+        /// <param name="remainder">引用,截至第几位文档比后面文档多一 例如11页文档 分为3份 4,4,3 remainder为1 第一个文档和第二文档比后续文档多一</param>
+        /// <returns></returns>
+        public static int AverageSplitDocs(int pagecontent, int averagedoc, ref int remainder)
+        {
+            if (pagecontent <= 0)
+            {
+                remainder = 0;
+                return 0;
+            }
+            if (pagecontent <= averagedoc)
+            {
+                remainder = 0;
+                return 1;
+            }
+            if (pagecontent > averagedoc)
+            {
+                remainder = pagecontent % averagedoc;
+                return pagecontent / averagedoc;
+            }
+            return 0;
+
+        }
+
+        public static void GetPagerange(string PageRangeSelectIndex ,CPDFViewer currentViewer,ref string pageRange,string pageRangeText) {
+            if (PageRangeSelectIndex == "0")
+            {
+                pageRange = "1-" + currentViewer.Document.PageCount.ToString();
+                Trace.WriteLine(" extractModel.PageRange" + pageRange);
+            }
+            else if (PageRangeSelectIndex == "1")
+            {
+                pageRange = "1";
+                for (int i = 3; i <= currentViewer.Document.PageCount; i += 2)
+                    pageRange = pageRange + "," + i;
+                Trace.WriteLine(" extractModel.PageRange" + pageRange);
+            }
+            else if (PageRangeSelectIndex == "2")
+            {
+                pageRange = "2";
+                for (int i = 4; i <= currentViewer.Document.PageCount; i += 2)
+                    pageRange = pageRange + "," + i;
+                Trace.WriteLine(" extractModel.PageRange" + pageRange);
+
+            }
+            else if (PageRangeSelectIndex == "3")
+            {
+                pageRange = pageRangeText;
+                Trace.WriteLine(" extractModel.PageRange" + pageRange);
+            }
+            else { return; }
+        }
+    }
+
+}

+ 85 - 85
PDF Office/Model/DialogNames.cs

@@ -1,89 +1,89 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PDF_Office.Model
-{
-    /// <summary>
-    /// 记录弹窗的名称
-    /// </summary>
-    public static class DialogNames
-    {
-        /// <summary>
-        /// 文档解密弹窗 需要传参PDFDocument对象
-        /// </summary>
-        public static string VerifyPassWordDialog = "PassWordDialog";
-
-        /// <summary>
-        /// 全屏模式弹窗
-        /// </summary>
-        public static string FullScreenDialog = "FullScreenDialog";
-
-        /// <summary>
-        /// 压缩弹窗
-        /// </summary>
-        public static string CompressDialog = "CompressDialog";
-
-        /// <summary>
-        /// 解压缩弹窗
-        /// </summary>
-        public static string SetPasswordDialog = "SetPasswordDialog";
-
-        /// <summary>
-        /// 解压缩弹窗
-        /// </summary>
-        public static string CheckPasswordDialog = "CheckPasswordDialog";
-
-        /// <summary>
-        /// 删除安全性设置
-        /// </summary>
-        public static string DeleteSafetySettingsDialog = "DeleteSafetySettingsDialog";
-
-        /// <summary>
-        /// 进度条
-        /// </summary>
-        public static string CompressProgressBarDialog = "CompressProgressBarDialog"; 
-        /// <summary>
-        /// 页面编辑- 提取弹窗
-        /// </summary>
-        public static string ExtractDialog = "ExtractDialog";
-
-        /// <summary>
-        /// 页面编辑-拆分弹窗
-        /// </summary>
-        public static string SplitDialog = "SplitDialog";
-
-        /// <summary>
-        /// 页面编辑-插入弹窗
-        /// </summary>
-        public static string InsertDialog = "InsertDialog";
-
-        ///<summary>
-        ///主页工具-提取弹窗
-        /// </summary>
-        public static string HomePageExtractDialog = "HomePageExtractDialog";
-
-        ///<summary>
-        ///主页工具-插入弹窗
-        /// </summary
-        public static string HomePageInsertDialog = "HomePageInsertDialog";
-
-        ///<summary>
-        ///主页工具-拆分弹窗
-        /// </summary>
-        public static string HomePageSplitDialog = "HomePageSplitDialog";
-
-        ///<summary>
-        ///主页工具-打印弹窗
-        /// </summary>
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model
+{
+    /// <summary>
+    /// 记录弹窗的名称
+    /// </summary>
+    public static class DialogNames
+    {
+        /// <summary>
+        /// 文档解密弹窗 需要传参PDFDocument对象
+        /// </summary>
+        public static string VerifyPassWordDialog = "PassWordDialog";
+
+        /// <summary>
+        /// 全屏模式弹窗
+        /// </summary>
+        public static string FullScreenDialog = "FullScreenDialog";
+
+        /// <summary>
+        /// 压缩弹窗
+        /// </summary>
+        public static string CompressDialog = "CompressDialog";
+
+        /// <summary>
+        /// 解压缩弹窗
+        /// </summary>
+        public static string SetPasswordDialog = "SetPasswordDialog";
+
+        /// <summary>
+        /// 解压缩弹窗
+        /// </summary>
+        public static string CheckPasswordDialog = "CheckPasswordDialog";
+
+        /// <summary>
+        /// 删除安全性设置
+        /// </summary>
+        public static string DeleteSafetySettingsDialog = "DeleteSafetySettingsDialog";
+
+        /// <summary>
+        /// 进度条
+        /// </summary>
+        public static string CompressProgressBarDialog = "CompressProgressBarDialog"; 
+        /// <summary>
+        /// 页面编辑- 提取弹窗
+        /// </summary>
+        public static string ExtractDialog = "ExtractDialog";
+
+        /// <summary>
+        /// 页面编辑-拆分弹窗
+        /// </summary>
+        public static string SplitDialog = "SplitDialog";
+
+        /// <summary>
+        /// 页面编辑-插入弹窗
+        /// </summary>
+        public static string InsertDialog = "InsertDialog";
+
+        ///<summary>
+        ///主页工具-提取弹窗
+        /// </summary>
+        public static string HomePageExtractDialog = "HomePageExtractDialog";
+
+        ///<summary>
+        ///主页工具-插入弹窗
+        /// </summary
+        public static string HomePageInsertDialog = "HomePageInsertDialog";
+
+        ///<summary>
+        ///主页工具-拆分弹窗
+        /// </summary>
+        public static string HomePageSplitDialog = "HomePageSplitDialog";
+
+        ///<summary>
+        ///主页工具-打印弹窗
+        /// </summary>
         public static string HomePagePrinterDialog = "HomePagePrinterDialog";
 
-        ///<summary>
-        ///打印弹窗-打印页面设置
-        /// </summary>
+        ///<summary>
+        ///打印弹窗-打印页面设置
+        /// </summary>
         public static string HomePagePrinterPageSetDialog = "HomePagePrinterPageSetDialog";
 
-    }
-}
+    }
+}

+ 7 - 7
PDF Office/Model/MainPageToolsDialogs/MainPageExtractDialogModel.cs

@@ -4,25 +4,25 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace PDF_Office.Model.MainPageToolsDialogs
+namespace PDF_Office.Model.HomePageToolsDialogs
 {
-    internal class MainPageExtractDialogModel
+    public class HomePageExtractDialogModel
     {
         /// <summary>
         /// 页码 存入页码范围;
         /// </summary>
-        public List<int> PageParm;
+        public List<int> PageParm=new List<int> { };
         /// <summary>
-        /// 自定模式下 把文本内容传过去
+        /// 页码 存入页码范围;
         /// </summary>
-        public string PageName = "";
+        public string PageRange="1,3-4,10";
         /// <summary>
         /// 是否拆分为单文件
         /// </summary>
-        public bool ExtractToSingleFile;
+        public bool ExtractToSingleFile=true;
         /// <summary>
         /// 提取后删除页面
         /// </summary>
-        public bool DeleteAfterExtract;
+        public bool DeleteAfterExtract=false;
     }
 }

+ 22 - 0
PDF Office/Model/HomePageToolsDialogs/HomePageInsertDialogModel.cs

@@ -0,0 +1,22 @@
+using ComPDFKit.PDFDocument;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.HomePageToolsDialogs
+{
+    public class HomePageInsertDialogModel
+    {
+        public string FilePath = "";
+        public int InsertIndex = 1;
+        public string Password = "";
+        public string InserPageRange(CPDFDocument doc) {
+            if (doc.PageCount < 1) { return ""; }
+            if (doc.PageCount == 1) { return "1"; }
+            return "1"+"-"+ doc.PageCount.ToString();
+        }
+
+    }
+}

+ 58 - 0
PDF Office/Model/HomePageToolsDialogs/HomePageSplitDialogModel.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.HomePageToolsDialogs
+{
+    public class HomePageSplitDialogModel
+    {
+
+        /// <summary>
+        /// 拆分模式
+        /// </summary>
+        public SplitMode Mode = SplitMode.AveragePages;
+        /// <summary>
+        /// 拆分模式份数或者页数
+        /// </summary>
+        public int GetModeCount = 1;
+        /// <summary>
+        /// 页面信息
+        /// </summary>
+        public string PageRange = "1,3-4,10";
+        /// <summary>
+        /// 文件名标签
+        /// </summary>
+        public string FileNameLabel = "part";
+        /// <summary>
+        /// 文件名与标签分隔符
+        /// </summary>
+        public string FileNameDeimiter = "-";
+        /// <summary>
+        /// 文件名与标签分隔符
+        /// </summary>
+        public bool FrontFileName = true;
+        /// <summary>
+        /// 页码 存入页码范围;
+        /// </summary>
+        public List<int> PageParm = new List<int> { };
+
+
+        public enum SplitMode
+        {
+            /// <summary>
+            /// 按页平均拆分
+            /// </summary>
+            AveragePages,
+            /// <summary>
+            /// 按文件平均拆分
+            /// </summary>
+            AverageFiles,
+            /// <summary>
+            /// 自定义页码范围拆分
+            /// </summary>
+            CustomPageRange
+        }
+    }
+}

+ 0 - 26
PDF Office/Model/MainPageToolsDialogs/MainPageInsertDialogModel.cs

@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PDF_Office.Model.MainPageToolsDialogs
-{
-    internal class MainPageInsertDialogModel
-    {
-        public class InsertEventClass : EventArgs
-        {
-            public InsertType Type;
-            public string filePath;
-            public string pageRange;
-            public int InsertIndex;
-            public string Password;
-        }
-
-        public enum InsertType
-        {
-            BlankPages,
-            FromOtherPdf
-        }
-    }
-}

+ 0 - 44
PDF Office/Model/MainPageToolsDialogs/MainPageSplitDialogModel.cs

@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PDF_Office.Model.MainPageToolsDialogs
-{
-    internal class MainPageSplitDialogModel
-    {
-        public class SplitEventClass : EventArgs
-        {
-            /// <summary>
-            /// 拆分模式
-            /// </summary>
-            public SplitMode Mode;
-            /// <summary>
-            /// 文件名
-            /// </summary>
-            public string FileName;
-            /// <summary>
-            /// 页面信息
-            /// </summary>
-            public string PageRange;
-
-        }
-
-        public enum SplitMode
-        {
-            /// <summary>
-            /// 按页平均拆分
-            /// </summary>
-            AveragePages,
-            /// <summary>
-            /// 按文件平均拆分
-            /// </summary>
-            AverageFiles,
-            /// <summary>
-            /// 自定义页码范围拆分
-            /// </summary>
-            CustomPageRange
-        }
-    }
-}

+ 11 - 3
PDF Office/PDF Office.csproj

@@ -159,6 +159,9 @@
     <Compile Include="CustomControl\NumericUpDown.xaml.cs">
       <DependentUpon>NumericUpDown.xaml</DependentUpon>
     </Compile>
+    <Compile Include="CustomControl\PageTurningPreview.xaml.cs">
+      <DependentUpon>PageTurningPreview.xaml</DependentUpon>
+    </Compile>
     <Compile Include="CustomControl\SystemControl\CustomCommandAction .cs" />
     <Compile Include="CustomControl\SystemControl\RoutedEventTrigger.cs" />
     <Compile Include="CustomControl\ToastControl.xaml.cs">
@@ -170,6 +173,7 @@
     <Compile Include="DataConvert\FileFormatToIconConvert.cs" />
     <Compile Include="EventAggregators\PageEditNotifyEvent.cs" />
     <Compile Include="EventAggregators\PageEditRefreshEvent.cs" />
+    <Compile Include="Helper\HomePageEditHelper.cs" />
     <Compile Include="Helper\PasswordBoxHelper.cs" />
     <Compile Include="Helper\SettingHelper.cs" />
     <Compile Include="Helper\ToolMethod.cs" />
@@ -182,9 +186,9 @@
     <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialogModel.cs" />
     <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\DeleteSafetySettintgsModel.cs" />
     <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialogModel.cs" />
-    <Compile Include="Model\MainPageToolsDialogs\MainPageExtractDialogModel.cs" />
-    <Compile Include="Model\MainPageToolsDialogs\MainPageInsertDialogModel.cs" />
-    <Compile Include="Model\MainPageToolsDialogs\MainPageSplitDialogModel.cs" />
+    <Compile Include="Model\HomePageToolsDialogs\HomePageExtractDialogModel.cs" />
+    <Compile Include="Model\HomePageToolsDialogs\HomePageInsertDialogModel.cs" />
+    <Compile Include="Model\HomePageToolsDialogs\HomePageSplitDialogModel.cs" />
     <Compile Include="Model\PageEdit\ExtractModel.cs" />
     <Compile Include="Model\PageEdit\PageEditItem.cs" />
     <Compile Include="Model\ParameterNames.cs" />
@@ -333,6 +337,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="CustomControl\PageTurningPreview.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="CustomControl\ToastControl.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

+ 186 - 34
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageExtractDialogViewModel.cs

@@ -1,34 +1,186 @@
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
-{
-    public class HomePageExtractDialogViewModel : BindableBase,IDialogAware
-    {
-        public HomePageExtractDialogViewModel()
-        {
-
-        }
-
-        public string Title => "";
-
-        public event Action<IDialogResult> RequestClose;
-
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
-
-        public void OnDialogClosed()
-        {
-        }
-
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-        }
-    }
-}
+using ComPDFKit.PDFDocument;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using SQLitePCL;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using PDF_Office.Model.HomePageToolsDialogs;
+using PDF_Office.Helper;
+using System.Diagnostics;
+using PDF_Office.CustomControl;
+
+namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
+{
+    public class HomePageExtractDialogViewModel : BindableBase,IDialogAware
+    {
+        private CPDFDocument document;
+
+        private CPDFViewer currentViewer;
+
+        private HomePageExtractDialogModel extractModel = new HomePageExtractDialogModel();
+
+        private string savefilepath { get; set; }
+
+        public DelegateCommand CancelCommand { get; set; }
+
+        public DelegateCommand ExtractCommand { get; set; }
+
+        public DelegateCommand ExtractToSingleFileCommand { get; set; }
+
+        public DelegateCommand DeleteAfterExtractCommand { get; set; }
+
+        private string extractToSingleFileIsCheck = "False";
+        public string ExtractToSingleFileIsCheck
+        {
+            get { return extractToSingleFileIsCheck; }
+            set
+            {
+                extractToSingleFileIsCheck = value;
+            }
+        }
+
+        private string deleteAfterExtractIsCheck = "Fales";
+        public string DeleteAfterExtractIsCheck
+        {
+            get { return deleteAfterExtractIsCheck; }
+            set
+            {
+                deleteAfterExtractIsCheck = value;
+            }
+        }
+
+        private string pageRangeText = "";
+        public string PageRangeText
+        {
+            get { return pageRangeText; }
+            set
+            {
+                pageRangeText = value;
+            }
+        }
+
+        private string pageRangeSelectIndex = "";
+        public string PageRangeSelectIndex
+        {
+            get { return pageRangeSelectIndex; }
+            set
+            {
+                pageRangeSelectIndex = value;
+            }
+        }
+
+        public HomePageExtractDialogViewModel()
+        {
+            CancelCommand = new DelegateCommand(cancel);
+            ExtractCommand = new DelegateCommand(extract);
+            ExtractToSingleFileCommand = new DelegateCommand(extractToSingleFile);
+            DeleteAfterExtractCommand = new DelegateCommand(deleteAfterExtract);
+
+        }
+
+        private void cancel()
+        {
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+
+        private void extract()
+        {
+            HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref extractModel.PageRange, PageRangeText);
+
+            char[] enumerationSeparator = new char[] { ',' };
+            char[] rangeSeparator = new char[] { '-' };
+            if (!CommonHelper.GetPagesInRange(ref extractModel.PageParm, extractModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
+            { //TODO
+                Trace.WriteLine("输入不对");
+                return; }
+            if (extractModel.ExtractToSingleFile) {
+                for (int i=0; i<extractModel.PageParm.ToArray().Length;i++) {
+                    CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                    extractdoc.ImportPages(currentViewer.Document, (extractModel.PageParm.ToArray()[i]+1).ToString());
+                    Trace.WriteLine(extractModel.PageParm.ToArray()[i].ToString());
+                    extractdoc.WriteToFilePath(savefilepath + ".extract"+i.ToString()+".pdf");
+                    extractdoc.Release();
+                }
+                if (extractModel.DeleteAfterExtract)
+                {
+                    currentViewer.Document.RemovePages(extractModel.PageParm.ToArray());
+                    currentViewer.Document.WriteToLoadedPath();
+                }
+                
+            }
+            else
+            {
+                CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                extractdoc.ImportPages(currentViewer.Document, extractModel.PageRange);
+                extractdoc.WriteToFilePath(savefilepath + ".extract.pdf");
+                if (extractModel.DeleteAfterExtract)
+                {
+                    currentViewer.Document.RemovePages(extractModel.PageParm.ToArray());
+                    currentViewer.Document.WriteToLoadedPath();
+                }
+                extractdoc.Release();
+            }
+            System.Diagnostics.Process.Start("Explorer", "/select," + currentViewer.Document.FilePath);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK));
+        }
+
+        private void extractToSingleFile() {
+            if (ExtractToSingleFileIsCheck == "True")
+            {
+                extractModel.ExtractToSingleFile = true;
+                Trace.WriteLine("ExtractToSingleFileIsCheck" + extractModel.ExtractToSingleFile);
+            }
+            else {
+                extractModel.ExtractToSingleFile = false;
+                Trace.WriteLine("ExtractToSingleFileIsCheck" + extractModel.ExtractToSingleFile);
+            }
+        }
+
+        private void deleteAfterExtract() {
+
+            if (DeleteAfterExtractIsCheck == "True")
+            {
+                extractModel.DeleteAfterExtract = true;
+                Trace.WriteLine("DeleteAfterExtractIsCheck" + extractModel.DeleteAfterExtract);
+            }
+            else
+            {
+                extractModel.DeleteAfterExtract = false;
+                Trace.WriteLine("DeleteAfterExtractIsCheck" + extractModel.DeleteAfterExtract);
+            }
+            
+        }
+
+        public string Title => "";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFViewer viewer = null;
+            string filepath = "";
+            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out viewer);
+            parameters.TryGetValue<string>(ParameterNames.FilePath, out filepath);
+            if (viewer != null&&viewer.Document!=null)
+            {
+                currentViewer=viewer;
+                savefilepath = filepath;
+                PageTurningPreview.document = currentViewer.Document;
+
+            }
+        }
+    }
+}

+ 233 - 34
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageInsertDialogViewModel.cs

@@ -1,34 +1,233 @@
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
-{
-    public class HomePageInsertDialogViewModel : BindableBase,IDialogAware
-    {
-        public HomePageInsertDialogViewModel()
-        {
-
-        }
-
-        public string Title => "";
-
-        public event Action<IDialogResult> RequestClose;
-
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
-
-        public void OnDialogClosed()
-        {
-        }
-
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-        }
-    }
-}
+using ComPDFKit.PDFDocument;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using PDF_Office.Model.HomePageToolsDialogs;
+using System.Diagnostics;
+using System.Globalization;
+using System.Windows;
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
+using System.Windows.Forms;
+using DialogResult = Prism.Services.Dialogs.DialogResult;
+using PDF_Office.CustomControl;
+
+namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
+{
+    public class HomePageInsertDialogViewModel : BindableBase,IDialogAware
+    {
+        private CPDFViewer currentViewer;
+
+        private string saveFilePath { get; set; }
+
+        private HomePageInsertDialogModel insertModel = new HomePageInsertDialogModel();
+
+        public DelegateCommand CancelCommand { get; set; }
+
+        public DelegateCommand InsertCommand { get; set; }
+
+        public DelegateCommand SelectFileCommand { get; set; }
+
+        public DelegateCommand FirstPageCommand { get; set; }
+
+        public DelegateCommand LastPageCommand { get; set; }
+
+        public DelegateCommand CustomPageCommand { get; set; }
+
+        private string selectFilePath = "选择文件";
+        public string SelectFilePath
+        {
+            get { return selectFilePath; }
+            set
+            {
+                SetProperty(ref selectFilePath, value);
+            }
+        }
+
+        private string pageLocation = "0";
+        public string PageLocation
+        {
+            get { return pageLocation; }
+            set
+            {
+                pageLocation = value;
+            }
+        }
+
+        private string pageNumber="1";
+        public string PageNumber
+        {
+            get { return pageNumber; }
+            set
+            {
+                SetProperty(ref pageNumber, value);
+            }
+        }
+
+        private string pageInsertIndex = "1";
+        public string PageInsertIndex
+        {
+            get {
+                    return pageInsertIndex; }
+            set
+            {
+                if (int.Parse(pageInsertIndex) > currentViewer.Document.PageCount)
+                { pageInsertIndex= currentViewer.Document.PageCount.ToString(); }
+                SetProperty(ref pageInsertIndex, value);
+            }
+        }
+
+        private string firstIsCheck = "True";
+        public string FirstIsCheck
+        {
+            get { return firstIsCheck; }
+            set
+            {
+                SetProperty(ref firstIsCheck, value);
+            }
+        }
+
+        private string lastIsCheck = "False";
+        public string LastIsCheck
+        {
+            get { return lastIsCheck; }
+            set
+            {
+                SetProperty(ref lastIsCheck, value);
+            }
+        }
+
+        private string customIsCheck = "False";
+        public string CustomIsCheck
+        {
+            get { return customIsCheck; }
+            set
+            {
+                SetProperty(ref customIsCheck, value);
+            }
+        }
+
+        private string customIsEnabled = "False";
+        public string CustomIsEnabled
+        {
+            get { return customIsEnabled; }
+            set
+            {
+                SetProperty(ref customIsEnabled, value);
+            }
+        }
+
+        public HomePageInsertDialogViewModel()
+        {
+            CancelCommand = new DelegateCommand(cancel);
+            InsertCommand = new DelegateCommand(insert);
+            SelectFileCommand = new DelegateCommand(selectFile);
+            FirstPageCommand = new DelegateCommand(firstPage);
+            LastPageCommand = new DelegateCommand(lastPage);
+            CustomPageCommand = new DelegateCommand(customPage);
+        }
+
+        private void cancel()
+        {
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+
+        private void insert()
+        {
+            
+            CPDFDocument insertdocument = CPDFDocument.InitWithFilePath(insertModel.FilePath);
+            if (insertdocument == null)
+            {
+                Trace.WriteLine("Document==null");
+                //TODO
+                return;
+            }
+            if (insertdocument.IsEncrypted) {
+                Trace.WriteLine("youmima");
+                //TODO
+                return;
+            }
+            if (PageLocation == "1") {
+                insertModel.InsertIndex=insertModel.InsertIndex - 1;
+            }
+            currentViewer.Document.ImportPagesAtIndex(insertdocument, insertModel.InserPageRange(insertdocument), insertModel.InsertIndex);
+            currentViewer.UndoManager.ClearHistory();
+            currentViewer.UndoManager.CanSave = true;
+            currentViewer.ReloadDocument();
+            currentViewer.Document.WriteToLoadedPath();
+            insertdocument.Release();
+            System.Diagnostics.Process.Start("Explorer", "/select," + currentViewer.Document.FilePath);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK));
+        }
+
+        private void selectFile() {
+            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
+            dlg.Multiselect = false;
+            dlg.Filter = "PDF|*.pdf;*.PDF;";
+            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            {
+                insertModel.FilePath= dlg.FileName;
+                SelectFilePath = dlg.FileName;
+            }
+
+        }
+
+        private void firstPage()
+        {
+            insertModel.InsertIndex = 1;
+            CustomIsEnabled = "False";
+            FirstIsCheck = "True";
+            LastIsCheck = "False";
+            CustomIsCheck = "False";
+        }
+
+        private void lastPage()
+        {
+            insertModel.InsertIndex = currentViewer.Document.PageCount;
+            CustomIsEnabled = "False";
+            FirstIsCheck = "False";
+            LastIsCheck = "True";
+            CustomIsCheck = "False";
+        }
+
+        private void customPage()
+        {
+            CustomIsEnabled = "True";
+            FirstIsCheck = "False";
+            LastIsCheck = "False";
+            CustomIsCheck = "True";
+        }
+
+        public string Title => "";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFViewer viewer = null;
+            string filepath = "";
+            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out viewer);
+            parameters.TryGetValue<string>(ParameterNames.FilePath, out filepath);
+            if (viewer != null && viewer.Document != null)
+            {
+                currentViewer = viewer;
+                saveFilePath = filepath;
+                PageNumber=currentViewer.Document.PageCount.ToString();
+                PageTurningPreview.document = currentViewer.Document;
+            }
+        }
+    }
+}

+ 45 - 35
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs

@@ -1,37 +1,47 @@
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
-{
-    public class HomePagePrinterDialogViewModel : BindableBase,IDialogAware
+using ComPDFKit.PDFDocument;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml.Linq;
+
+namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
+{
+    public class HomePagePrinterDialogViewModel : BindableBase,IDialogAware
     {
+        private CPDFDocument document;
+
+        public IDialogService dialogs;
+
+        public HomePagePrinterDialogViewModel(IDialogService dialogService)
+        {
+            dialogs = dialogService;
+        }
+
+        public string Title => "";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+        }
 
-        public IDialogService dialogs;
-
-        public HomePagePrinterDialogViewModel(IDialogService dialogService)
-        {
-            dialogs = dialogService;
-        }
-
-        public string Title => "";
-
-        public event Action<IDialogResult> RequestClose;
-
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
-
-        public void OnDialogClosed()
-        {
-        }
-
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-        }
-    }
-}
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFDocument doc = null;
+            parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
+            if (doc != null)
+            {
+                document = doc;
+            }
+        }
+    }
+}

+ 494 - 33
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePageSplitDialogViewModel.cs

@@ -1,33 +1,494 @@
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
-{
-    public class HomePageSplitDialogViewModel : BindableBase,IDialogAware
-    {
-        public HomePageSplitDialogViewModel()
-        {
-        }
-
-        public string Title =>"";
-
-        public event Action<IDialogResult> RequestClose;
-
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
-
-        public void OnDialogClosed()
-        {
-        }
-
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-        }
-    }
-}
+using ComPDFKit.PDFDocument;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using PDF_Office.Helper;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using PDF_Office.Model.HomePageToolsDialogs;
+using ImTools;
+using PDF_Office.Model.PageEdit;
+using ComPDFKit.PDFPage;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+using System.Windows.Media;
+using PDF_Office.CustomControl;
+
+namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
+{
+    public class HomePageSplitDialogViewModel : BindableBase, IDialogAware
+    {
+        CPDFDocument document;
+
+        private CPDFViewer currentViewer;
+
+        private HomePageSplitDialogModel splitModel = new HomePageSplitDialogModel();
+
+        private string savefilepath { get; set; }
+
+        private string savefilename { get; set; }
+
+        public DelegateCommand CancelCommand { get; set; }
+
+        public DelegateCommand SplitCommand { get; set; }
+
+        public DelegateCommand AveragePagesCommand { get; set; }
+
+        public DelegateCommand AverageFilesCommand { get; set; }
+
+        public DelegateCommand CustomPageRangeCommand { get; set; }
+
+        public DelegateCommand FrontFileNameCommand { get; set; }
+
+        public DelegateCommand FileNameLabelCommand { get; set; }
+
+        public DelegateCommand FileNameDeimiterCommand { get; set; }
+
+        public DelegateCommand FileNameDeimiterChangeCommand { get; set; }
+
+        public DelegateCommand FileNameLabelChangeCommand { get; set; }
+
+       
+
+        private string pageRangeText = "0";
+        public string PageRangeText
+        {
+            get { return pageRangeText; }
+            set
+            {
+                pageRangeText = value;
+            }
+        }
+
+        private string pageRangeSelectIndex = "0";
+        public string PageRangeSelectIndex
+        {
+            get { return pageRangeSelectIndex; }
+            set
+            {
+                pageRangeSelectIndex = value;
+            }
+        }
+
+        private string averagePagesIsCheck = "True";
+        public string AveragePagesIsCheck
+        {
+            get { return averagePagesIsCheck; }
+            set
+            {
+                SetProperty(ref averagePagesIsCheck, value);
+            }
+        }
+
+        private string averageFilesIsCheck = "False";
+        public string AverageFilesIsCheck
+        {
+            get { return averageFilesIsCheck; }
+            set
+            {
+                SetProperty(ref averageFilesIsCheck, value);
+            }
+        }
+
+        private string customPageRangeIsCheck = "False";
+        public string CustomPageRangeIsCheck
+        {
+            get { return customPageRangeIsCheck; }
+            set
+            {
+                SetProperty(ref customPageRangeIsCheck, value);
+            }
+        }
+
+        private string averagePagesIsEnabled = "True";
+        public string AveragePagesIsEnabled
+        {
+            get { return averagePagesIsEnabled; }
+            set
+            {
+                SetProperty(ref averagePagesIsEnabled, value);
+            }
+        }
+
+        private string averageFilesIsEnabled = "False";
+        public string AverageFilesIsEnabled
+        {
+            get { return averageFilesIsEnabled; }
+            set
+            {
+                SetProperty(ref averageFilesIsEnabled, value);
+            }
+        }
+
+        private string customPageRangeIsEnabled = "False";
+        public string CustomPageRangeIsEnabled
+        {
+            get { return customPageRangeIsEnabled; }
+            set
+            {
+                SetProperty(ref customPageRangeIsEnabled, value);
+            }
+        }
+
+        private string averagePagesText = "";
+        public string AveragePagesText
+        {
+            get { return averagePagesText; }
+            set
+            {
+                averagePagesText = value;
+            }
+        }
+
+        private string averageFilesText = "";
+        public string AverageFilesText
+        {
+            get { return averageFilesText; }
+            set
+            {
+                averageFilesText = value;
+            }
+        }
+
+        private string filePathName = "";
+        public string FilePathName
+        {
+            get { return filePathName; }
+            set
+            {
+                SetProperty(ref filePathName, value);
+            }
+        }
+
+        private string fileNameLabelText = "part";
+        public string FileNameLabelText
+        {
+            get { return fileNameLabelText; }
+            set
+            {
+                fileNameLabelText = value;
+            }
+        }
+
+        private string fileNameDeimiterText = "-";
+        public string FileNameDeimiterText
+        {
+            get { return fileNameDeimiterText; }
+            set
+            {
+                fileNameDeimiterText = value;
+            }
+        }
+
+        private string frontFileIsCheck = "True";
+        public string FrontFileIsCheck
+        {
+            get { return frontFileIsCheck; }
+            set
+            {
+                frontFileIsCheck = value;
+            }
+        }
+
+        private string fileNameLabelIsCheck = "True";
+        public string FileNameLabelIsCheck
+        {
+            get { return fileNameLabelIsCheck; }
+            set
+            {
+                fileNameLabelIsCheck = value;
+            }
+        }
+
+        private string fileNameDeimiterIsCheck = "True";
+        public string FileNameDeimiterIsCheck
+        {
+            get { return fileNameDeimiterIsCheck; }
+            set
+            {
+                fileNameDeimiterIsCheck = value;
+            }
+        }
+
+        public HomePageSplitDialogViewModel()
+        {
+            CancelCommand = new DelegateCommand(cancel);
+            SplitCommand = new DelegateCommand(split);
+            AveragePagesCommand = new DelegateCommand(averagePages);
+            AverageFilesCommand = new DelegateCommand(averageFiles);
+            CustomPageRangeCommand = new DelegateCommand(customPageRange);
+            FrontFileNameCommand = new DelegateCommand(frontFileName);
+            FileNameLabelCommand = new DelegateCommand(fileNameLabel);
+            FileNameDeimiterCommand = new DelegateCommand(fileNameDeimiter);
+            FileNameDeimiterChangeCommand = new DelegateCommand(fileNameDeimiter);
+            FileNameLabelChangeCommand= new DelegateCommand(fileNameLabel);
+            
+
+        }
+
+        private void cancel()
+        {
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+
+        private void split()
+        {
+            HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref splitModel.PageRange, PageRangeText);
+
+            if (FileNameDeimiterIsCheck == "True")
+            {
+                splitModel.FileNameDeimiter = FileNameDeimiterText;
+            }
+            else
+            {
+                splitModel.FileNameDeimiter = "";
+            }
+
+            if (FileNameDeimiterIsCheck == "True")
+            {
+                splitModel.FileNameDeimiter = FileNameDeimiterText;
+            }
+            else
+            {
+                splitModel.FileNameDeimiter = "";
+            }
+            if (FileNameLabelIsCheck == "True")
+            {
+                splitModel.FrontFileName = true;
+            }
+            else
+            {
+                splitModel.FrontFileName = false;
+            }
+
+            char[] enumerationSeparator = new char[] { ',' };
+            char[] rangeSeparator = new char[] { '-' };
+            if (!CommonHelper.GetPagesInRange(ref splitModel.PageParm, splitModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
+            { //TODO
+                Trace.WriteLine("输入不对");
+                return;
+            }
+            Trace.WriteLine("mmmmmmmmmmmmmmmmmmmmm---mmm"+splitModel.PageRange+"pppppp");
+            if (splitModel.Mode == HomePageSplitDialogModel.SplitMode.AveragePages)
+            {
+                if (AveragePagesText != "") { 
+                splitModel.GetModeCount = int.Parse(AveragePagesText);
+                }
+                int averagepagesremainder = 0;
+                var averagepagesdocs = HomePageEditHelper.AverageSplitPages(currentViewer.Document.PageCount, splitModel.GetModeCount, ref averagepagesremainder);
+                int averagepagesdoc;
+                for (averagepagesdoc = 1; averagepagesdoc < averagepagesdocs; averagepagesdoc++) {
+                    CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                    extractdoc.ImportPages(currentViewer.Document, (1 + splitModel.GetModeCount * (averagepagesdoc - 1)).ToString() + "-" + (splitModel.GetModeCount * averagepagesdoc).ToString());
+                    if (splitModel.FrontFileName)
+                    {
+                        extractdoc.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + averagepagesdoc.ToString() + ".pdf");
+                    }
+                    else {
+                        extractdoc.WriteToFilePath(currentViewer.Document.FilePath + splitModel.FileNameLabel + splitModel.FileNameDeimiter + currentViewer.Document.FileName + averagepagesdoc.ToString() + ".pdf");
+
+                    }
+                    extractdoc.Release();
+                }
+                if (averagepagesdoc == averagepagesdocs) {
+                    CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                    extractdoc.ImportPages(currentViewer.Document, (1 + splitModel.GetModeCount * (averagepagesdoc - 1)).ToString() + "-" + currentViewer.Document.PageCount.ToString());
+                    if (splitModel.FrontFileName)
+                    {
+                        extractdoc.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + averagepagesdoc.ToString() + ".pdf");
+                    }
+                    else
+                    {
+                        extractdoc.WriteToFilePath(currentViewer.Document.FilePath + splitModel.FileNameLabel + splitModel.FileNameDeimiter + currentViewer.Document.FileName + averagepagesdoc.ToString() + ".pdf");
+
+                    }
+                }
+            }
+            if (splitModel.Mode == HomePageSplitDialogModel.SplitMode.AverageFiles)
+            {
+                if (AverageFilesText != "")
+                {
+                    splitModel.GetModeCount = int.Parse(AverageFilesText);
+                }
+                int averagefilesremainder = 0;
+                var averagefilespages = HomePageEditHelper.AverageSplitDocs(currentViewer.Document.PageCount, splitModel.GetModeCount, ref averagefilesremainder);
+                int averagefilesdoc;
+                if (splitModel.GetModeCount > currentViewer.Document.PageCount)
+                { splitModel.GetModeCount = 10; }
+                for (averagefilesdoc = 1; averagefilesdoc <= splitModel.GetModeCount; averagefilesdoc++) {
+                    CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                    if (averagefilesremainder > 0) {
+                        extractdoc.ImportPages(currentViewer.Document, (1 + (averagefilespages + 1) * (averagefilesdoc - 1)).ToString() + "-" + ((averagefilespages + 1) * averagefilesdoc).ToString());
+                        Trace.WriteLine("gggggggggggggg" + (1 + (averagefilespages + 1) * (averagefilesdoc - 1)).ToString() + "-" + ((averagefilespages + 1) * averagefilesdoc).ToString());
+                        extractdoc.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + averagefilesdoc.ToString() + ".pdf");
+                        averagefilesremainder--;
+                    }
+                    else {
+                        extractdoc.ImportPages(currentViewer.Document, (averagefilespages * averagefilesremainder + averagefilesremainder + 1 + averagefilespages * (averagefilesdoc - 1)).ToString() + "-" + (averagefilespages * averagefilesremainder + averagefilesremainder + (averagefilespages * averagefilesdoc)).ToString());
+                        Trace.WriteLine("gggggggggggggg" + (averagefilespages * averagefilesremainder + averagefilesremainder + 1 + averagefilespages * (averagefilesdoc - 1)).ToString() + "-" + (averagefilespages * averagefilesremainder + averagefilesremainder + (averagefilespages * averagefilesdoc)).ToString());
+                        extractdoc.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + averagefilesdoc.ToString() + ".pdf");
+                    }
+                    
+                    extractdoc.Release();
+                }
+
+            }
+            if (splitModel.Mode == HomePageSplitDialogModel.SplitMode.CustomPageRange)
+            {
+
+                CPDFDocument extractdoc = CPDFDocument.CreateDocument();
+                extractdoc.ImportPages(currentViewer.Document, splitModel.PageRange);
+                extractdoc.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + "1" + ".pdf");
+                currentViewer.Document.RemovePages(splitModel.PageParm.ToArray());
+                currentViewer.Document.WriteToFilePath(savefilepath + splitModel.FileNameDeimiter + splitModel.FileNameLabel + "2" + ".pdf");
+
+            }
+            System.Diagnostics.Process.Start("Explorer", "/select," + currentViewer.Document.FilePath);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK));
+        }
+
+        private void averagePages() {
+            CustomPageRangeIsCheck = "False";
+            AverageFilesIsCheck = "False";
+            AveragePagesIsCheck = "True";
+
+            CustomPageRangeIsEnabled = "False";
+            AverageFilesIsEnabled = "False";
+            AveragePagesIsEnabled = "True";
+            splitModel.Mode = HomePageSplitDialogModel.SplitMode.AveragePages;
+
+        }
+
+        private void averageFiles() {
+            CustomPageRangeIsCheck = "False";
+            AverageFilesIsCheck = "True";
+            AveragePagesIsCheck = "False";
+
+            CustomPageRangeIsEnabled = "False";
+            AverageFilesIsEnabled = "True";
+            AveragePagesIsEnabled = "False";
+            splitModel.Mode = HomePageSplitDialogModel.SplitMode.AverageFiles;
+
+        }
+
+        private void customPageRange() {
+            CustomPageRangeIsCheck = "True";
+            AverageFilesIsCheck = "False";
+            AveragePagesIsCheck = "False";
+
+            CustomPageRangeIsEnabled = "True";
+            AverageFilesIsEnabled = "False";
+            AveragePagesIsEnabled = "False";
+            splitModel.Mode = HomePageSplitDialogModel.SplitMode.CustomPageRange;
+
+        }
+
+        private void frontFileName() {
+            if (FrontFileIsCheck == "True")
+            {
+                FilePathName = savefilename + FileNameDeimiterText + FileNameLabelText;
+                splitModel.FrontFileName = true;
+            }
+            else { 
+                splitModel.FrontFileName=false;
+                FilePathName = FileNameLabelText + FileNameDeimiterText + savefilename;
+            }
+            
+        }
+
+        private void fileNameLabel() {
+            if (FileNameLabelIsCheck == "True")
+            {
+                if (FrontFileIsCheck == "True")
+                {
+                    FilePathName = savefilename + FileNameDeimiterText + FileNameLabelText;
+                    splitModel.FrontFileName = true;
+                }
+                else
+                {
+                    splitModel.FrontFileName = false;
+                    FilePathName = FileNameLabelText + FileNameDeimiterText + savefilename;
+                }
+            }
+            else {
+                
+                if (FrontFileIsCheck == "True")
+                {
+                    FilePathName = savefilename + FileNameDeimiterText + FileNameLabelText;
+                    splitModel.FrontFileName = true;
+                }
+                else
+                {
+                    splitModel.FrontFileName = false;
+                    FilePathName = FileNameLabelText + FileNameDeimiterText + savefilename;
+                }
+            }
+        
+        }
+
+        private void fileNameDeimiter() {
+            if (FileNameDeimiterIsCheck == "True")
+            {
+                if (FrontFileIsCheck == "True")
+                {
+                    FilePathName = savefilename + FileNameDeimiterText + FileNameLabelText;
+                    
+                }
+                else
+                {
+                    
+                    FilePathName = FileNameLabelText + FileNameDeimiterText + savefilename;
+                }
+            }
+            else
+            {
+                
+                if (FrontFileIsCheck == "True")
+                {
+                    FilePathName = savefilename + FileNameDeimiterText + FileNameLabelText;
+                    
+                }
+                else
+                {
+                    
+                    FilePathName = FileNameLabelText + FileNameDeimiterText + savefilename;
+                }
+            }
+
+        }
+
+       
+        public string Title =>"";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFViewer viewer = null;
+            string filepath = "";
+            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out viewer);
+            parameters.TryGetValue<string>(ParameterNames.FilePath, out filepath);
+            if (viewer != null && viewer.Document != null)
+            {
+                currentViewer = viewer;
+                savefilepath = filepath;
+                savefilename = currentViewer.Document.FileName;
+                
+            }
+        }
+    }
+}

+ 54 - 25
PDF Office/ViewModels/HomePanel/HomeGuidContentViewModel.cs

@@ -1,4 +1,6 @@
-using ComPDFKitViewer.PdfViewer;
+using ComPDFKit.PDFDocument;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.CustomControl;
 using PDF_Office.Model;
 using PDF_Office.Model.PDFTool;
 using PDF_Office.Views.HomePanel.PDFTools;
@@ -10,6 +12,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml.Linq;
 
 namespace PDF_Office.ViewModels.HomePanel
 {
@@ -25,37 +29,62 @@ namespace PDF_Office.ViewModels.HomePanel
 
         public void QuickTools_Click(ToolItem toolItem)
         {
-            switch (toolItem.Tag)
+           
+            
+            /*
+             *设置这个对话框的起始保存路径
+             */
+            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
+            dlg.Multiselect = false;
+            dlg.Filter = "PDF|*.pdf;*.PDF;";
+            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
-                case PDFToolType.Split:
-                    Split_Click();
-                    DialogParameters splitvalue = new DialogParameters();
-                    dialogs.ShowDialog(DialogNames.HomePageSplitDialog, splitvalue, e => { });
-                    break;
+                CPDFViewer viewer=new CPDFViewer();
+                 viewer.InitDocument(dlg.FileName);
+                switch (toolItem.Tag)
+                {
+                    case PDFToolType.Split:
+                        Split_Click();
+                        DialogParameters splitvalue = new DialogParameters();
+                        splitvalue.Add(ParameterNames.PDFViewer, viewer);
+                        splitvalue.Add(ParameterNames.FilePath, dlg.FileName);
+                        PageTurningPreview.document = viewer.Document;
+                        dialogs.ShowDialog(DialogNames.HomePageSplitDialog, splitvalue, e => { });
+                        break;
 
-                case PDFToolType.Extract:
-                    DialogParameters extractvalue = new DialogParameters();
-                    dialogs.ShowDialog(DialogNames.HomePageExtractDialog, extractvalue, e => { });
-                    break;
+                    case PDFToolType.Extract:
+                        DialogParameters extractvalue = new DialogParameters();
+                        extractvalue.Add(ParameterNames.PDFViewer, viewer); 
+                        extractvalue.Add(ParameterNames.FilePath, dlg.FileName);
+                        PageTurningPreview.document = viewer.Document;
+                        dialogs.ShowDialog(DialogNames.HomePageExtractDialog, extractvalue, e => { });
+                        break;
 
-                case PDFToolType.Insert:
-                    DialogParameters insertvalue = new DialogParameters();
-                    dialogs.ShowDialog(DialogNames.HomePageInsertDialog, insertvalue, e => { });
-                    break;
+                    case PDFToolType.Insert:
+                        DialogParameters insertvalue = new DialogParameters();
+                        insertvalue.Add(ParameterNames.PDFViewer, viewer); 
+                        insertvalue.Add(ParameterNames.FilePath, dlg.FileName);
+                        PageTurningPreview.document = viewer.Document;
+                        dialogs.ShowDialog(DialogNames.HomePageInsertDialog, insertvalue, e => { });
+                        break;
 
-                case PDFToolType.Compress:
-                    break;
+                    case PDFToolType.Compress:
+                        break;
 
-                case PDFToolType.Merge:
-                    break;
+                    case PDFToolType.Merge:
+                        break;
 
-                case PDFToolType.Print:
-                    DialogParameters printvalue = new DialogParameters();
-                    dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printvalue, e => { });
-                    break;
+                    case PDFToolType.Print:
+                        DialogParameters printvalue = new DialogParameters();
+                        printvalue.Add(ParameterNames.PDFViewer, viewer); ;
+                        printvalue.Add(ParameterNames.FilePath, dlg.FileName);
+                        dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printvalue, e => { });
+                        break;
+
+                    case PDFToolType.Security:
+                        break;
+                }
 
-                case PDFToolType.Security:
-                    break;
             }
         }
 

+ 22 - 21
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageExtractDialog.xaml

@@ -1,5 +1,5 @@
 <UserControl x:Class="PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageExtractDialog"
-           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -23,23 +23,8 @@
                     <ColumnDefinition Width="1*"/>
                 </Grid.ColumnDefinitions>
 				<Grid Grid.Column="0">
-					<Border  Margin="10,40,10,40" Width="176" Height="218" Background="LightGray" >
-						<Viewbox >
-							<Image Name="Image"></Image>
-						</Viewbox>
-					</Border>
-					<StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">
-						<Button Name="PrePage"   Width="20" Height="20" HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-							<TextBlock Text="&lt;" VerticalAlignment="Center"></TextBlock>
-						</Button>
-						<TextBox x:Name="CurrentPage" Width="30" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="1"   ></TextBox>
-						<TextBlock  Text="of"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0"></TextBlock>
-						<TextBlock x:Name="PageIndex"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"></TextBlock>
-						<Button Name="NextPage" Width="20" Height="20" HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-							<TextBlock Text=">" VerticalAlignment="Center"></TextBlock>
-						</Button>
-					</StackPanel>
-				</Grid>
+                    <cus:PageTurningPreview ></cus:PageTurningPreview>
+                </Grid>
                 <Grid Grid.Column="1">
                     <Grid.RowDefinitions>
                         <RowDefinition Height="5*"/>
@@ -48,16 +33,16 @@
                     <Grid Grid.Row="0">
                         <StackPanel Orientation="Vertical" Margin="0,40,0,0">
                             <TextBlock Text="页面范围" FontWeight="ExtraBlack" Width="56" Height="22" HorizontalAlignment="Left"/>
-                            <cus:WritableComboBox Width="208" Height="32" HorizontalAlignment="Left" Margin="0,20,0,0"></cus:WritableComboBox>
+                            <cus:WritableComboBox Width="208" Height="32" HorizontalAlignment="Left" Margin="0,20,0,0" Text="{Binding PageRangeText,Mode=TwoWay}" SelectedIndex="{Binding PageRangeSelectIndex,Mode=TwoWay}"></cus:WritableComboBox>
                         </StackPanel>
                     </Grid>
                     <Grid Grid.Row="1">
                         <StackPanel Orientation="Vertical">
                             <TextBlock Text="页面范围" FontWeight="ExtraBlack" Width="56" Height="22" HorizontalAlignment="Left"/>
-                            <CheckBox Margin="0,20,0,0">
+                            <CheckBox Margin="0,20,0,0" Command="{Binding ExtractToSingleFileCommand}" IsChecked="{Binding ExtractToSingleFileIsCheck}">
                                 <TextBlock Text="每个页面作为单独页面"></TextBlock>
                             </CheckBox>
-                            <CheckBox Margin="0,20,0,0">
+                            <CheckBox Margin="0,20,0,0" Command="{Binding DeleteAfterExtractCommand}" IsChecked="{Binding DeleteAfterExtractIsCheck}">
                                 <TextBlock Text="提取后删除页面"></TextBlock>
                             </CheckBox>
                         </StackPanel>
@@ -65,5 +50,21 @@
                 </Grid>
             </Grid>
         </Border>
+        <Grid Grid.Row="2">
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="0,0,124,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding ExtractCommand}"
+                    Content="提取" />
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="16,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding CancelCommand}"
+                    Content="取消" />
+        </Grid>
     </Grid>
 </UserControl>

+ 30 - 25
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageInsertDialog.xaml

@@ -1,5 +1,6 @@
 <UserControl x:Class="PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageInsertDialog"
-     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:cus="clr-namespace:PDF_Office.CustomControl"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -22,22 +23,7 @@
                     <ColumnDefinition Width="4*"/>
                 </Grid.ColumnDefinitions>
                 <Grid Grid.Column="0">
-                    <Border  Margin="10,40,10,40" Background="LightGray" Width="200">
-                        <Viewbox>
-                            <Image Name="Image"></Image>
-                        </Viewbox>
-                    </Border>
-                    <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">
-                        <Button Name="PrePage" Width="20" Height="20" HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-                            <TextBlock Text="&lt;" VerticalAlignment="Center"></TextBlock>
-                        </Button>
-                        <TextBox x:Name="CurrentPage" Width="30" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="1" InputMethod.IsInputMethodEnabled="False" ></TextBox>
-                        <TextBlock  Text="of"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0"></TextBlock>
-                        <TextBlock x:Name="PageIndex"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"></TextBlock>
-                        <Button Name="NextPage"  Width="20" Height="20" HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-                            <TextBlock Text=">" VerticalAlignment="Center"></TextBlock>
-                        </Button>
-                    </StackPanel>
+                    <cus:PageTurningPreview></cus:PageTurningPreview>
                 </Grid>
                 <Grid Grid.Column="1" Margin="7,27,13,40">
                     <Grid.RowDefinitions>
@@ -48,34 +34,53 @@
                     <StackPanel Grid.Row="0" Orientation="Vertical">
                         <TextBlock Text="插入文件"></TextBlock>
                         <StackPanel Orientation="Horizontal">
-                            <TextBox Height="32" Width="198" Margin="0,0,4,0" VerticalContentAlignment="Center" Text="选择文件" Padding="16,0,6,0"></TextBox>
-                            <Button Height="32" Width="56" Content="选择"></Button>
+                            <TextBox Height="32" Width="198" Margin="0,0,4,0" VerticalContentAlignment="Center" Text="{Binding SelectFilePath}" Padding="16,0,6,0"></TextBox>
+                            <Button Height="32" Width="56" Content="选择" Command="{Binding SelectFileCommand}"></Button>
                         </StackPanel>
                     </StackPanel>
                     <Grid Grid.Row="1"></Grid>
                     <StackPanel Grid.Row="1" Orientation="Vertical">
                         <TextBlock Text="插入位置" Height="22" Width="56" HorizontalAlignment="Left"></TextBlock>
                         <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
-                            <RadioButton  Margin="0,0,64,0">
+                            <RadioButton x:Name="FirstIsCheckRadioButton"  Margin="0,0,64,0" IsChecked="{Binding FirstIsCheck}" Command="{Binding FirstPageCommand}">
                                 <TextBlock Text="第一页" Margin="12,0,0,0"></TextBlock>
                             </RadioButton>
-                            <RadioButton>
+                            <RadioButton x:Name="LastIsCheckRadioButton" IsChecked="{Binding LastIsCheck}" Command="{Binding LastPageCommand}">
                                 <TextBlock Text="最后一页" Margin="12,0,0,0"></TextBlock>
                             </RadioButton>
                         </StackPanel>
                     </StackPanel>
                     <StackPanel Grid.Row="2" Orientation="Vertical">
                         <StackPanel Orientation="Horizontal">
-                            <RadioButton VerticalAlignment="Center"></RadioButton>
+                            <RadioButton x:Name="CustomIsCheckRadioButton" VerticalAlignment="Center" IsChecked="{Binding CustomIsCheck}" Command="{Binding CustomPageCommand}"></RadioButton>
                             <TextBlock Text="页面" VerticalAlignment="Center"  Margin="12,0,0,0"></TextBlock>
-                            <TextBox Height="32" Width="100"></TextBox>
+                            <TextBox Height="32" Width="100" Text="{Binding PageInsertIndex}" IsEnabled="{Binding CustomIsEnabled}"></TextBox>
                             <TextBlock Text="/" VerticalAlignment="Center"></TextBlock>
-                            <TextBlock Text="page" VerticalAlignment="Center"></TextBlock>
+                            <TextBlock Text="{Binding PageNumber}" VerticalAlignment="Center"></TextBlock>
                         </StackPanel>
-                        <ComboBox Margin="28,7,13,0"></ComboBox>
+                        <ComboBox Margin="28,7,13,0" SelectedIndex="{Binding PageLocation}">
+                            <ComboBoxItem Content="之后"></ComboBoxItem>
+                            <ComboBoxItem Content="之前"></ComboBoxItem>
+                        </ComboBox>
                     </StackPanel>
                 </Grid>
             </Grid>
         </Border>
+        <Grid Grid.Row="2">
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="16,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding CancelCommand}"
+                    Content="取消" />
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="124,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding InsertCommand}"
+                    Content="插入" />
+        </Grid>
     </Grid>
 </UserControl>

+ 30 - 29
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageSplitDialog.xaml

@@ -15,7 +15,7 @@
             <RowDefinition Height="*"></RowDefinition>
             <RowDefinition Height="64"></RowDefinition>
         </Grid.RowDefinitions>
-        <TextBlock Grid.Row="0" Text="插入" FontSize="20" FontWeight="ExtraBlack" VerticalAlignment="Center" HorizontalAlignment="Left"  Margin="20,0,0,0" Height="28" Width="120"/>
+        <TextBlock Grid.Row="0" Text="拆分" FontSize="20" FontWeight="ExtraBlack" VerticalAlignment="Center" HorizontalAlignment="Left"  Margin="20,0,0,0" Height="28" Width="120"/>
         <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1,0,1" VerticalAlignment="Center" Height="409">
             <Grid >
                 <Grid.ColumnDefinitions>
@@ -23,22 +23,7 @@
                     <ColumnDefinition Width="4*"/>
                 </Grid.ColumnDefinitions>
                 <Grid Grid.Column="0" VerticalAlignment="Top">
-                    <Border  Margin="10,40,10,40" Background="LightGray"  Height="218" Width="176">
-                        <Viewbox>
-                            <Image Name="Image"></Image>
-                        </Viewbox>
-                    </Border>
-                    <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">
-                        <Button Name="PrePage" Width="20" Height="20" HorizontalAlignment="Left" FontSize="16" Background="WhiteSmoke" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-                            <TextBlock Text="&lt;" VerticalAlignment="Center"></TextBlock>
-                        </Button>
-                        <TextBox x:Name="CurrentPage" Width="30" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,5,0" Text="1" InputMethod.IsInputMethodEnabled="False" ></TextBox>
-                        <TextBlock  Text="of"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0"></TextBlock>
-                        <TextBlock x:Name="PageIndex"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"></TextBlock>
-                        <Button Name="NextPage" Width="20" Height="20" HorizontalAlignment="Left" FontSize="16"  Background="WhiteSmoke"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
-                            <TextBlock Text=">" VerticalAlignment="Center"></TextBlock>
-                        </Button>
-                    </StackPanel>
+                    <cus:PageTurningPreview ></cus:PageTurningPreview>
                 </Grid>
                 <Grid Grid.Column="1" Margin="7,40,10,40">
                     <Grid.RowDefinitions>
@@ -49,46 +34,62 @@
                         <StackPanel Orientation="Vertical">
                             <TextBlock Text="拆分方式" Height="22" Width="56" HorizontalAlignment="Left" Margin="0,0,0,17"></TextBlock>
                             <StackPanel Orientation="Horizontal" Margin="0,0,0,8">
-                                <RadioButton VerticalAlignment="Center"></RadioButton>
+                                <RadioButton VerticalAlignment="Center" IsChecked="{Binding AveragePagesIsCheck}" Command="{Binding AveragePagesCommand}"></RadioButton>
                                 <TextBlock Text="平均每"  VerticalAlignment="Center"></TextBlock>
-                                <cus:NumericUpDown Height="32" Width="110"></cus:NumericUpDown>
+                                <cus:NumericUpDown Height="32" Width="110" Text="{Binding AveragePagesText,Mode=TwoWay}" IsEnabled="{Binding AveragePagesIsEnabled}"></cus:NumericUpDown>
                                 <TextBlock Text="页拆分为一个文件"  VerticalAlignment="Center"></TextBlock>
                             </StackPanel>
                             <StackPanel Orientation="Horizontal" Margin="0,0,0,8">
-                                <RadioButton VerticalAlignment="Center"></RadioButton>
+                                <RadioButton VerticalAlignment="Center" IsChecked="{Binding AverageFilesIsCheck}"  Command="{Binding AverageFilesCommand}"></RadioButton>
                                 <TextBlock Text="平均拆分为"  VerticalAlignment="Center"></TextBlock>
-                                <cus:NumericUpDown Height="32" Width="110"></cus:NumericUpDown>
+                                <cus:NumericUpDown Height="32" Width="110" Text="{Binding AverageFilesText,Mode=TwoWay}" IsEnabled="{Binding AverageFilesIsEnabled}"></cus:NumericUpDown>
                                 <TextBlock Text="个PDF文件"></TextBlock>
                             </StackPanel>
                             <StackPanel Orientation="Horizontal">
-                                <RadioButton VerticalAlignment="Center"></RadioButton>
+                                <RadioButton VerticalAlignment="Center" IsChecked="{Binding CustomPageRangeIsCheck}" Command="{Binding CustomPageRangeCommand}"></RadioButton>
                                 <TextBlock Text="按特定页面拆分" VerticalAlignment="Center"></TextBlock>
-                                <cus:WritableComboBox  Height="32" Width="183"></cus:WritableComboBox>
+                                <cus:WritableComboBox  Height="32" Width="183" Text="{Binding PageRangeText,Mode=TwoWay}" IsEnabled="{Binding CustomPageRangeIsEnabled}" SelectedIndex="{Binding PageRangeSelectIndex,Mode=TwoWay}"></cus:WritableComboBox>
                             </StackPanel>
                         </StackPanel>
                     </Grid>
                     <Grid Grid.Row="1">
                         <StackPanel Orientation="Vertical">
                             <TextBlock Text="文档命名" Height="22" Width="56" HorizontalAlignment="Left"></TextBlock>
-                            <TextBox Height="32" Width="346" Margin="0,0,0,6"></TextBox>
+                            <TextBox Height="32" Width="303" Margin="0,0,0,6" Text="{Binding FilePathName}"></TextBox>
                             <StackPanel Orientation="Horizontal" Margin="0,0,0,13">
-                                <CheckBox Margin="0,0,11,0"></CheckBox>
+                                <CheckBox Margin="0,0,11,0" Command="{Binding FrontFileNameCommand}" IsChecked="{Binding FrontFileIsCheck}"></CheckBox>
                                 <TextBlock Text="将原始文档名前置"></TextBlock>
                             </StackPanel>
                             <StackPanel Orientation="Horizontal" Margin="0,0,0,8">
-                                <CheckBox VerticalAlignment="Center" Margin="0,0,11,0"></CheckBox>
+                                <CheckBox VerticalAlignment="Center" Margin="0,0,11,0" Command="{Binding FileNameLabelCommand}" IsChecked="{Binding FileNameLabelIsCheck}"></CheckBox>
                                 <TextBlock Text="标签" VerticalAlignment="Center" Margin="0,0,30,0"></TextBlock>
-                                <TextBox Height="32" Width="110"></TextBox>
+                                <TextBox x:Name="FileNameLabelTextBox" Height="32" Width="110" Text="{Binding FileNameLabelText}" TextChanged="TextBox_TextChanged"></TextBox>
                             </StackPanel>
                             <StackPanel Orientation="Horizontal">
-                                <CheckBox VerticalAlignment="Center" Margin="0,0,11,0"></CheckBox>
+                                <CheckBox VerticalAlignment="Center" Margin="0,0,11,0"  Command="{Binding FileNameDeimiterCommand}" IsChecked="{Binding FileNameDeimiterIsCheck}"></CheckBox>
                                 <TextBlock Text="分隔符" VerticalAlignment="Center" Margin="0,0,18,0"></TextBlock>
-                                <TextBox  Height="32" Width="110" ></TextBox>
+                                <TextBox x:Name="FileNameDeimiterTextBox"  Height="32" Width="110" Text="{Binding FileNameDeimiterText}" TextChanged="TextBox_TextChanged"></TextBox>
                             </StackPanel>
                         </StackPanel>
                     </Grid>
                 </Grid>
             </Grid>
         </Border>
+        <Grid Grid.Row="2">
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="16,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding CancelCommand}"
+                    Content="取消" />
+            <Button
+                    Width="98"
+                    Height="32"
+                    Margin="124,0"
+                    HorizontalAlignment="Right"
+                    Command="{Binding SplitCommand}"
+                    Content="拆分" />
+        </Grid>
     </Grid>
 </UserControl>

+ 29 - 2
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePageSplitDialog.xaml.cs

@@ -1,4 +1,8 @@
-using System;
+using PDF_Office.CustomControl;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
+using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs;
+using PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -23,6 +27,29 @@ namespace PDF_Office.Views.Dialog.HomePageToolsDialogs
         public HomePageSplitDialog()
         {
             InitializeComponent();
-        }
+        }
+
+        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            TextBox textBox = sender as TextBox;
+            switch (textBox.Name.ToString())
+            {
+                case "FileNameLabelTextBox":
+                    {
+                        ((HomePageSplitDialogViewModel)this.DataContext).FileNameLabelText = FileNameLabelTextBox.Text;
+                        ((HomePageSplitDialogViewModel)this.DataContext).FileNameLabelChangeCommand.Execute();
+                    }
+                    break;
+                case "FileNameDeimiterTextBox":
+                    {
+                        ((HomePageSplitDialogViewModel)this.DataContext).FileNameDeimiterText = FileNameDeimiterTextBox.Text;
+                        ((HomePageSplitDialogViewModel)this.DataContext).FileNameDeimiterChangeCommand.Execute();
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
+
     }
 }

+ 1 - 1
PDF Office/Views/Dialog/PageEditDialogs/InsertDialog.xaml

@@ -63,7 +63,7 @@
                 </StackPanel>
             </Grid>
         </cus:DialogContent.Content>
-        <cus:DialogContent.BottmBar>
+        <cus:DialogContent.BottmBar >
             <Grid>
                 <Button
                     Width="98"