|
@@ -118,7 +118,6 @@ namespace Compdfkit_Tools.PDFControl
|
|
get { return PageEditListBox.SelectedIndex; }
|
|
get { return PageEditListBox.SelectedIndex; }
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public event EventHandler ExitPageEdit;
|
|
public event EventHandler ExitPageEdit;
|
|
|
|
|
|
public CPDFPageEditControl()
|
|
public CPDFPageEditControl()
|
|
@@ -151,9 +150,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pageExtractWindow.InitPageExtractWindow(SelectedItemsRange, pdfViewer.Document.PageCount);
|
|
pageExtractWindow.InitPageExtractWindow(SelectedItemsRange, pdfViewer.Document.PageCount);
|
|
pageExtractWindow.DialogClosed += PageExtractWindow_DialogClosed;
|
|
pageExtractWindow.DialogClosed += PageExtractWindow_DialogClosed;
|
|
pageExtractWindow.Owner = parentWindow;
|
|
pageExtractWindow.Owner = parentWindow;
|
|
- pageExtractWindow.ShowDialog();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ pageExtractWindow.ShowDialog();
|
|
}
|
|
}
|
|
else if (PageEditString == "Copy")
|
|
else if (PageEditString == "Copy")
|
|
{
|
|
{
|
|
@@ -203,11 +200,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
- {
|
|
|
|
- // Hide the Border control after the timer is triggered
|
|
|
|
|
|
+ {
|
|
AlertBorder.Visibility = Visibility.Collapsed;
|
|
AlertBorder.Visibility = Visibility.Collapsed;
|
|
-
|
|
|
|
- // Stop the timer
|
|
|
|
|
|
+
|
|
DispatcherTimer timer = (DispatcherTimer)sender;
|
|
DispatcherTimer timer = (DispatcherTimer)sender;
|
|
timer.Stop();
|
|
timer.Stop();
|
|
timer.Tick -= Timer_Tick;
|
|
timer.Tick -= Timer_Tick;
|
|
@@ -257,8 +252,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
ScrollViewer sv = GetScrollHost(PageEditListBox);
|
|
ScrollViewer sv = GetScrollHost(PageEditListBox);
|
|
-
|
|
|
|
- //ListBoxItem item = PageEditListBox.Items[pageIndex] as ListBoxItem;
|
|
|
|
|
|
+
|
|
ListBoxItem listboxitem = PageEditListBox.ItemContainerGenerator.ContainerFromIndex(pageIndex) as ListBoxItem;
|
|
ListBoxItem listboxitem = PageEditListBox.ItemContainerGenerator.ContainerFromIndex(pageIndex) as ListBoxItem;
|
|
if (ViewportHelper.IsInViewport(sv, listboxitem))
|
|
if (ViewportHelper.IsInViewport(sv, listboxitem))
|
|
{
|
|
{
|
|
@@ -407,16 +401,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- ///
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="isFromClick">是否是缩放时的刷新</param>
|
|
|
|
public void RefreshThumbnail(bool isZooming = false)
|
|
public void RefreshThumbnail(bool isZooming = false)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
if (pdfViewer == null) return;
|
|
if (pdfViewer == null) return;
|
|
- //确保缩放后选中项不发生改变
|
|
|
|
var items = GetListFromSelectedItems();
|
|
var items = GetListFromSelectedItems();
|
|
PopulateThumbnailList();
|
|
PopulateThumbnailList();
|
|
if (pdfViewer.CurrentIndex >= PageEditListBox.Items.Count)
|
|
if (pdfViewer.CurrentIndex >= PageEditListBox.Items.Count)
|
|
@@ -445,7 +434,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private void PageEditListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
|
|
private void PageEditListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
|
|
{
|
|
{
|
|
- ItemsInViewHitTest();//第一次加载时触发的Scollchange 直接刷新界面,减少白板显示时间
|
|
|
|
|
|
+ ItemsInViewHitTest();
|
|
|
|
|
|
if (startChoose)
|
|
if (startChoose)
|
|
{
|
|
{
|
|
@@ -464,16 +453,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
var s = GetScrollHost(PageEditListBox);
|
|
var s = GetScrollHost(PageEditListBox);
|
|
Point start = new Point();
|
|
Point start = new Point();
|
|
- start = new Point(startPostion.X, startPostion.Y - s.VerticalOffset);//通过 实时的垂直偏移量和第一次的偏移量抵消,来获取准确的垂直偏移值。
|
|
|
|
|
|
+ start = new Point(startPostion.X, startPostion.Y - s.VerticalOffset);
|
|
var rec = new Rect(start, Mouse.GetPosition(PageEditListBox));
|
|
var rec = new Rect(start, Mouse.GetPosition(PageEditListBox));
|
|
ChooseRect.Margin = new Thickness(rec.Left, rec.Top, 0, 0);
|
|
ChooseRect.Margin = new Thickness(rec.Left, rec.Top, 0, 0);
|
|
ChooseRect.Width = rec.Width;
|
|
ChooseRect.Width = rec.Width;
|
|
ChooseRect.Height = rec.Height;
|
|
ChooseRect.Height = rec.Height;
|
|
ChooseRect.Visibility = Visibility.Visible;
|
|
ChooseRect.Visibility = Visibility.Visible;
|
|
- for (int i = 0; i < PageEditListBox.Items.Count; i++)//检测所有内容是否在矩形框中
|
|
|
|
|
|
+ for (int i = 0; i < PageEditListBox.Items.Count; i++)
|
|
{
|
|
{
|
|
var _item = PageEditListBox.Items[i] as ListBoxItem;
|
|
var _item = PageEditListBox.Items[i] as ListBoxItem;
|
|
- //通过这一步来避免重复误选中
|
|
|
|
var parent = Utils.FindVisualParent<VirtualizingWrapPanel>(_item);
|
|
var parent = Utils.FindVisualParent<VirtualizingWrapPanel>(_item);
|
|
if (parent == null)
|
|
if (parent == null)
|
|
continue;
|
|
continue;
|
|
@@ -522,7 +510,6 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //未选中item 并且不是点击滑轨时 开始框选
|
|
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
var scroller = Utils.FindVisualParent<ScrollBar>(result.VisualHit);
|
|
var scroller = Utils.FindVisualParent<ScrollBar>(result.VisualHit);
|
|
if (listBoxItem == null)
|
|
if (listBoxItem == null)
|
|
@@ -532,7 +519,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
startChoose = false;
|
|
startChoose = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //点击空白处时开始框选
|
|
|
|
|
|
+
|
|
startChoose = true;
|
|
startChoose = true;
|
|
PageEditListBox.SelectedItems.Clear();
|
|
PageEditListBox.SelectedItems.Clear();
|
|
startPostion = e.GetPosition(PageEditListBox);
|
|
startPostion = e.GetPosition(PageEditListBox);
|
|
@@ -541,10 +528,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
Mouse.Capture(PageEditListBox);
|
|
Mouse.Capture(PageEditListBox);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- startChoose = false;//选中了item 时,不能框选
|
|
|
|
|
|
+ startChoose = false;
|
|
if (listBoxItem.IsSelected == true && !Keyboard.IsKeyDown(Key.LeftCtrl))
|
|
if (listBoxItem.IsSelected == true && !Keyboard.IsKeyDown(Key.LeftCtrl))
|
|
{
|
|
{
|
|
- // isDraging = true;
|
|
|
|
e.Handled = true;
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -566,11 +552,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- // shift多选后,再次点击时,清空选中项,高亮当前项 按下ctrl时,不处理
|
|
|
|
- //因为listView 本身在选择项方面相当别扭,所以常见的按键模式都要逐个测试,并借助较多的限定条件才能实现
|
|
|
|
if (iskeyDown && !Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift))
|
|
if (iskeyDown && !Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift))
|
|
{
|
|
{
|
|
- //IskeyDown = false;
|
|
|
|
PageEditListBox.SelectedItems.Clear();
|
|
PageEditListBox.SelectedItems.Clear();
|
|
PageEditListBox.SelectedItem = listBoxItem;
|
|
PageEditListBox.SelectedItem = listBoxItem;
|
|
listBoxItem.IsSelected = true;
|
|
listBoxItem.IsSelected = true;
|
|
@@ -587,7 +570,6 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
if (isDragingEnter)
|
|
if (isDragingEnter)
|
|
{
|
|
{
|
|
- //在当前位置插入整个pdf
|
|
|
|
CPDFDocument dragDoc = CPDFDocument.InitWithFilePath(dragingEnterPath);
|
|
CPDFDocument dragDoc = CPDFDocument.InitWithFilePath(dragingEnterPath);
|
|
if (dragingEnterPath.Substring(dragingEnterPath.LastIndexOf(".")).ToLower() == ".pdf")
|
|
if (dragingEnterPath.Substring(dragingEnterPath.LastIndexOf(".")).ToLower() == ".pdf")
|
|
{
|
|
{
|
|
@@ -608,12 +590,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
else
|
|
else
|
|
{
|
|
{
|
|
}
|
|
}
|
|
- //提示文档损坏无法打开
|
|
|
|
}
|
|
}
|
|
else if (!string.IsNullOrEmpty(dragingEnterPath))
|
|
else if (!string.IsNullOrEmpty(dragingEnterPath))
|
|
{
|
|
{
|
|
- //其他文件 则新增一个页签打开
|
|
|
|
- // DragAddTab.Invoke(dragingEnterPath, new RoutedEventArgs());//底层库需要加一个 Load(TPDFDocument)的接口
|
|
|
|
}
|
|
}
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
isDragingEnter = false;
|
|
isDragingEnter = false;
|
|
@@ -624,12 +603,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
var result = VisualTreeHelper.HitTest(PageEditListBox, pos);
|
|
var result = VisualTreeHelper.HitTest(PageEditListBox, pos);
|
|
if (result == null)
|
|
if (result == null)
|
|
{
|
|
{
|
|
- //超出当前可控区域
|
|
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
isDraging = false;
|
|
isDraging = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //查找元数据
|
|
|
|
var sourcePerson = e.Data.GetData(typeof(StackPanel)) as StackPanel;
|
|
var sourcePerson = e.Data.GetData(typeof(StackPanel)) as StackPanel;
|
|
if (sourcePerson == null)
|
|
if (sourcePerson == null)
|
|
{
|
|
{
|
|
@@ -637,19 +614,16 @@ namespace Compdfkit_Tools.PDFControl
|
|
isDraging = false;
|
|
isDraging = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //查找目标数据
|
|
|
|
- int targetindex = 0;//目标插入位置
|
|
|
|
|
|
+ int targetindex = 0;
|
|
if (InsertIndex != -1)
|
|
if (InsertIndex != -1)
|
|
{
|
|
{
|
|
- //往前移动时 此index 不是准确的,需要处理++
|
|
|
|
targetindex = InsertIndex;
|
|
targetindex = InsertIndex;
|
|
}
|
|
}
|
|
- else//基本不会命中 仅作为保险措施
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
if (listBoxItem == null)
|
|
if (listBoxItem == null)
|
|
{
|
|
{
|
|
- ////鼠标停留在两个item之间或其他无效区域 暂时不做处理(比较麻烦)
|
|
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
isDraging = false;
|
|
isDraging = false;
|
|
return;
|
|
return;
|
|
@@ -668,14 +642,12 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
List<ListBoxItem> list = new List<ListBoxItem>();
|
|
List<ListBoxItem> list = new List<ListBoxItem>();
|
|
- List<int> sourceindex = new List<int>();//需要保存每个页面对应的位置
|
|
|
|
- //开始排序
|
|
|
|
|
|
+ List<int> sourceindex = new List<int>();
|
|
List<int> pages = new List<int>();
|
|
List<int> pages = new List<int>();
|
|
- //要先对所有选中项 根据页码排序
|
|
|
|
for (int i = 0; i < PageEditListBox.SelectedItems.Count; i++)
|
|
for (int i = 0; i < PageEditListBox.SelectedItems.Count; i++)
|
|
{
|
|
{
|
|
var pageindex = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[i] as ListBoxItem);
|
|
var pageindex = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[i] as ListBoxItem);
|
|
- pages.Add(pageindex);//存入的为页码索引值
|
|
|
|
|
|
+ pages.Add(pageindex);
|
|
}
|
|
}
|
|
pages.Sort();
|
|
pages.Sort();
|
|
if (pages.Count <= 0)
|
|
if (pages.Count <= 0)
|
|
@@ -685,9 +657,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- //要考虑每一次交换都会导致局部页码发生改变
|
|
|
|
- //每次整体往后移动时,先移动大页码;整体往前移动时,先移动小页码;往中间移动时,再按上述两种情况分别移动
|
|
|
|
- if (targetindex <= pages[0])// 目标位置在所有选中内容左边,整体前移动 优先先判断左移的情况
|
|
|
|
|
|
+ if (targetindex <= pages[0])
|
|
{
|
|
{
|
|
sourceindex.Add(-1);
|
|
sourceindex.Add(-1);
|
|
list = new List<ListBoxItem>();
|
|
list = new List<ListBoxItem>();
|
|
@@ -698,7 +668,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
DragToSort(pages[i], targetindex + i);
|
|
DragToSort(pages[i], targetindex + i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if (targetindex > pages[pages.Count - 1])//目标位置在所有选中内容右边 整体后移
|
|
|
|
|
|
+ else if (targetindex > pages[pages.Count - 1])
|
|
{
|
|
{
|
|
sourceindex.Add(1);
|
|
sourceindex.Add(1);
|
|
list = new List<ListBoxItem>();
|
|
list = new List<ListBoxItem>();
|
|
@@ -706,43 +676,40 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
list.Add(PageEditListBox.Items[pages[pages.Count - 1 - i]] as ListBoxItem);
|
|
list.Add(PageEditListBox.Items[pages[pages.Count - 1 - i]] as ListBoxItem);
|
|
sourceindex.Add(pages[pages.Count - 1 - i]);
|
|
sourceindex.Add(pages[pages.Count - 1 - i]);
|
|
- DragToSort(pages[pages.Count - 1 - i], targetindex - 1 - i/* + (PageEditListBox.SelectedItems.Count - 1 - i)*/);
|
|
|
|
|
|
+ DragToSort(pages[pages.Count - 1 - i], targetindex - 1 - i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else//目标位置在所有选中项中间
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
int i, j, k;
|
|
int i, j, k;
|
|
- for (k = 0; k < pages.Count - 1; k++)//找出PageEditListBox.Items中页码等于destpage的下标
|
|
|
|
|
|
+ for (k = 0; k < pages.Count - 1; k++)
|
|
{
|
|
{
|
|
- //这里要算入K---即前面部分的页面个数
|
|
|
|
if (pages[k] < targetindex && pages[k + 1] >= targetindex)
|
|
if (pages[k] < targetindex && pages[k + 1] >= targetindex)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
sourceindex.Add(0);
|
|
sourceindex.Add(0);
|
|
list = new List<ListBoxItem>();
|
|
list = new List<ListBoxItem>();
|
|
- for (i = 0; i <= k; i++)//局部往后移动
|
|
|
|
|
|
+ for (i = 0; i <= k; i++)
|
|
{
|
|
{
|
|
list.Add(PageEditListBox.Items[pages[k - i]] as ListBoxItem);
|
|
list.Add(PageEditListBox.Items[pages[k - i]] as ListBoxItem);
|
|
sourceindex.Add(pages[k - i]);
|
|
sourceindex.Add(pages[k - i]);
|
|
DragToSort(pages[k - i], targetindex - 1 - i);
|
|
DragToSort(pages[k - i], targetindex - 1 - i);
|
|
}
|
|
}
|
|
- for (j = i; j < pages.Count; j++)//局部往前移动
|
|
|
|
|
|
+ for (j = i; j < pages.Count; j++)
|
|
{
|
|
{
|
|
list.Add(PageEditListBox.Items[pages[j]] as ListBoxItem);
|
|
list.Add(PageEditListBox.Items[pages[j]] as ListBoxItem);
|
|
sourceindex.Add(pages[j]);
|
|
sourceindex.Add(pages[j]);
|
|
DragToSort(pages[j], targetindex);
|
|
DragToSort(pages[j], targetindex);
|
|
targetindex++;
|
|
targetindex++;
|
|
}
|
|
}
|
|
- sourceindex.Add(k);//往中间移时, index数组的最后一位 表示 间隔位置K
|
|
|
|
|
|
+ sourceindex.Add(k);
|
|
}
|
|
}
|
|
isDraging = false;
|
|
isDraging = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void MidLane_Drop(object sender, DragEventArgs e)
|
|
private void MidLane_Drop(object sender, DragEventArgs e)
|
|
- {
|
|
|
|
- //指针停留在中间线上后释放 也需要隐藏
|
|
|
|
- MidLane.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
+ { MidLane.Visibility = Visibility.Collapsed;
|
|
this.PageEditListBox_Drop(sender, e);
|
|
this.PageEditListBox_Drop(sender, e);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -761,7 +728,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
startChoose = false;
|
|
startChoose = false;
|
|
ChooseRect.Visibility = Visibility.Collapsed;
|
|
ChooseRect.Visibility = Visibility.Collapsed;
|
|
- Mouse.Capture(null);//暂时未想到靠近顶部和底部自动翻滚的好方法,只能先屏蔽这部分功能
|
|
|
|
|
|
+ Mouse.Capture(null);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
DoSelectItems();
|
|
DoSelectItems();
|
|
@@ -810,33 +777,21 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
private void Grid_DragOver(object sender, DragEventArgs e)
|
|
private void Grid_DragOver(object sender, DragEventArgs e)
|
|
- {
|
|
|
|
- //if (startchoose)
|
|
|
|
- //{
|
|
|
|
- // return;
|
|
|
|
- //}
|
|
|
|
|
|
+ {
|
|
try
|
|
try
|
|
- {
|
|
|
|
- //ctrl建按下 不显示插入标记和虚影 因为释放不会响应drop事件
|
|
|
|
|
|
+ {
|
|
if (e.KeyStates == (DragDropKeyStates.ControlKey | DragDropKeyStates.LeftMouseButton) || e.KeyStates == (DragDropKeyStates.ShiftKey | DragDropKeyStates.LeftMouseButton | DragDropKeyStates.ControlKey))
|
|
if (e.KeyStates == (DragDropKeyStates.ControlKey | DragDropKeyStates.LeftMouseButton) || e.KeyStates == (DragDropKeyStates.ShiftKey | DragDropKeyStates.LeftMouseButton | DragDropKeyStates.ControlKey))
|
|
return;
|
|
return;
|
|
-
|
|
|
|
- //滚动后有 位置不准确 要减去滚动偏移量
|
|
|
|
- //控制线的位置
|
|
|
|
|
|
+
|
|
var pos = e.GetPosition(PageEditListBox);
|
|
var pos = e.GetPosition(PageEditListBox);
|
|
var result = VisualTreeHelper.HitTest(PageEditListBox, pos);
|
|
var result = VisualTreeHelper.HitTest(PageEditListBox, pos);
|
|
if (result == null)
|
|
if (result == null)
|
|
- {
|
|
|
|
- //MidLane.Visibility = Visibility.Collapsed;
|
|
|
|
- //return;
|
|
|
|
|
|
+ {
|
|
}
|
|
}
|
|
-
|
|
|
|
- //获取当前鼠标指针下的容器
|
|
|
|
|
|
+
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
|
if (listBoxItem == null)
|
|
if (listBoxItem == null)
|
|
- {
|
|
|
|
- //MidLane.Visibility = Visibility.Collapsed;
|
|
|
|
- //return;
|
|
|
|
|
|
+ {
|
|
}
|
|
}
|
|
|
|
|
|
#region 计算虚影位置
|
|
#region 计算虚影位置
|
|
@@ -903,8 +858,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
-
|
|
|
|
- //暂时处理 鼠标移出边框时,虚影的显示问题
|
|
|
|
|
|
+
|
|
if (pos.Y <= 30 || pos.Y >= PageEditListBox.ActualHeight - 10)
|
|
if (pos.Y <= 30 || pos.Y >= PageEditListBox.ActualHeight - 10)
|
|
{
|
|
{
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
MidLane.Visibility = Visibility.Collapsed;
|
|
@@ -927,8 +881,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
var v = scroll.VerticalOffset;
|
|
var v = scroll.VerticalOffset;
|
|
- scroll.ScrollToVerticalOffset(v + speed);//触发连续滚动
|
|
|
|
- //SetReadModeTip(true, str, true);
|
|
|
|
|
|
+ scroll.ScrollToVerticalOffset(v + speed);
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -941,11 +894,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
this.PageEditListBox_Drop(sender, e);
|
|
this.PageEditListBox_Drop(sender, e);
|
|
}
|
|
}
|
|
-
|
|
|
|
- //增加辅助判断,防止误触发 拖动排序
|
|
|
|
|
|
+
|
|
private void ListBoxItem_DragLeave(object sender, DragEventArgs e)
|
|
private void ListBoxItem_DragLeave(object sender, DragEventArgs e)
|
|
- {
|
|
|
|
- //较大幅度拖动才能触发排序
|
|
|
|
|
|
+ {
|
|
isDraging = true;
|
|
isDraging = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -956,8 +907,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
var list = GetListFromSelectedItems();
|
|
var list = GetListFromSelectedItems();
|
|
DoDelete(list, true);
|
|
DoDelete(list, true);
|
|
}
|
|
}
|
|
-
|
|
|
|
- //顺时针旋转图片
|
|
|
|
|
|
+
|
|
public void Rotate_Click(object sender, RoutedEventArgs e)
|
|
public void Rotate_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
var item = sender as MenuItem;
|
|
var item = sender as MenuItem;
|
|
@@ -1014,16 +964,14 @@ namespace Compdfkit_Tools.PDFControl
|
|
if (pdfViewer == null)
|
|
if (pdfViewer == null)
|
|
return;
|
|
return;
|
|
if (isFirstLoad)
|
|
if (isFirstLoad)
|
|
- {
|
|
|
|
- //第一次载入的时候 减少一次刷新次数
|
|
|
|
|
|
+ {
|
|
isFirstLoad = false;
|
|
isFirstLoad = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if ((bool)e.NewValue == true && pdfViewer != null && pdfViewer.CurrentIndex >= 0 /*&& (this.Parent as Grid).Name != "Thumbnail"*/)//添加一个判断条件,避免来回切换时影响缩略图显示效果
|
|
|
|
|
|
+ if ((bool)e.NewValue == true && pdfViewer != null && pdfViewer.CurrentIndex >= 0)
|
|
{
|
|
{
|
|
- RefreshThumbnail();//保证从View 切换到PageEdit时,能及时更新
|
|
|
|
- }
|
|
|
|
- //每次切换到页面编辑都同步选中项
|
|
|
|
|
|
+ RefreshThumbnail();
|
|
|
|
+ }
|
|
if (pdfViewer?.CurrentIndex >= PageEditListBox.Items.Count || PageEditListBox.Items.Count == 0)
|
|
if (pdfViewer?.CurrentIndex >= PageEditListBox.Items.Count || PageEditListBox.Items.Count == 0)
|
|
return;
|
|
return;
|
|
ListBoxItem item = PageEditListBox.Items[pdfViewer?.CurrentIndex == -1 ? 0 : pdfViewer.CurrentIndex] as ListBoxItem;
|
|
ListBoxItem item = PageEditListBox.Items[pdfViewer?.CurrentIndex == -1 ? 0 : pdfViewer.CurrentIndex] as ListBoxItem;
|
|
@@ -1033,8 +981,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
private async void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
private async void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
- {
|
|
|
|
- //点击刷新加载失败的图片
|
|
|
|
|
|
+ {
|
|
if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift))
|
|
if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift))
|
|
{
|
|
{
|
|
var item = sender as ListBoxItem;
|
|
var item = sender as ListBoxItem;
|
|
@@ -1051,7 +998,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
private void PageGrid_PreviewDragEnter(object sender, DragEventArgs e)
|
|
private void PageGrid_PreviewDragEnter(object sender, DragEventArgs e)
|
|
{
|
|
{
|
|
var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
|
|
var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
|
|
- if (file == null || file.Length > 1)//为null 表示内部拖动 触发的
|
|
|
|
|
|
+ if (file == null || file.Length > 1)
|
|
{ return; }
|
|
{ return; }
|
|
foreach (var f in file)
|
|
foreach (var f in file)
|
|
{
|
|
{
|
|
@@ -1062,8 +1009,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- //右键菜单初始化
|
|
|
|
|
|
+
|
|
private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
|
|
private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
if (ViewportHelper.CopyDoc == null)
|
|
if (ViewportHelper.CopyDoc == null)
|
|
@@ -1132,7 +1078,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
if (viewer == null || viewer.Document == null)
|
|
if (viewer == null || viewer.Document == null)
|
|
return;
|
|
return;
|
|
|
|
|
|
- if (pdfViewer != null && viewer != pdfViewer)//创建空白文档 更新pdfviewer时
|
|
|
|
|
|
+ if (pdfViewer != null && viewer != pdfViewer)
|
|
{
|
|
{
|
|
pdfViewer = viewer;
|
|
pdfViewer = viewer;
|
|
this.PopulateThumbnailList();
|
|
this.PopulateThumbnailList();
|
|
@@ -1239,17 +1185,12 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
PageEditListBox.ItemsSource = bindPageList;
|
|
PageEditListBox.ItemsSource = bindPageList;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 需要先从文档层添加,再添加UI层,保证显示的页大小准确
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="ItemIndex"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
|
|
+
|
|
public ListBoxItem GetNewItem(int ItemIndex)
|
|
public ListBoxItem GetNewItem(int ItemIndex)
|
|
{
|
|
{
|
|
int thumbnailWidth = thumbnailSize[zoomLevel];
|
|
int thumbnailWidth = thumbnailSize[zoomLevel];
|
|
Size pageSize = pdfViewer.Document.GetPageSize(ItemIndex);
|
|
Size pageSize = pdfViewer.Document.GetPageSize(ItemIndex);
|
|
- if (pageSize.Width == 0 || pageSize.Height == 0)// 全选替换时,手动设定页码大小
|
|
|
|
|
|
+ if (pageSize.Width == 0 || pageSize.Height == 0)
|
|
{
|
|
{
|
|
pageSize = new Size(228, 300);
|
|
pageSize = new Size(228, 300);
|
|
}
|
|
}
|
|
@@ -1257,9 +1198,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
int imageHeight = pageSize.Height > pageSize.Width ? thumbnailWidth * 2 : (int)(pageSize.Height / pageSize.Width * thumbnailWidth * 2);
|
|
int imageHeight = pageSize.Height > pageSize.Width ? thumbnailWidth * 2 : (int)(pageSize.Height / pageSize.Width * thumbnailWidth * 2);
|
|
|
|
|
|
Image img = new Image()
|
|
Image img = new Image()
|
|
- {
|
|
|
|
- // Margin = new Thickness(0, 0, 5, 0),
|
|
|
|
-
|
|
|
|
|
|
+ {
|
|
Width = imageWidth,
|
|
Width = imageWidth,
|
|
Height = imageHeight,
|
|
Height = imageHeight,
|
|
Stretch = Stretch.Uniform,
|
|
Stretch = Stretch.Uniform,
|
|
@@ -1319,8 +1258,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
item.Margin = new Thickness(6, 10, 6, 10);
|
|
item.Margin = new Thickness(6, 10, 6, 10);
|
|
return item;
|
|
return item;
|
|
}
|
|
}
|
|
-
|
|
|
|
- //UI层 在指定位置插入一定数量的空白页 在文档操作之后
|
|
|
|
|
|
+
|
|
public void AddBlankPages(int pagecount, int insertindex)
|
|
public void AddBlankPages(int pagecount, int insertindex)
|
|
{
|
|
{
|
|
for (int i = 0; i < pagecount; i++)
|
|
for (int i = 0; i < pagecount; i++)
|
|
@@ -1328,15 +1266,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
var item = GetNewItem(insertindex + i);
|
|
var item = GetNewItem(insertindex + i);
|
|
bindPageList.Insert(insertindex + i, item);
|
|
bindPageList.Insert(insertindex + i, item);
|
|
if (visiblePageIndexes.Contains(insertindex + i))
|
|
if (visiblePageIndexes.Contains(insertindex + i))
|
|
- visiblePageIndexes.Remove(insertindex + i);//如果不删除,则不会显示图片
|
|
|
|
|
|
+ visiblePageIndexes.Remove(insertindex + i);
|
|
}
|
|
}
|
|
PageEditListBox.UpdateLayout();
|
|
PageEditListBox.UpdateLayout();
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 刷新指定页面的UI
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="pageindex"></param>
|
|
|
|
|
|
+
|
|
private async void RenderPage(int pageindex)
|
|
private async void RenderPage(int pageindex)
|
|
{
|
|
{
|
|
var range = GetRoughViewportRange(PageEditListBox, (PageEditListBox.Items[0] as ListBoxItem).DesiredSize, new Thickness(6, 10, 6, 10));
|
|
var range = GetRoughViewportRange(PageEditListBox, (PageEditListBox.Items[0] as ListBoxItem).DesiredSize, new Thickness(6, 10, 6, 10));
|
|
@@ -1360,25 +1294,17 @@ namespace Compdfkit_Tools.PDFControl
|
|
if (VisualTreeHelper.GetParent(this) == null)
|
|
if (VisualTreeHelper.GetParent(this) == null)
|
|
return;
|
|
return;
|
|
|
|
|
|
- //List<int> pagesOnScreen = new List<int>();
|
|
|
|
- //pageThumbnailsToRequest.Clear();
|
|
|
|
-
|
|
|
|
var range = GetRoughViewportRange(PageEditListBox, (PageEditListBox.Items[0] as ListBoxItem).DesiredSize, new Thickness(6, 10, 6, 10));
|
|
var range = GetRoughViewportRange(PageEditListBox, (PageEditListBox.Items[0] as ListBoxItem).DesiredSize, new Thickness(6, 10, 6, 10));
|
|
for (int i = 0; i < PageEditListBox.Items.Count; ++i)
|
|
for (int i = 0; i < PageEditListBox.Items.Count; ++i)
|
|
- {
|
|
|
|
- //if (i>=pdfViewer.Document.PageCount)
|
|
|
|
- //{
|
|
|
|
- // break;
|
|
|
|
- //}
|
|
|
|
- ListBoxItem item = PageEditListBox.Items[i] as ListBoxItem;
|
|
|
|
- // ListBoxItem listboxitem = PageEditListBox.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
|
|
|
|
|
|
+ {
|
|
|
|
+ ListBoxItem item = PageEditListBox.Items[i] as ListBoxItem;
|
|
Image img = GetImageElement(item);
|
|
Image img = GetImageElement(item);
|
|
- if (i >= (range.Item1 - 1) && i <= range.Item2 || ViewportHelper.IsInViewport(sv, item))//更改判断方式 因为BOTA缩略图不准确
|
|
|
|
|
|
+ if (i >= (range.Item1 - 1) && i <= range.Item2 || ViewportHelper.IsInViewport(sv, item))
|
|
{
|
|
{
|
|
if (img.Source == null && !visiblePageIndexes.Contains(i))
|
|
if (img.Source == null && !visiblePageIndexes.Contains(i))
|
|
{
|
|
{
|
|
visiblePageIndexes.Add(i);
|
|
visiblePageIndexes.Add(i);
|
|
- await Task.Delay(1);//有刷不出图的情况 增减页面时
|
|
|
|
|
|
+ await Task.Delay(1);
|
|
await pdfViewer.GetThumbnail(i, (int)img.Width, (int)img.Height);
|
|
await pdfViewer.GetThumbnail(i, (int)img.Width, (int)img.Height);
|
|
Debug.WriteLine("Page {0} is visible, asking for thumb", (i + 1));
|
|
Debug.WriteLine("Page {0} is visible, asking for thumb", (i + 1));
|
|
}
|
|
}
|
|
@@ -1395,8 +1321,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
Image image = GetImageElement(PageEditListBox.Items[i] as ListBoxItem);
|
|
Image image = GetImageElement(PageEditListBox.Items[i] as ListBoxItem);
|
|
if (image.Source != null)
|
|
if (image.Source != null)
|
|
{
|
|
{
|
|
- image.Source = null;
|
|
|
|
- //(image.Parent as Border).BorderBrush = Brushes.Transparent;
|
|
|
|
|
|
+ image.Source = null;
|
|
Debug.WriteLine("Page {0} is out of range, removed thumb", (i + 1));
|
|
Debug.WriteLine("Page {0} is out of range, removed thumb", (i + 1));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1495,8 +1420,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
- //拖拽排序的主体方法
|
|
|
|
|
|
+
|
|
private void DragToSort(int sourceindex, int targetindex)
|
|
private void DragToSort(int sourceindex, int targetindex)
|
|
{
|
|
{
|
|
if (targetindex == sourceindex || targetindex < 0)
|
|
if (targetindex == sourceindex || targetindex < 0)
|
|
@@ -1526,12 +1450,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
this.PageMoved.Invoke(this, new RoutedEventArgs());
|
|
this.PageMoved.Invoke(this, new RoutedEventArgs());
|
|
UpdateSortedPageNum(sourceindex, targetindex);
|
|
UpdateSortedPageNum(sourceindex, targetindex);
|
|
}
|
|
}
|
|
-
|
|
|
|
- //更新排序后的页码 适用于总页数不变的情况
|
|
|
|
|
|
+
|
|
private void UpdateSortedPageNum(int sourceIndex, int targetIndex)
|
|
private void UpdateSortedPageNum(int sourceIndex, int targetIndex)
|
|
{
|
|
{
|
|
int sum = sourceIndex + targetIndex;
|
|
int sum = sourceIndex + targetIndex;
|
|
- targetIndex = targetIndex > sourceIndex ? targetIndex : sourceIndex;//保证targetindex为较大值
|
|
|
|
|
|
+ targetIndex = targetIndex > sourceIndex ? targetIndex : sourceIndex;
|
|
sourceIndex = sum - targetIndex;
|
|
sourceIndex = sum - targetIndex;
|
|
sourceIndex = sourceIndex <= 0 ? 0 : sourceIndex;
|
|
sourceIndex = sourceIndex <= 0 ? 0 : sourceIndex;
|
|
targetIndex = targetIndex + 1 > PageEditListBox.Items.Count ? PageEditListBox.Items.Count - 1 : targetIndex;
|
|
targetIndex = targetIndex + 1 > PageEditListBox.Items.Count ? PageEditListBox.Items.Count - 1 : targetIndex;
|
|
@@ -1543,10 +1466,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pagenum.Text = (i + 1).ToString();
|
|
pagenum.Text = (i + 1).ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 适用于页总数发生改变的页码更新
|
|
|
|
- /// </summary>
|
|
|
|
|
|
+
|
|
private void UpdateAllPageNum()
|
|
private void UpdateAllPageNum()
|
|
{
|
|
{
|
|
for (int i = 0; i < PageEditListBox.Items.Count; i++)
|
|
for (int i = 0; i < PageEditListBox.Items.Count; i++)
|
|
@@ -1586,7 +1506,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
pdfViewer.ReloadDocument();
|
|
pdfViewer.ReloadDocument();
|
|
PageEditListBox.ScrollIntoView(PageEditListBox.SelectedItem as ListBoxItem);
|
|
PageEditListBox.ScrollIntoView(PageEditListBox.SelectedItem as ListBoxItem);
|
|
- ItemsInViewHitTest();//刷新图片
|
|
|
|
|
|
+ ItemsInViewHitTest();
|
|
}
|
|
}
|
|
|
|
|
|
public void DoReplace()
|
|
public void DoReplace()
|
|
@@ -1601,10 +1521,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
dialog.Multiselect = false;
|
|
dialog.Multiselect = false;
|
|
dialog.Filter = "(*.pdf)|*.pdf";
|
|
dialog.Filter = "(*.pdf)|*.pdf";
|
|
if ((bool)dialog.ShowDialog())
|
|
if ((bool)dialog.ShowDialog())
|
|
- {
|
|
|
|
- //用选择的整个文件替换选中页
|
|
|
|
- CPDFDocument doc = CPDFDocument.InitWithFilePath(dialog.FileName);
|
|
|
|
- //文件页数
|
|
|
|
|
|
+ {
|
|
|
|
+ CPDFDocument doc = CPDFDocument.InitWithFilePath(dialog.FileName);
|
|
int pagecount = doc.PageCount;
|
|
int pagecount = doc.PageCount;
|
|
|
|
|
|
int insertindex = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItem);
|
|
int insertindex = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItem);
|
|
@@ -1612,17 +1530,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
insertindex = 0;
|
|
insertindex = 0;
|
|
|
|
|
|
var result = pdfViewer.Document.ImportPagesAtIndex(doc, "1-" + pagecount, insertindex);
|
|
var result = pdfViewer.Document.ImportPagesAtIndex(doc, "1-" + pagecount, insertindex);
|
|
- doc.Release();
|
|
|
|
- //UI层插入
|
|
|
|
|
|
+ doc.Release();
|
|
for (int i = 0; i < pagecount; i++)
|
|
for (int i = 0; i < pagecount; i++)
|
|
{
|
|
{
|
|
var item = GetNewItem(insertindex + i);
|
|
var item = GetNewItem(insertindex + i);
|
|
bindPageList.Insert(insertindex + i, item);
|
|
bindPageList.Insert(insertindex + i, item);
|
|
if (visiblePageIndexes.Contains(insertindex + i))
|
|
if (visiblePageIndexes.Contains(insertindex + i))
|
|
- visiblePageIndexes.Remove(insertindex + i);//要求重新刷新图片
|
|
|
|
|
|
+ visiblePageIndexes.Remove(insertindex + i);
|
|
}
|
|
}
|
|
-
|
|
|
|
- // RefreshThumbnail();
|
|
|
|
|
|
+
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
|
|
|
|
@@ -1636,9 +1552,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DoDelete(list, false);
|
|
DoDelete(list, false);
|
|
- UpdateAllPageNum();//更新页码
|
|
|
|
|
|
+ UpdateAllPageNum();
|
|
RefreshBookMarkList();
|
|
RefreshBookMarkList();
|
|
- ItemsInViewHitTest();//刷新图片
|
|
|
|
|
|
+ ItemsInViewHitTest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1663,8 +1579,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
image.LayoutTransform = new RotateTransform(angle, image.ActualWidth / 2, image.ActualHeight / 2);
|
|
image.LayoutTransform = new RotateTransform(angle, image.ActualWidth / 2, image.ActualHeight / 2);
|
|
var index = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[i]);
|
|
var index = PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[i]);
|
|
pdfViewer.Document.RotatePage(index, (int)angleStep / 90);
|
|
pdfViewer.Document.RotatePage(index, (int)angleStep / 90);
|
|
- pdfViewer.Document.ReleasePages(index);
|
|
|
|
- //旋转页面后取消选中
|
|
|
|
|
|
+ pdfViewer.Document.ReleasePages(index);
|
|
pdfViewer.ClearSelectPDFEdit(true);
|
|
pdfViewer.ClearSelectPDFEdit(true);
|
|
|
|
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
@@ -1676,13 +1591,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pdfViewer.ReloadDocument();
|
|
pdfViewer.ReloadDocument();
|
|
ItemsInViewHitTest();
|
|
ItemsInViewHitTest();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 检测文件是否重复 追加尾号
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="path"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
|
|
+
|
|
public static string CreateFilePath(string path)
|
|
public static string CreateFilePath(string path)
|
|
{
|
|
{
|
|
int i = 1;
|
|
int i = 1;
|
|
@@ -1716,20 +1625,19 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
var data = e as ExtractEventClass;
|
|
var data = e as ExtractEventClass;
|
|
int pagecount = pdfViewer.Document.PageCount;
|
|
int pagecount = pdfViewer.Document.PageCount;
|
|
- string pageName = "";
|
|
|
|
- //获取页码范围
|
|
|
|
|
|
+ string pageName = "";
|
|
List<int> pagenums = new List<int>();
|
|
List<int> pagenums = new List<int>();
|
|
pagenums.Clear();
|
|
pagenums.Clear();
|
|
switch (data.PageMode)
|
|
switch (data.PageMode)
|
|
{
|
|
{
|
|
- case 1://全部页面
|
|
|
|
|
|
+ case 1:
|
|
for (int i = 0; i < pagecount; i++)
|
|
for (int i = 0; i < pagecount; i++)
|
|
{
|
|
{
|
|
pagenums.Add(i + 1);
|
|
pagenums.Add(i + 1);
|
|
}
|
|
}
|
|
pageName = "1-" + pagecount;
|
|
pageName = "1-" + pagecount;
|
|
break;
|
|
break;
|
|
- case 2://奇数页面
|
|
|
|
|
|
+ case 2:
|
|
int count = (pagecount + 1) / 2;
|
|
int count = (pagecount + 1) / 2;
|
|
for (int i = 0; i < count; i++)
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
{
|
|
@@ -1737,8 +1645,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
pageName = "OddPages";
|
|
pageName = "OddPages";
|
|
break;
|
|
break;
|
|
- case 3://偶数页面
|
|
|
|
- if (pagecount == 1)//弹窗时,已经过滤了一次,此处为以防万一。
|
|
|
|
|
|
+ case 3:
|
|
|
|
+ if (pagecount == 1)
|
|
return;
|
|
return;
|
|
count = pagecount / 2;
|
|
count = pagecount / 2;
|
|
for (int i = 0; i < count; i++)
|
|
for (int i = 0; i < count; i++)
|
|
@@ -1747,8 +1655,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
pageName = "EvenPages";
|
|
pageName = "EvenPages";
|
|
break;
|
|
break;
|
|
- case 4://自定义范围
|
|
|
|
- //弹窗已经判断过文本内容是否合理
|
|
|
|
|
|
+ case 4:
|
|
pagenums = data.PageParm;
|
|
pagenums = data.PageParm;
|
|
pageName = data.PageName;
|
|
pageName = data.PageName;
|
|
break;
|
|
break;
|
|
@@ -1765,10 +1672,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- return;
|
|
|
|
- //要显示文件路径
|
|
|
|
- string selectedfile = "";
|
|
|
|
- //根据是否单页生成文件 处理
|
|
|
|
|
|
+ return;
|
|
|
|
+ string selectedfile = "";
|
|
if (data.ExtractToSingleFile)
|
|
if (data.ExtractToSingleFile)
|
|
{
|
|
{
|
|
for (int i = 0; i < pagenums.Count; i++)
|
|
for (int i = 0; i < pagenums.Count; i++)
|
|
@@ -1780,8 +1685,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
CPDFDocument savedoc = CPDFDocument.CreateDocument();
|
|
CPDFDocument savedoc = CPDFDocument.CreateDocument();
|
|
bool result = savedoc.ImportPages(pdfViewer.Document, (pagenums[i]).ToString());
|
|
bool result = savedoc.ImportPages(pdfViewer.Document, (pagenums[i]).ToString());
|
|
if (!result)
|
|
if (!result)
|
|
- {
|
|
|
|
- //SetReadModeTip(true, "提取异常,请稍后重试", false);
|
|
|
|
|
|
+ {
|
|
savedoc.Release();
|
|
savedoc.Release();
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -1789,14 +1693,12 @@ namespace Compdfkit_Tools.PDFControl
|
|
if (!result)
|
|
if (!result)
|
|
{
|
|
{
|
|
savedoc.Release();
|
|
savedoc.Release();
|
|
- continue;
|
|
|
|
- //File.Delete(path);
|
|
|
|
- // SetReadModeTip(true, "保存异常,请稍后重试", false);
|
|
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- savedoc.Release();//释放内存
|
|
|
|
|
|
+ savedoc.Release();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else//全部生成一个文件
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
string filename = pdfViewer.Document.FileName + " " + pageName + ".pdf";
|
|
string filename = pdfViewer.Document.FileName + " " + pageName + ".pdf";
|
|
string path = System.IO.Path.Combine(dialog.SelectedPath, filename);
|
|
string path = System.IO.Path.Combine(dialog.SelectedPath, filename);
|
|
@@ -1807,19 +1709,16 @@ namespace Compdfkit_Tools.PDFControl
|
|
bool result = savedoc.ImportPages(pdfViewer.Document, range);
|
|
bool result = savedoc.ImportPages(pdfViewer.Document, range);
|
|
if (!result)
|
|
if (!result)
|
|
{
|
|
{
|
|
- return;
|
|
|
|
- // File.Delete(path);
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
result = savedoc.WriteToFilePath(path);
|
|
result = savedoc.WriteToFilePath(path);
|
|
if (!result)
|
|
if (!result)
|
|
- {
|
|
|
|
- //File.Delete(path);
|
|
|
|
- }
|
|
|
|
- //IsModefied = true;
|
|
|
|
- savedoc.Release();//释放内存
|
|
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ savedoc.Release();
|
|
}
|
|
}
|
|
|
|
|
|
- if (data.DeleteAfterExtract)//提取后删除
|
|
|
|
|
|
+ if (data.DeleteAfterExtract)
|
|
{
|
|
{
|
|
List<ListBoxItem> items = new List<ListBoxItem>();
|
|
List<ListBoxItem> items = new List<ListBoxItem>();
|
|
for (int i = 0; i < pagenums.Count; i++)
|
|
for (int i = 0; i < pagenums.Count; i++)
|
|
@@ -1844,8 +1743,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- int insertIndex = 0;
|
|
|
|
- //粘贴在所有选中项末尾
|
|
|
|
|
|
+ int insertIndex = 0;
|
|
for (int k = 0; k < PageEditListBox.SelectedItems.Count; k++)
|
|
for (int k = 0; k < PageEditListBox.SelectedItems.Count; k++)
|
|
{
|
|
{
|
|
if (insertIndex < PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[k] as ListBoxItem))
|
|
if (insertIndex < PageEditListBox.Items.IndexOf(PageEditListBox.SelectedItems[k] as ListBoxItem))
|
|
@@ -1912,8 +1810,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
for (int i = 0; i < pages.Count; i++)
|
|
for (int i = 0; i < pages.Count; i++)
|
|
{
|
|
{
|
|
int preindex = pages[i];
|
|
int preindex = pages[i];
|
|
- int laterIndex = pages[pages.Count - i - 1];//尾部的索引
|
|
|
|
- if (laterIndex <= preindex)//交换完成
|
|
|
|
|
|
+ int laterIndex = pages[pages.Count - i - 1];
|
|
|
|
+ if (laterIndex <= preindex)
|
|
return;
|
|
return;
|
|
var sourceitem = PageEditListBox.Items[preindex] as ListBoxItem;
|
|
var sourceitem = PageEditListBox.Items[preindex] as ListBoxItem;
|
|
var targetitem = PageEditListBox.Items[laterIndex] as ListBoxItem;
|
|
var targetitem = PageEditListBox.Items[laterIndex] as ListBoxItem;
|
|
@@ -1931,11 +1829,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
PageEditListBox.SelectedItems.Add(sourceitem);
|
|
PageEditListBox.SelectedItems.Add(sourceitem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 删除选中页面 bool 设置删除前是否弹窗提示
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="tip">是否弹窗提示</param>
|
|
|
|
|
|
+
|
|
private void DoDelete(List<ListBoxItem> pageLists, bool tip)
|
|
private void DoDelete(List<ListBoxItem> pageLists, bool tip)
|
|
{
|
|
{
|
|
if (pageLists.Count == 0)
|
|
if (pageLists.Count == 0)
|
|
@@ -1959,7 +1853,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
for (int i = 0; i < pageLists.Count; i++)
|
|
for (int i = 0; i < pageLists.Count; i++)
|
|
{
|
|
{
|
|
var index = PageEditListBox.Items.IndexOf(pageLists[i]);
|
|
var index = PageEditListBox.Items.IndexOf(pageLists[i]);
|
|
- pages.Add(index);//存入页的index
|
|
|
|
|
|
+ pages.Add(index);
|
|
}
|
|
}
|
|
pages.Sort();
|
|
pages.Sort();
|
|
|
|
|
|
@@ -1967,8 +1861,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
for (int i = pages.Count - 1; i >= 0; i--)
|
|
for (int i = pages.Count - 1; i >= 0; i--)
|
|
{
|
|
{
|
|
bindPageList.RemoveAt(pages[i]);
|
|
bindPageList.RemoveAt(pages[i]);
|
|
- }
|
|
|
|
- //文档层操
|
|
|
|
|
|
+ }
|
|
var r = pdfViewer.Document.RemovePages(pages.ToArray());
|
|
var r = pdfViewer.Document.RemovePages(pages.ToArray());
|
|
if (!r)
|
|
if (!r)
|
|
{
|
|
{
|
|
@@ -1978,9 +1871,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
pdfViewer.UndoManager.ClearHistory();
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
pdfViewer.UndoManager.CanSave = true;
|
|
|
|
|
|
- UpdateAllPageNum();
|
|
|
|
- //需要刷新 不然最后一页会出现白板
|
|
|
|
- // ItemsInViewHitTest();
|
|
|
|
|
|
+ UpdateAllPageNum();
|
|
pdfViewer.ReloadDocument();
|
|
pdfViewer.ReloadDocument();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1994,20 +1885,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
return itemlists;
|
|
return itemlists;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 校验PageRange 输入是否合法,且可返回List<int> Pages 存放的索引值
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="pageList">返回的页面集合</param>
|
|
|
|
- /// <param name="pageRange">需要判断的文本</param>
|
|
|
|
- /// <param name="count">页面总数</param>
|
|
|
|
- /// <param name="enumerationSeparator">例 new char[] { ',' }</param>
|
|
|
|
- /// <param name="rangeSeparator">例 new char[] { '-' }</param>
|
|
|
|
- /// <param name="inittag"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
|
|
+
|
|
public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
|
|
public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
|
|
{
|
|
{
|
|
- string[] rangeSplit = pageRange.Split(enumerationSeparator);//根据分隔符 拆分字符串
|
|
|
|
|
|
+ string[] rangeSplit = pageRange.Split(enumerationSeparator);
|
|
|
|
|
|
pageList.Clear();
|
|
pageList.Clear();
|
|
|
|
|
|
@@ -2018,19 +1899,18 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
starttag = 0;
|
|
starttag = 0;
|
|
}
|
|
}
|
|
- if (range.Contains("-"))//连续页
|
|
|
|
|
|
+ if (range.Contains("-"))
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- string[] limits = range.Split(rangeSeparator);//对子字符串再根据”-“ 拆分
|
|
|
|
|
|
+ string[] limits = range.Split(rangeSeparator);
|
|
if (limits.Length >= 2 && !string.IsNullOrWhiteSpace(limits[0]) && !string.IsNullOrWhiteSpace(limits[1]))
|
|
if (limits.Length >= 2 && !string.IsNullOrWhiteSpace(limits[0]) && !string.IsNullOrWhiteSpace(limits[1]))
|
|
{
|
|
{
|
|
int start = int.Parse(limits[0]);
|
|
int start = int.Parse(limits[0]);
|
|
int end = int.Parse(limits[1]);
|
|
int end = int.Parse(limits[1]);
|
|
|
|
|
|
if ((start < starttag) || (end > count) || (start > end))
|
|
if ((start < starttag) || (end > count) || (start > end))
|
|
- {
|
|
|
|
- //throw new Exception(string.Format("Invalid page(s) in range {0} - {1}", start, end));
|
|
|
|
|
|
+ {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2053,36 +1933,26 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
int pageNr;
|
|
int pageNr;
|
|
try
|
|
try
|
|
- {
|
|
|
|
- // Single page
|
|
|
|
- pageNr = int.Parse(range);//单页
|
|
|
|
|
|
+ {
|
|
|
|
+ pageNr = int.Parse(range);
|
|
}
|
|
}
|
|
- catch (Exception)//格式不正确时
|
|
|
|
|
|
+ catch (Exception)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
if (pageNr < starttag || pageNr > count)
|
|
if (pageNr < starttag || pageNr > count)
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- //throw new Exception(string.Format("Invalid page {0}", pageNr));
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
if (pageList.Contains(pageNr))
|
|
if (pageList.Contains(pageNr))
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
- // throw new Exception(string.Format("Invalid page {0}", pageNr));
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
pageList.Add(pageNr - 1);
|
|
pageList.Add(pageNr - 1);
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 从其他pdf插入页面
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="filepath">文件路径</param>
|
|
|
|
- /// <param name="pagerange">页码范围</param>
|
|
|
|
- /// <param name="insertindex">插入位置</param>
|
|
|
|
|
|
+
|
|
private void DoAddFromOtherPdf(string filepath, string pagerange, int insertindex, string password)
|
|
private void DoAddFromOtherPdf(string filepath, string pagerange, int insertindex, string password)
|
|
{
|
|
{
|
|
CPDFDocument doc = CPDFDocument.InitWithFilePath(filepath);
|
|
CPDFDocument doc = CPDFDocument.InitWithFilePath(filepath);
|
|
@@ -2134,15 +2004,13 @@ namespace Compdfkit_Tools.PDFControl
|
|
GetPagesInRange(ref page, pagerange, doc.PageCount, new char[] { ',' }, new char[] { '-' });
|
|
GetPagesInRange(ref page, pagerange, doc.PageCount, new char[] { ',' }, new char[] { '-' });
|
|
insertRange = pagerange;
|
|
insertRange = pagerange;
|
|
pagecount = page.Count;
|
|
pagecount = page.Count;
|
|
- }
|
|
|
|
- //先文档操作,再更新UI
|
|
|
|
|
|
+ }
|
|
var result = pdfViewer.Document.ImportPagesAtIndex(doc, insertRange, insertindex);
|
|
var result = pdfViewer.Document.ImportPagesAtIndex(doc, insertRange, insertindex);
|
|
if (!result)
|
|
if (!result)
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- doc.Release();
|
|
|
|
- //刷新UI
|
|
|
|
|
|
+ doc.Release();
|
|
RefreshThumbnail();
|
|
RefreshThumbnail();
|
|
PageEditListBox.SelectedItems.Clear();
|
|
PageEditListBox.SelectedItems.Clear();
|
|
for (int i = insertindex; i < insertindex + pagecount; i++)
|
|
for (int i = insertindex; i < insertindex + pagecount; i++)
|
|
@@ -2168,7 +2036,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
if (pagesList.Count != 0)
|
|
if (pagesList.Count != 0)
|
|
{
|
|
{
|
|
- pagesList.Sort();//先对页码排序
|
|
|
|
|
|
+ pagesList.Sort();
|
|
|
|
|
|
for (int i = 0; i < pagesList.Count; i++)
|
|
for (int i = 0; i < pagesList.Count; i++)
|
|
{
|
|
{
|
|
@@ -2178,7 +2046,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (pagesList[i] == pagesList[i - 1] + 1)//页码连续
|
|
|
|
|
|
+ if (pagesList[i] == pagesList[i - 1] + 1)
|
|
{
|
|
{
|
|
if (i >= 2)
|
|
if (i >= 2)
|
|
{
|
|
{
|
|
@@ -2193,7 +2061,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pageParam += pagesList[i].ToString();
|
|
pageParam += pagesList[i].ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else//页码不连续时
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
if (i >= 2)
|
|
if (i >= 2)
|
|
{
|
|
{
|
|
@@ -2207,12 +2075,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
return pageParam;
|
|
return pageParam;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 返回指定路径的图标
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="path"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
|
|
+
|
|
public static BitmapSource ToBitmapSource(string path)
|
|
public static BitmapSource ToBitmapSource(string path)
|
|
{
|
|
{
|
|
System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(path);
|
|
System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(path);
|
|
@@ -2228,8 +2091,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
return returnSource;
|
|
return returnSource;
|
|
}
|
|
}
|
|
-
|
|
|
|
- //返回当前视图中的item 范围
|
|
|
|
|
|
+
|
|
private Tuple<int, int, int> GetRoughViewportRange(ListBox view, Size itemSize, Thickness itemMargin)
|
|
private Tuple<int, int, int> GetRoughViewportRange(ListBox view, Size itemSize, Thickness itemMargin)
|
|
{
|
|
{
|
|
var scrollViewer = GetScrollHost(view);
|
|
var scrollViewer = GetScrollHost(view);
|
|
@@ -2238,8 +2100,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
try
|
|
try
|
|
{
|
|
{
|
|
var currentHeight = scrollViewer.ActualHeight - view.Padding.Top;
|
|
var currentHeight = scrollViewer.ActualHeight - view.Padding.Top;
|
|
- var currentWidth = scrollViewer.ActualWidth;
|
|
|
|
- //计算当前窗口大小能显示的行数和列数
|
|
|
|
|
|
+ var currentWidth = scrollViewer.ActualWidth;
|
|
var columnCount = (int)(currentWidth / (itemSize.Width + itemMargin.Left));
|
|
var columnCount = (int)(currentWidth / (itemSize.Width + itemMargin.Left));
|
|
var rowCount = (int)Math.Ceiling(currentHeight / (itemSize.Height + itemMargin.Bottom));
|
|
var rowCount = (int)Math.Ceiling(currentHeight / (itemSize.Height + itemMargin.Bottom));
|
|
|
|
|