|
@@ -1132,7 +1132,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 +1239,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);
|
|
}
|
|
}
|
|
@@ -1318,9 +1313,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
item.Tag = ItemIndex;
|
|
item.Tag = ItemIndex;
|
|
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 +1322,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));
|
|
@@ -1358,27 +1348,19 @@ namespace Compdfkit_Tools.PDFControl
|
|
if (sv == null) return;
|
|
if (sv == null) return;
|
|
|
|
|
|
if (VisualTreeHelper.GetParent(this) == null)
|
|
if (VisualTreeHelper.GetParent(this) == null)
|
|
- return;
|
|
|
|
-
|
|
|
|
- //List<int> pagesOnScreen = new List<int>();
|
|
|
|
- //pageThumbnailsToRequest.Clear();
|
|
|
|
|
|
+ return;
|
|
|
|
|
|
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));
|
|
}
|
|
}
|
|
@@ -1495,8 +1477,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 +1507,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;
|
|
@@ -1542,11 +1522,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
TextBlock pagenum = GetPageNumTextBlock(item);
|
|
TextBlock pagenum = GetPageNumTextBlock(item);
|
|
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 +1563,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 +1578,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,14 +1587,13 @@ 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();
|
|
// RefreshThumbnail();
|
|
@@ -1636,9 +1610,9 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DoDelete(list, false);
|
|
DoDelete(list, false);
|
|
- UpdateAllPageNum();//更新页码
|
|
|
|
|
|
+ UpdateAllPageNum();
|
|
RefreshBookMarkList();
|
|
RefreshBookMarkList();
|
|
- ItemsInViewHitTest();//刷新图片
|
|
|
|
|
|
+ ItemsInViewHitTest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1663,8 +1637,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();
|
|
@@ -1677,12 +1650,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
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 +1684,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 +1704,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 +1714,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 +1731,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 +1744,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 +1752,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 +1768,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 +1802,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 +1869,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 +1888,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 +1912,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 +1920,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 +1930,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 +1944,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 +1958,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 +1992,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 +2063,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 +2095,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 +2105,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 +2120,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
pageParam += pagesList[i].ToString();
|
|
pageParam += pagesList[i].ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else//页码不连续时
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
if (i >= 2)
|
|
if (i >= 2)
|
|
{
|
|
{
|
|
@@ -2207,12 +2134,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 +2150,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 +2159,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));
|
|
|
|
|
|
@@ -2263,12 +2183,10 @@ namespace Compdfkit_Tools.PDFControl
|
|
}
|
|
}
|
|
|
|
|
|
private void ShowAlertWithTimeout(AlertType alertType)
|
|
private void ShowAlertWithTimeout(AlertType alertType)
|
|
- {
|
|
|
|
- // Reset the status of the AlertBorder control.
|
|
|
|
|
|
+ {
|
|
AlertBorder.Visibility = Visibility.Visible;
|
|
AlertBorder.Visibility = Visibility.Visible;
|
|
AlertBorder.Opacity = 1.0;
|
|
AlertBorder.Opacity = 1.0;
|
|
-
|
|
|
|
- // Check the alert type and set the text of the AlertTextBlock control accordingly.
|
|
|
|
|
|
+
|
|
if (alertType == AlertType.EmptyPageAlert)
|
|
if (alertType == AlertType.EmptyPageAlert)
|
|
{
|
|
{
|
|
AlertTextBlock.Text = "Please select at least one page.";
|
|
AlertTextBlock.Text = "Please select at least one page.";
|
|
@@ -2281,13 +2199,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
{
|
|
{
|
|
AlertTextBlock.Text = "Please don't select all pages";
|
|
AlertTextBlock.Text = "Please don't select all pages";
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Animate the opacity of the AlertBorder control to 0.0 over a period of 3 seconds.
|
|
|
|
|
|
+
|
|
DoubleAnimation animation = new DoubleAnimation();
|
|
DoubleAnimation animation = new DoubleAnimation();
|
|
animation.From = 1.0;
|
|
animation.From = 1.0;
|
|
animation.To = 0.0;
|
|
animation.To = 0.0;
|
|
- animation.Duration = TimeSpan.FromSeconds(3);
|
|
|
|
- // Start the animation.
|
|
|
|
|
|
+ animation.Duration = TimeSpan.FromSeconds(3);
|
|
AlertBorder.BeginAnimation(OpacityProperty, animation);
|
|
AlertBorder.BeginAnimation(OpacityProperty, animation);
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
@@ -2300,7 +2216,7 @@ namespace Compdfkit_Tools.PDFControl
|
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
{
|
|
DoSelectItems();
|
|
DoSelectItems();
|
|
- ItemsInViewHitTest();//Scollchange, triggered on the first load, directly refreshes the interface and reduces the whiteboard display time
|
|
|
|
|
|
+ ItemsInViewHitTest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|