|
@@ -319,9 +319,6 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
}
|
|
|
|
|
|
ReloadAfterOption(true, true, Tuple.Create(insertIndex-1, insertIndex + pageCount));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
|
}
|
|
@@ -331,7 +328,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// </summary>
|
|
|
private void SplitCommandEvent()
|
|
|
{
|
|
|
-
|
|
|
+ dialogs.ShowDialog(DialogNames.SplitDialog, null, null);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -339,7 +336,13 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// </summary>
|
|
|
private void ExtractCommandEvent()
|
|
|
{
|
|
|
-
|
|
|
+ dialogs.ShowDialog(DialogNames.ExtractDialog,null,e=> {
|
|
|
+ if(e.Result==ButtonResult.OK&&e.Parameters!=null)
|
|
|
+ {
|
|
|
+ var model = e.Parameters.GetValue<ExtractModel>(ParameterNames.DataModel);
|
|
|
+ DoExtractPages(model.IsEveryPageToFile,model.IsDeleteAfterExtract);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -417,6 +420,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
else
|
|
|
{
|
|
|
//插入自定义页面
|
|
|
+ dialogs.ShowDialog(DialogNames.InsertDialog, null, null);
|
|
|
}
|
|
|
IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
@@ -424,10 +428,13 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// <summary>
|
|
|
/// 删除选中页面
|
|
|
/// </summary>
|
|
|
- private void DeleteCommandEvent()
|
|
|
+ private async void DeleteCommandEvent()
|
|
|
{
|
|
|
+ IsLoading = Visibility.Visible;
|
|
|
+ await Task.Delay(3);
|
|
|
DoRemoveSelectedPages();
|
|
|
- ReloadAfterOption(true, true, null);
|
|
|
+ ReloadAfterOption(true, true, Tuple.Create(0,PDFViewer.Document.PageCount));
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -716,10 +723,8 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// 删除选中项的方法 不带Reload操作
|
|
|
/// 方便其他逻辑中调用
|
|
|
/// </summary>
|
|
|
- private async void DoRemoveSelectedPages(List<int> pageList = null)
|
|
|
+ private void DoRemoveSelectedPages(List<int> pageList = null)
|
|
|
{
|
|
|
- IsLoading = Visibility.Visible;
|
|
|
- await Task.Delay(3);
|
|
|
List<int> indexList = new List<int>();
|
|
|
if (pageList == null || pageList.Count < 0)
|
|
|
{
|
|
@@ -738,7 +743,6 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
|
|
|
if(indexList.Count>0&& indexList.Count==PDFViewer.Document.PageCount)
|
|
|
{
|
|
|
- IsLoading = Visibility.Collapsed;
|
|
|
AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
alertsMessage.ShowDialog("","不能删除所有页面","OK");
|
|
|
return;
|
|
@@ -748,7 +752,6 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
if (!result)
|
|
|
{
|
|
|
ShowTip = Visibility.Visible;
|
|
|
- IsLoading = Visibility.Collapsed;
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -757,6 +760,95 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
|
PageEditItems.RemoveAt(indexList[i]);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 提取选中页面的方法
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="isEveryPageToFile">是否每页生成一个文件</param>
|
|
|
+ /// <param name="isDeleteAfterExtract">是否提取后删除页面</param>
|
|
|
+ private async void DoExtractPages(bool isEveryPageToFile,bool isDeleteAfterExtract)
|
|
|
+ {
|
|
|
+ System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
+ if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dialog.SelectedPath))
|
|
|
+ {
|
|
|
+ AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
+ alertsMessage.ShowDialog("","","OK");//补充提示文案
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return;
|
|
|
+
|
|
|
+ string selectedfile = "";
|
|
|
+ IsLoading = Visibility.Visible;
|
|
|
+ await Task.Delay(3);
|
|
|
+ List<int> pagenums = new List<int>();
|
|
|
+ for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ {
|
|
|
+ if(PageEditItems[i].Selected)
|
|
|
+ {
|
|
|
+ pagenums.Add(PageEditItems[i].PageNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEveryPageToFile)
|
|
|
+ {
|
|
|
+ //每页生成的单独的文件
|
|
|
+ for (int i = 0; i < pagenums.Count; i++)
|
|
|
+ {
|
|
|
+ string filename = PDFViewer.Document.FileName + " " + pagenums[i] + ".pdf";
|
|
|
+ string path = System.IO.Path.Combine(dialog.SelectedPath, filename);
|
|
|
+ path = CommonHelper.CreateFilePath(path);
|
|
|
+ selectedfile = path;
|
|
|
+ CPDFDocument savedoc = CPDFDocument.CreateDocument();
|
|
|
+ bool result = savedoc.ImportPages(PDFViewer.Document, pagenums[i].ToString());
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ savedoc.Release();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ result = savedoc.WriteToFilePath(path);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ savedoc.Release();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ savedoc.Release();//释放内存
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else//全部生成一个文件
|
|
|
+ {
|
|
|
+ string filename = PDFViewer.Document.FileName + " " + CommonHelper.GetPageParmFromList(pagenums) + ".pdf";
|
|
|
+ string path = System.IO.Path.Combine(dialog.SelectedPath, filename);
|
|
|
+ path = CommonHelper.CreateFilePath(path);
|
|
|
+ selectedfile = path;
|
|
|
+ CPDFDocument savedoc = CPDFDocument.CreateDocument();
|
|
|
+ string range = String.Join(",", pagenums);
|
|
|
+ bool result = savedoc.ImportPages(PDFViewer.Document, range);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ ShowTip = Visibility.Visible;
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ result = savedoc.WriteToFilePath(path);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ ShowTip = Visibility.Visible;
|
|
|
+ }
|
|
|
+ savedoc.Release();//释放内存
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isDeleteAfterExtract)
|
|
|
+ {
|
|
|
+ DoRemoveSelectedPages();
|
|
|
+ ReloadAfterOption(true,true,Tuple.Create(0,PDFViewer.Document.PageCount));
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonHelper.ShowFileBrowser(selectedfile);
|
|
|
IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
|
|