|
@@ -22,6 +22,7 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
{
|
|
|
class OutLineControlViewModel : BindableBase, INavigationAware
|
|
|
{
|
|
|
+ private string PageDefaultName = "";
|
|
|
//缩略图相关全局变量,减少内存申请次数
|
|
|
private WriteableBitmap WirteBitmap;
|
|
|
private byte[] bmpData;
|
|
@@ -146,13 +147,13 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
return;
|
|
|
}
|
|
|
CPDFAction action = outline.Outline.GetAction();
|
|
|
- //if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
|
|
|
- // PDFViewer.ProcessAction(action);
|
|
|
- //else
|
|
|
- //{
|
|
|
+ if (action != null && action.ActionType != C_ACTION_TYPE.ACTION_TYPE_UNKNOWN)
|
|
|
+ PDFViewer.ProcessAction(action);
|
|
|
+ else
|
|
|
+ {
|
|
|
Size size = PDFViewer.Document.GetPageSize(Convert.ToInt32(outline.PageIndex) - 1);
|
|
|
PDFViewer.GoToPage(Convert.ToInt32(outline.PageIndex) - 1, new Point(size.Width - outline.PositionX, size.Height - outline.PositionY));
|
|
|
- //}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -194,38 +195,91 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
CPDFDestination info = new CPDFDestination();
|
|
|
info.PageIndex = textSelectNodes[0].PageIndex;
|
|
|
Size size = PDFViewer.Document.GetPageSize(textSelectNodes[0].PageIndex);
|
|
|
- info.Position_X = (float)(size.Width-textSelectNodes[0].StartPoint.X);
|
|
|
- info.Position_Y = (float)(size.Height-textSelectNodes[0].StartPoint.Y);
|
|
|
+ info.Position_X = (float)(size.Width - textSelectNodes[0].StartPoint.X);
|
|
|
+ info.Position_Y = (float)(size.Height - textSelectNodes[0].StartPoint.Y);
|
|
|
outline.Outline.SetDestination(PDFViewer.Document, info);
|
|
|
- PDFViewer.Document.ReleaseOutlineList();
|
|
|
Updata(false);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 添加大纲
|
|
|
/// </summary>
|
|
|
- public void AddOutLine()
|
|
|
+ public int AddOutLine(OutlineNode outline)
|
|
|
{
|
|
|
+ int ItemIndex = 0;
|
|
|
List<TextSelectNode> textSelectNodes = PDFViewer.GetCreateOutLineInfo();
|
|
|
CPDFDestination info = new CPDFDestination();
|
|
|
+ if (textSelectNodes.Count <= 0)
|
|
|
+ {
|
|
|
+ //SDK出错了
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
info.PageIndex = textSelectNodes[0].PageIndex;
|
|
|
info.Position_X = (float)textSelectNodes[0].StartPoint.X;
|
|
|
info.Position_Y = (float)textSelectNodes[0].StartPoint.Y;
|
|
|
CPDFOutline dto = null;
|
|
|
+ //当前有选中大纲列表
|
|
|
+ if (outline != null)
|
|
|
+ {
|
|
|
+ CPDFOutline parentoutline = outline.Outline.GetParent();
|
|
|
+ if (parentoutline == null)
|
|
|
+ {
|
|
|
+ //获取父级失败,直接添加在根节点最下方
|
|
|
+ PDFViewer.Document.GetOutlineList();
|
|
|
+ CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
|
|
|
+ if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
|
|
|
+ {
|
|
|
+ //SDK出错了
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ ItemIndex = parent.ChildList.Count;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //获取父节点成功,添加在父节点中选中项下方
|
|
|
+ int index = GetOutlinesIndexFormParent(parentoutline, outline.Outline);
|
|
|
+ parentoutline.InsertChildAtIndex(PDFViewer.Document, index, ref dto);
|
|
|
+ ItemIndex = index + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //未选中数据,直接添加在根节点最下方
|
|
|
+ PDFViewer.Document.GetOutlineList();
|
|
|
+ CPDFOutline parent = PDFViewer.Document.GetOutlineRoot();
|
|
|
+ if (!parent.InsertChildAtIndex(PDFViewer.Document, parent.ChildList.Count, ref dto))
|
|
|
+ {
|
|
|
+ //SDK出错了
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ ItemIndex = parent.ChildList.Count;
|
|
|
+ }
|
|
|
+ ///当前没有选中文字
|
|
|
if (string.IsNullOrEmpty(textSelectNodes[0].SelectText))
|
|
|
{
|
|
|
- dto.SetTitle(textSelectNodes[0].PageIndex.ToString());
|
|
|
+ string addPageName = PageDefaultName + (textSelectNodes[0].PageIndex + 1).ToString();
|
|
|
+ if (!dto.SetTitle(addPageName))
|
|
|
+ {
|
|
|
+ //SDK出错了
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dto.SetTitle(textSelectNodes[0].SelectText);
|
|
|
+ string addPageName = PageDefaultName + textSelectNodes[0].SelectText;
|
|
|
+ if (!dto.SetTitle(addPageName))
|
|
|
+ {
|
|
|
+ //SDK出错了
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
dto.SetDestination(PDFViewer.Document, info);
|
|
|
- PDFViewer.Document.ReleaseOutlineList();
|
|
|
Updata(false);
|
|
|
+ return ItemIndex;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 删除所有大纲
|
|
|
/// </summary>
|
|
@@ -496,6 +550,42 @@ namespace PDF_Office.ViewModels.BOTA
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 从当前列表中找到对应的OutlineNode对象
|
|
|
+ /// </summary>
|
|
|
+ public OutlineNode FindOutlineFromList(ObservableCollection<OutlineNode> list, OutlineNode outline, int outlineindex)
|
|
|
+ {
|
|
|
+ //如果传入比对数据为null,则返回最后一项
|
|
|
+ if (outline == null)
|
|
|
+ {
|
|
|
+ return list.Last();
|
|
|
+ }
|
|
|
+ int index = list.IndexOf(outline);
|
|
|
+ if (index >= 0)
|
|
|
+ {
|
|
|
+ if (outlineindex <= index)
|
|
|
+ {
|
|
|
+ return list[index];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return list[outlineindex - 1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ OutlineNode node = FindOutlineFromList(item.Chlidlist, outline, outlineindex);
|
|
|
+ if (node != null)
|
|
|
+ {
|
|
|
+ return node;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private int GetIndexFromParent(List<CPDFOutline> parentlist, CPDFOutline outline)
|
|
|
{
|
|
|
for (int i = 0; i < parentlist.Count; i++)
|