123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using ComPDFKit.PDFDocument;
- using compdfkit_tools.Annotation.PDFAnnotationControl;
- 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();
- public MainWindow()
- {
- InitializeComponent();
- TitleBarControl.Loaded += TitleBarControl_Loaded;
- AnnotationBarControl.Loaded += AnnotationBarControl_Loaded;
- ModeSelectorBarControl.ShowBOTAEvent += ModrSelectorBarControl_ShowBOTAEvent;
- }
- private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
- {
- AnnotationProperties[] annotationProperties = { AnnotationProperties.Highlight,AnnotationProperties.Underline, AnnotationProperties.Strikeout, AnnotationProperties.Squiggly, AnnotationProperties.Freetext, AnnotationProperties.Note, AnnotationProperties.Sharp, AnnotationProperties.Line, AnnotationProperties.Stamp, AnnotationProperties.Signature, AnnotationProperties.Link, AnnotationProperties.Sound};
- AnnotationBarControl.InitAnnotationBar(annotationProperties);
- AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
- }
- private void AnnotationBarControl_AnnotationPropertyChanged(object sender, string e)
- {
- UIElement propertyPanel = GetPropertyPanel();
- if (propertyPanel == null)
- {
- CPDFAnnotationControl pdfAnnotationControl = new CPDFAnnotationControl();
- pdfAnnotationControl.LoadAnnotationPanel(AnnotationProperties.Highlight);
- SetPropertyPanel(pdfAnnotationControl);
- }
- ExpandPropertyPanel((sender as ToggleButton).IsChecked == true);
- }
- private void ModrSelectorBarControl_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);
- }
- 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;
- }
- 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;
- }
- }
- }
|