|
@@ -22,6 +22,8 @@ using Prism.Events;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using System.Windows.Input;
|
|
|
using PDF_Office.Helper;
|
|
|
+using Microsoft.Win32;
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
@@ -49,7 +51,12 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
public ObservableCollection<string> PageRangeItems { get; set; }
|
|
|
|
|
|
#region 属性
|
|
|
- private Visibility showTip;
|
|
|
+ /// <summary>
|
|
|
+ /// 是否是第一次加载
|
|
|
+ /// </summary>
|
|
|
+ private bool isFirstLoad = true;
|
|
|
+
|
|
|
+ private Visibility showTip = Visibility.Collapsed;
|
|
|
/// <summary>
|
|
|
/// 是否显示渐隐提示
|
|
|
/// </summary>
|
|
@@ -62,6 +69,20 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Visibility isLoading = Visibility.Collapsed;
|
|
|
+ /// <summary>
|
|
|
+ /// 是否正在处理中
|
|
|
+ /// </summary>
|
|
|
+ public Visibility IsLoading
|
|
|
+ {
|
|
|
+ get { return isLoading; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref isLoading, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private int listSelecedIndex;
|
|
|
/// <summary>
|
|
|
/// 缩略图选中项的索引
|
|
@@ -79,6 +100,20 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private bool isMutiSelected;
|
|
|
+ /// <summary>
|
|
|
+ /// 是否有多选 用于判断倒序和替换功能
|
|
|
+ /// </summary>
|
|
|
+ public bool IsMutiSelected
|
|
|
+ {
|
|
|
+ get { return isMutiSelected; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref isMutiSelected, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private int comboxSelectIndex;
|
|
|
/// <summary>
|
|
|
/// 下拉框选项集合
|
|
@@ -107,7 +142,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
set
|
|
|
{
|
|
|
SetProperty(ref tbPageRangeVisibility, value);
|
|
|
- if(value==Visibility.Visible)
|
|
|
+ if (value == Visibility.Visible)
|
|
|
{
|
|
|
comboxSelectIndex = -1;
|
|
|
}
|
|
@@ -141,11 +176,6 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 控件原始大小
|
|
|
- /// </summary>
|
|
|
- private Size itemSize = new Size(208,294);
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 页面缩放状态,-1 为最小值,1为最大值
|
|
|
/// </summary>
|
|
@@ -239,17 +269,17 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
SelectionChangedCommand = new DelegateCommand<object>(SelectionChangedEvent);
|
|
|
PreviewKeyDown = new DelegateCommand<object>(PreviewKeyDownEvent);
|
|
|
KeyDown = new DelegateCommand<object>(KeyDownEvent);
|
|
|
-
|
|
|
+
|
|
|
SplitCommand = new DelegateCommand(SplitCommandEvent);
|
|
|
InsertCommand = new DelegateCommand(InsertCommandEvent);
|
|
|
- ReplaceCommand = new DelegateCommand(ReplaceCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
- ExtractCommand = new DelegateCommand(ExtractCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ ReplaceCommand = new DelegateCommand(ReplaceCommandEvent, CanReplaceCommandExcute).ObservesProperty(() => IsMutiSelected);
|
|
|
+ ExtractCommand = new DelegateCommand(ExtractCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
DeleteCommand = new DelegateCommand(DeleteCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
LeftRotateCommand = new DelegateCommand(LeftRotateCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
RightRotateCommand = new DelegateCommand(RightRotateCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
- ReverseCommand = new DelegateCommand(ReverseCommandEvent,CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
- ZoomInCommand = new DelegateCommand(ZoomInCommandEvent,CanZoomIn).ObservesProperty(()=>ZoomIndex);
|
|
|
- ZoomOutCommand = new DelegateCommand(ZoomOutCommandEvent, CanZoomOut).ObservesProperty(()=> ZoomIndex);
|
|
|
+ ReverseCommand = new DelegateCommand(ReverseCommandEvent, CanFileCommandExcute).ObservesProperty(() => ListSelectedIndex);
|
|
|
+ ZoomInCommand = new DelegateCommand(ZoomInCommandEvent, CanZoomIn).ObservesProperty(() => ZoomIndex);
|
|
|
+ ZoomOutCommand = new DelegateCommand(ZoomOutCommandEvent, CanZoomOut).ObservesProperty(() => ZoomIndex);
|
|
|
|
|
|
//订阅页面刷新事件
|
|
|
eventAggregator.GetEvent<PageEditRefreshEvent>().Subscribe(OnPageEditRefreshEvent, e => e.Unicode == unicode);
|
|
@@ -262,9 +292,82 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// <summary>
|
|
|
/// 替换功能的逻辑
|
|
|
/// </summary>
|
|
|
- private void ReplaceCommandEvent()
|
|
|
+ private async void ReplaceCommandEvent()
|
|
|
{
|
|
|
+ OpenFileDialog dialog = new OpenFileDialog();
|
|
|
+ dialog.Multiselect = false;
|
|
|
+ dialog.Filter = PDF_Office.Properties.Resources.OpenDialogFilter;
|
|
|
+ if ((bool)dialog.ShowDialog())
|
|
|
+ {
|
|
|
+ IsLoading = Visibility.Visible;
|
|
|
+ await Task.Delay(200);
|
|
|
+ int pageCount = 0;
|
|
|
+ int insertIndex = -1;
|
|
|
+ CPDFDocument doc = CPDFDocument.InitWithFilePath(dialog.FileName);
|
|
|
+ if (doc == null)
|
|
|
+ {
|
|
|
+ showTip = Visibility.Visible;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (doc.IsLocked)
|
|
|
+ {
|
|
|
+ DialogParameters value = new DialogParameters();
|
|
|
+ value.Add(ParameterNames.PDFDocument, doc);
|
|
|
+ dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
|
|
|
+ {
|
|
|
+ if (e.Result != ButtonResult.OK)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ pageCount = doc.PageCount;
|
|
|
+
|
|
|
+ insertIndex = listSelecedIndex;
|
|
|
+ //删除原有页面
|
|
|
+ DeleteCommandEvent();
|
|
|
+
|
|
|
+ //插入整个新文档
|
|
|
+ //文档层插入
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ var result = PDFViewer.Document.ImportPagesAtIndex(doc, "1-" + pageCount, insertIndex);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ ShowTip = Visibility.Visible;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //插入成功后释放临时Document对象
|
|
|
+ doc.Release();
|
|
|
+ });
|
|
|
+ //UI层插入
|
|
|
+ for (int i = 0; i < pageCount; i++)
|
|
|
+ {
|
|
|
+ PageEditItem item = new PageEditItem();
|
|
|
+ if (PDFViewer.Document.PageAtIndex(i).Rotation % 2 != 0)
|
|
|
+ {
|
|
|
+ ///标记为横向页面
|
|
|
+ item.isVertical = false;
|
|
|
+ }
|
|
|
+ var pagesize = PDFViewer.Document.GetPageSize(i);
|
|
|
+ item.PageSize = $"{pagesize.Width}mm*{pagesize.Height} mm";
|
|
|
+ PageEditItems.Insert(insertIndex + i, item);
|
|
|
+ }
|
|
|
+
|
|
|
+ ReloadAfterOption(true, true, Tuple.Create(insertIndex, insertIndex + pageCount));
|
|
|
+
|
|
|
+ //加一点延时才能显示选中效果
|
|
|
+ await Task.Delay(400);
|
|
|
+
|
|
|
+ for (int i = 0; i < pageCount; i++)
|
|
|
+ {
|
|
|
+ PageEditItems[insertIndex + i].Selected = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -296,35 +399,8 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// </summary>
|
|
|
private void DeleteCommandEvent()
|
|
|
{
|
|
|
- List<int> indexList = new List<int>();
|
|
|
- for(int i=0;i<PageEditItems.Count;i++)
|
|
|
- {
|
|
|
- if(PageEditItems[i].Selected)
|
|
|
- {
|
|
|
- indexList.Add(i);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var result = PDFViewer.Document.RemovePages(indexList.ToArray());
|
|
|
- if(!result)
|
|
|
- {
|
|
|
- ShowTip = Visibility.Visible;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //文档层操作成功后再删除UI层
|
|
|
- for(int i= indexList.Count-1; i>=0;i--)
|
|
|
- {
|
|
|
- PageEditItems.RemoveAt(indexList[i]);
|
|
|
- }
|
|
|
-
|
|
|
- RefreshPageNum();
|
|
|
-
|
|
|
- PDFViewer.ReloadDocument();
|
|
|
-
|
|
|
- //清空undo栈,标记为可保存状态
|
|
|
- PDFViewer.UndoManager.ClearHistory();
|
|
|
- PDFViewer.UndoManager.CanSave = true;
|
|
|
+ DoRemoveSelectedPages();
|
|
|
+ ReloadAfterOption(true, true, null);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -357,29 +433,37 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// <returns></returns>
|
|
|
private bool CanFileCommandExcute()
|
|
|
{
|
|
|
- if(ListSelectedIndex<0)
|
|
|
+ if (ListSelectedIndex < 0)
|
|
|
{
|
|
|
return false;
|
|
|
- }
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 校验是否可以替换
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool CanReplaceCommandExcute()
|
|
|
+ {
|
|
|
+ return !IsMutiSelected;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 放大页面
|
|
|
/// </summary>
|
|
|
private void ZoomInCommandEvent()
|
|
|
{
|
|
|
- for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
PageEditItems[i].ItemSize = new Size(PageEditItems[i].ItemSize.Width * 2, PageEditItems[i].ItemSize.Height * 2);
|
|
|
}
|
|
|
ZoomIndex++;
|
|
|
|
|
|
- //通知UI刷新页面范围
|
|
|
- eventor.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs() { Unicode = unicode});
|
|
|
+ NotifyUIToRefresh();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -389,16 +473,15 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
|
for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
- PageEditItems[i].ItemSize = new Size(PageEditItems[i].ItemSize.Width /2, PageEditItems[i].ItemSize.Height /2);
|
|
|
+ PageEditItems[i].ItemSize = new Size(PageEditItems[i].ItemSize.Width / 2, PageEditItems[i].ItemSize.Height / 2);
|
|
|
}
|
|
|
ZoomIndex--;
|
|
|
- //通知UI刷新页面范围
|
|
|
- eventor.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs() { Unicode = unicode });
|
|
|
+ NotifyUIToRefresh();
|
|
|
}
|
|
|
|
|
|
private bool CanZoomIn()
|
|
|
{
|
|
|
- if(ZoomIndex>=1)
|
|
|
+ if (ZoomIndex >= 1)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
@@ -410,7 +493,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
|
|
|
private bool CanZoomOut()
|
|
|
{
|
|
|
- if (ZoomIndex <=-1)
|
|
|
+ if (ZoomIndex <= -1)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
@@ -441,18 +524,18 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
|
var args = e as SelectionChangedEventArgs;
|
|
|
var listbox = args.OriginalSource as ListBox;
|
|
|
- if (TbPageRangeVisibility == Visibility.Visible&&args!=null)
|
|
|
+ if (TbPageRangeVisibility == Visibility.Visible && args != null)
|
|
|
{
|
|
|
List<int> pagelist = new List<int>();
|
|
|
- for(int i=0;i< listbox.SelectedItems.Count;i++)
|
|
|
+ for (int i = 0; i < listbox.SelectedItems.Count; i++)
|
|
|
{
|
|
|
pagelist.Add((listbox.SelectedItems[i] as PageEditItem).PageNumber);
|
|
|
}
|
|
|
|
|
|
//手动取消其他项的选中状态
|
|
|
- for(int j=0;j<PageEditItems.Count;j++)
|
|
|
+ for (int j = 0; j < PageEditItems.Count; j++)
|
|
|
{
|
|
|
- if(!pagelist.Contains(PageEditItems[j].PageNumber))
|
|
|
+ if (!pagelist.Contains(PageEditItems[j].PageNumber))
|
|
|
{
|
|
|
PageEditItems[j].Selected = false;
|
|
|
}
|
|
@@ -468,12 +551,22 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
string pageparm = CommonHelper.GetPageParmFromList(pagelist);
|
|
|
TbPageRange = pageparm;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
if (listbox.SelectedItem != null)
|
|
|
{
|
|
|
listbox.ScrollIntoView(listbox.SelectedItem);
|
|
|
}
|
|
|
+
|
|
|
+ //判断是否有选中多项
|
|
|
+ if (listbox.SelectedItems.Count > 1)
|
|
|
+ {
|
|
|
+ IsMutiSelected = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsMutiSelected = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -483,12 +576,12 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
private void PreviewKeyDownEvent(object e)
|
|
|
{
|
|
|
var args = e as KeyEventArgs;
|
|
|
- if(args==null)
|
|
|
+ if (args == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (args.Key!=Key.Enter&&args.Key!=Key.Back&&args.Key !=Key.OemComma && args.Key !=Key.Subtract && !((args.Key>=Key.D0&&args.Key<=Key.D9)||(args.Key>=Key.NumPad0&&args.Key<=Key.NumPad9)))
|
|
|
+ if (args.Key != Key.Enter && args.Key != Key.Back && args.Key != Key.OemComma && args.Key != Key.Subtract && !((args.Key >= Key.D0 && args.Key <= Key.D9) || (args.Key >= Key.NumPad0 && args.Key <= Key.NumPad9)))
|
|
|
{
|
|
|
args.Handled = true;
|
|
|
}
|
|
@@ -501,7 +594,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
private void KeyDownEvent(object e)
|
|
|
{
|
|
|
var args = e as KeyEventArgs;
|
|
|
- if(args==null)
|
|
|
+ if (args == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
@@ -517,7 +610,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
//选中输入的页面范围
|
|
|
for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
- if (TargetPageIndexs.Contains(PageEditItems[i].PageNumber-1))
|
|
|
+ if (TargetPageIndexs.Contains(PageEditItems[i].PageNumber - 1))
|
|
|
{
|
|
|
PageEditItems[i].Selected = true;
|
|
|
}
|
|
@@ -532,31 +625,105 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
#endregion
|
|
|
|
|
|
#region 方法
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通知UI刷新页面范围
|
|
|
+ /// </summary>
|
|
|
+ private void NotifyUIToRefresh()
|
|
|
+ {
|
|
|
+ //通知UI刷新页面范围
|
|
|
+ eventor.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs() { Unicode = unicode });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除选中项的方法 不带Reload操作
|
|
|
+ /// 方便其他逻辑中调用
|
|
|
+ /// </summary>
|
|
|
+ private async void DoRemoveSelectedPages()
|
|
|
+ {
|
|
|
+ IsLoading = Visibility.Visible;
|
|
|
+ await Task.Delay(3);
|
|
|
+ List<int> indexList = new List<int>();
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
+ {
|
|
|
+ if (PageEditItems[i].Selected)
|
|
|
+ {
|
|
|
+ indexList.Add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = PDFViewer.Document.RemovePages(indexList.ToArray());
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ ShowTip = Visibility.Visible;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //文档层操作成功后再删除UI层
|
|
|
+ for (int i = indexList.Count - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ PageEditItems.RemoveAt(indexList[i]);
|
|
|
+ }
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 进行文件操作后刷新PDFView
|
|
|
+ /// 清除undo 栈
|
|
|
+ /// 重加载Document
|
|
|
+ /// 设置保存状态
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="needRefreshPageNum">是否需要刷新页码</param>
|
|
|
+ /// <param name="needClearUndoHistory">是否需要清空注释Undo栈</param>
|
|
|
+ /// <param name="pageRange">需要刷新的页面范围图片</param>
|
|
|
+ private void ReloadAfterOption(bool needRefreshPageNum = false, bool needClearUndoHistory = true, Tuple<int, int> pageRange = null)
|
|
|
+ {
|
|
|
+ if (needRefreshPageNum)
|
|
|
+ {
|
|
|
+ RefreshPageNum();
|
|
|
+ }
|
|
|
+ if (needClearUndoHistory)
|
|
|
+ {
|
|
|
+ PDFViewer.UndoManager.ClearHistory();
|
|
|
+ }
|
|
|
+ if (pageRange != null)
|
|
|
+ {
|
|
|
+ if (pageRange.Item2 - pageRange.Item1 > 30)
|
|
|
+ {
|
|
|
+ //范围较大时,通知UI获取更准确的刷新范围
|
|
|
+ eventor.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs() { Unicode = unicode });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RefreshItemImage(pageRange.Item1, pageRange.Item2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PDFViewer.UndoManager.CanSave = true;
|
|
|
+ PDFViewer.ReloadDocument();
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 旋转所有选中页面
|
|
|
/// </summary>
|
|
|
/// <param name="rightRotate"></param>
|
|
|
- private void RotateSelectedPages(bool rightRotate = true)
|
|
|
+ private async void RotateSelectedPages(bool rightRotate = true)
|
|
|
{
|
|
|
+ IsLoading = Visibility.Visible;
|
|
|
+ await Task.Delay(2);
|
|
|
for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
if (PageEditItems[i].Selected)
|
|
|
{
|
|
|
- //逆时针旋转传-1 顺时针旋转传1
|
|
|
- PDFViewer.Document.RotatePage(i, rightRotate?1:-1);
|
|
|
+ //逆时针旋转传 - 1 顺时针旋转传1
|
|
|
+ PDFViewer.Document.RotatePage(i, rightRotate ? 1 : -1);
|
|
|
PDFViewer.Document.ReleasePages(i);
|
|
|
|
|
|
//重新拿图
|
|
|
PageEditItems[i].isVertical = !PageEditItems[i].isVertical;
|
|
|
PageEditItems[i].IsGetImage = false;
|
|
|
- RefreshItemImage(i, i);
|
|
|
-
|
|
|
- PDFViewer.UndoManager.ClearHistory();
|
|
|
- PDFViewer.UndoManager.CanSave = true;
|
|
|
- //需要ReloadDocument 才能刷新阅读页图片
|
|
|
- PDFViewer.ReloadDocument();
|
|
|
}
|
|
|
}
|
|
|
+ ReloadAfterOption(false, true, Tuple.Create(0,PageEditItems.Count));
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -564,7 +731,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// </summary>
|
|
|
private void RefreshPageNum()
|
|
|
{
|
|
|
- for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
PageEditItems[i].PageNumber = i + 1;
|
|
|
}
|
|
@@ -669,9 +836,9 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// 是否显示页面尺寸
|
|
|
/// </summary>
|
|
|
/// <param name="show">是或否</param>
|
|
|
- private void ShowPageSize(bool show=true)
|
|
|
+ private void ShowPageSize(bool show = true)
|
|
|
{
|
|
|
- for(int i=0;i<PageEditItems.Count;i++)
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
PageEditItems[i].ShowPageSize = show;
|
|
|
}
|
|
@@ -681,22 +848,33 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// <summary>
|
|
|
/// 从PDFView获取所有Items集合
|
|
|
/// </summary>
|
|
|
- private void GetSourceItems()
|
|
|
+ private void GetSourceItems(bool isFirstLoad)
|
|
|
{
|
|
|
- PageEditItems.Clear();
|
|
|
- for (int i = 0; i < PDFViewer.Document.PageCount; i++)
|
|
|
+ if (isFirstLoad)
|
|
|
{
|
|
|
- PageEditItem item = new PageEditItem();
|
|
|
- item.PageNumber = i + 1;
|
|
|
+ PageEditItems.Clear();
|
|
|
+ for (int i = 0; i < PDFViewer.Document.PageCount; i++)
|
|
|
+ {
|
|
|
+ PageEditItem item = new PageEditItem();
|
|
|
+ item.PageNumber = i + 1;
|
|
|
|
|
|
- if(PDFViewer.Document.PageAtIndex(i).Rotation % 2 != 0)
|
|
|
+ if (PDFViewer.Document.PageAtIndex(i).Rotation % 2 != 0)
|
|
|
+ {
|
|
|
+ ///标记为横向页面
|
|
|
+ item.isVertical = false;
|
|
|
+ }
|
|
|
+ var pagesize = PDFViewer.Document.GetPageSize(i);
|
|
|
+ item.PageSize = $"{pagesize.Width}mm*{pagesize.Height} mm";
|
|
|
+ PageEditItems.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //后续进来仅刷新图片即可
|
|
|
+ for (int i = 0; i < PageEditItems.Count; i++)
|
|
|
{
|
|
|
- ///标记为横向页面
|
|
|
- PageEditItems[i].isVertical = false;
|
|
|
+ PageEditItems[i].IsGetImage = false;
|
|
|
}
|
|
|
- var pagesize = PDFViewer.Document.GetPageSize(i);
|
|
|
- item.PageSize = $"{pagesize.Width}mm*{pagesize.Height} mm";
|
|
|
- PageEditItems.Add(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -709,8 +887,8 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
{
|
|
|
var booklist = PDFViewer.Document.GetBookmarkList();
|
|
|
if (booklist == null)
|
|
|
- {
|
|
|
- return;
|
|
|
+ {
|
|
|
+ return;
|
|
|
}
|
|
|
//获取所有书签的Index集合
|
|
|
List<int> marks = new List<int>();
|
|
@@ -735,11 +913,11 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
/// </summary>
|
|
|
/// <param name="startIndex"></param>
|
|
|
/// <param name="endIndex"></param>
|
|
|
- private async void RefreshItemImage(int startIndex,int endIndex)
|
|
|
+ private async void RefreshItemImage(int startIndex, int endIndex)
|
|
|
{
|
|
|
- for (int i = startIndex; i <=endIndex;i++)
|
|
|
+ for (int i = startIndex; i <= endIndex; i++)
|
|
|
{
|
|
|
- if (i <= PDFViewer.Document.PageCount - 1&&i>=0)
|
|
|
+ if (i <= PDFViewer.Document.PageCount - 1 && i >= 0 && PageEditItems.Count > 0)
|
|
|
{
|
|
|
//宽高为样式中图片控件宽高
|
|
|
if (PageEditItems[i].isVertical)
|
|
@@ -789,7 +967,7 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -804,15 +982,19 @@ namespace PDF_Office.ViewModels.PageEdit
|
|
|
navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
if (PDFViewer != null)
|
|
|
{
|
|
|
- PDFViewer.OnThumbnailGenerated += PDFViewer_OnThumbnailGenerated;
|
|
|
+ if (isFirstLoad)
|
|
|
+ {
|
|
|
+ PDFViewer.OnThumbnailGenerated += PDFViewer_OnThumbnailGenerated;
|
|
|
+ ZoomIndex = 0;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- GetSourceItems();
|
|
|
+ GetSourceItems(isFirstLoad);
|
|
|
|
|
|
ListSelectedIndex = PDFViewer.CurrentIndex;
|
|
|
|
|
|
- ZoomIndex = 0;
|
|
|
-
|
|
|
RefreshBookMarkList();
|
|
|
+ isFirstLoad = false;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|