123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using ComPDFKit.PDFDocument;
- using compdfkit_tools.PDFControlUI;
- using compdfkit_tools.PDFView.PDFOutline.PDFOutlineData;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.PDFControl
- {
- /// <summary>
- /// CPDFOutlineControl.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFOutlineControl : UserControl
- {
- CPDFViewer pdfViewer;
- private CPDFOutline CurrentCPDFOutline { set; get; }
- public ObservableCollection<CPDFOutlineNode> OutlineList
- {
- set; get;
- }
- public CPDFOutlineControl()
- {
- InitializeComponent();
- }
- private int GetIndexFromParent(List<CPDFOutline> parentlist, CPDFOutline outline)
- {
- for (int i = 0; i < parentlist.Count; i++)
- {
- if (parentlist[i] == outline)
- {
- return i;
- }
- }
- return -1;
- }
- public CPDFOutlineNode FindOutlineFromDto(ObservableCollection<CPDFOutlineNode> list, CPDFOutline outline)
- {
- foreach (CPDFOutlineNode item in list)
- {
- CPDFOutline parent = outline.GetParent();
- CPDFOutline PARENT = item.PDFOutline.GetParent();
- item.CurrentNodeName = outline.Title;
- int i = GetIndexFromParent(parent.ChildList, outline);
- int I = GetIndexFromParent(PARENT.ChildList, item.PDFOutline);
- if (item.PDFOutline.Title == outline.Title && i == I && outline.Level == item.PDFOutline.Level && ((parent.Title == PARENT.Title) || (parent.Title == null && PARENT.Title == null)))
- {
- return item;
- }
- else if (item.ChildrenNodeList.Count > 0)
- {
- CPDFOutlineNode retdto = FindOutlineFromDto(item.ChildrenNodeList, outline);
- if (retdto != null)
- {
- return retdto;
- }
- }
- }
- return null;
- }
- private CPDFOutlineNode ConvertCPDFToOutlineNode(CPDFOutline outline, CPDFOutlineNode parent)
- {
- CPDFOutlineNode node = new CPDFOutlineNode();
- if (outline != null)
- {
- node.PDFOutline = outline;
- if (parent != null)
- {
- node.ParentNode = parent;
- }
- if (OutlineList != null && OutlineList.Count > 0)
- {
- CPDFOutlineNode oldnode = FindOutlineFromDto(OutlineList, node.PDFOutline);
- }
- node.ChildrenNodeList = new ObservableCollection<CPDFOutlineNode>();
- if (outline.ChildList.Count > 0)
- {
- foreach (CPDFOutline item in outline.ChildList)
- {
- node.ChildrenNodeList.Add(ConvertCPDFToOutlineNode(item, node));
- }
- }
- }
- return node;
- }
- public ObservableCollection<CPDFOutlineNode> GetOutlineViewDataSource()
- {
- ObservableCollection<CPDFOutlineNode> data = new ObservableCollection<CPDFOutlineNode>();
- List<CPDFOutline> datasource = pdfViewer.Document.GetOutlineList();
- foreach (CPDFOutline item in datasource)
- {
- CPDFOutlineNode dto = ConvertCPDFToOutlineNode(item, null);
- if (dto != null)
- {
- data.Add(dto);
- }
- }
- return data;
- }
- public void InitWithPDFViewer(CPDFViewer pdfViewer)
- {
- this.pdfViewer = pdfViewer;
- List<CPDFOutline> outlineList = pdfViewer.Document.GetOutlineList();
- CPDFOutlineUI.SetOutlineTree(outlineList);
- }
- }
- }
|