123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using ComPDFKit.PDFDocument;
- using compdfkit_tools.Annotation.PDFAnnotationControl;
- using compdfkit_tools.Data;
- using compdfkit_tools.PDFControl;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- 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 annotation_ctrl_demo
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- private CPDFViewer pdfViewer = new CPDFViewer();
- CPDFAnnotationControl pdfAnnotationControl = null;
- public MainWindow()
- {
- InitializeComponent();
- TitleBarControl.Loaded += TitleBarControl_Loaded;
- AnnotationBarControl.Loaded += AnnotationBarControl_Loaded;
- ModeSelectorBarControl.ShowBOTAEvent += ModeSelectorBarControl_ShowBOTAEvent;
- }
- private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
- {
- AnnotationType[] annotationProperties = { AnnotationType.Highlight, AnnotationType.Underline, AnnotationType.Strikeout, AnnotationType.Squiggly, AnnotationType.Freetext, AnnotationType.Note, AnnotationType.Circle, AnnotationType.Square, AnnotationType.Arrow, AnnotationType.Line, AnnotationType.Stamp, AnnotationType.Signature, AnnotationType.Link, AnnotationType.Sound };
- AnnotationBarControl.InitAnnotationBar(annotationProperties);
- AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
- AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
- }
- private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
- {
- pdfAnnotationControl.AnnotationCancel();
- ExpandPropertyPanel((sender as ToggleButton).IsChecked == true);
- }
- /// <summary>
- /// 注释菜单选项变换时
- /// 1、注释属性面板变换,注册属性变换的监听
- /// 2、PDFViewerControl属性设置变换
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AnnotationBarControl_AnnotationPropertyChanged(object sender, AnnotationType e)
- {
- UIElement propertyPanel = GetPropertyPanel();
- pdfAnnotationControl = new CPDFAnnotationControl();
- pdfAnnotationControl.InitWithPDFViewer(pdfViewer);
- pdfAnnotationControl.LoadAnnotationPanel(e);
- SetPropertyPanel(pdfAnnotationControl);
- ExpandPropertyPanel((sender as ToggleButton).IsChecked == true);
- }
- private void ModeSelectorBarControl_ShowBOTAEvent(object sender, EventArgs e)
- {
- UIElement botaTool = GetBotaTool();
- if (botaTool == null)
- {
- CPDFBOTABarControl pdfBOTABarControl = new CPDFBOTABarControl(BOTATools.Outline | BOTATools.Thumbnail | BOTATools.Annotation | BOTATools.Search | BOTATools.Bookmark);
- if (pdfViewer != null && pdfViewer.Document != null)
- {
- pdfBOTABarControl.InitWithPDFViewer(pdfViewer);
- }
- SetBotaTool(pdfBOTABarControl);
- }
- ExpandTool(ModeSelectorBarControl.BOTABarIsShowing == true);
- }
- /// <summary>
- /// 加载文档
- /// </summary>
- private void LoadDocument()
- {
- pdfViewer.Load();
- PDFGrid.Child = pdfViewer;
- UIElement currentBotaTool = GetBotaTool();
- if (currentBotaTool is CPDFBOTABarControl)
- {
- ((CPDFBOTABarControl)currentBotaTool).InitWithPDFViewer(pdfViewer);
- }
- }
- private void TitleBarControl_OpenFileEvent(object sender, string filePath)
- {
- pdfViewer?.CloseDocument();
- pdfViewer?.InitDocument(filePath);
- LoadDocument();
- }
- private void TitleBarControl_Loaded(object sender, RoutedEventArgs e)
- {
- TitleBarControl.OpenFileEvent += TitleBarControl_OpenFileEvent;
- }
- private UIElement GetPropertyPanel()
- {
- return PropertyPanelContainer.Child;
- }
- private UIElement GetBotaTool()
- {
- return BotaToolContainer.Child;
- }
- private void SetPropertyPanel(UIElement propertyPanel)
- {
- PropertyPanelContainer.Child = propertyPanel;
- }
- private void SetBotaTool(UIElement newChild)
- {
- BotaToolContainer.Child = newChild;
- }
- /// <summary>
- /// 展开Property工具
- /// </summary>
- /// <param name="isExpand"></param>
- private void ExpandPropertyPanel(bool isExpand)
- {
- if (isExpand)
- {
- BodyGrid.ColumnDefinitions[4].Width = new GridLength(300);
- }
- else
- {
- BodyGrid.ColumnDefinitions[4].Width = new GridLength(0);
- }
- PropertyPanelContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- PropertyPanelSplitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- }
- /// <summary>
- /// 展开Bota工具
- /// </summary>
- /// <param name="isExpand"></param>
- private void ExpandTool(bool isExpand)
- {
- if (isExpand)
- {
- BodyGrid.ColumnDefinitions[0].Width = new GridLength(300);
- }
- else
- {
- BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
- }
- BotaToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- BotaSplitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- }
- }
- }
|