123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using ComPDFKit.PDFDocument;
- using compdfkit_tools;
- using compdfkit_tools.PDFControl;
- using compdfkit_tools.PDFControl;
- using compdfkit_tools.PDFControlUI;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Win32;
- 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 viewer_ctrl_demo
- {
-
-
-
- public partial class MainWindow : Window
- {
- public CPDFViewer pdfViewer;
- public MainWindow()
- {
- InitializeComponent();
- TitleBarControl.Loaded += TitleBarControl_Loaded;
- LoadDefaultDocument();
- }
- private void LoadDocument()
- {
- pdfViewer.Load();
- PDFGrid.Child = pdfViewer;
- CPDFScalingControl.InitWithPDFViewer(pdfViewer);
- CPDFPageTurningControl.InitWithPDFViewer(pdfViewer);
- CPDFBrowseModeControl.InitWithPDFViewer(pdfViewer);
- CPDFColorModeControl.InitWithPDFViewer(pdfViewer);
- UIElement currentBotaTool = GetBotaTool();
- if (currentBotaTool is CPDFSearchControl)
- {
- ((CPDFSearchControl)currentBotaTool).SetPDFView(pdfViewer);
- }
- if (currentBotaTool is CPDFThumbnailControl)
- {
- ((CPDFThumbnailControl)currentBotaTool).SetPDFView(pdfViewer);
- ((CPDFThumbnailControl)currentBotaTool).ThumbLoaded = false;
- ((CPDFThumbnailControl)currentBotaTool).LoadThumb();
- }
- }
- private void LoadDefaultDocument()
- {
- string defaultFilePath = "..\\..\\..\\..\\developer_guide_windows.pdf";
- pdfViewer = new CPDFViewer();
- pdfViewer.InitDocument(defaultFilePath);
- LoadDocument();
- }
- private void TitleBarControl_Loaded(object sender, RoutedEventArgs e)
- {
- TitleBarControl.OpenFileEvent += TitleBarControl_OpenFileEvent;
- }
- private void TitleBarControl_OpenFileEvent(object sender, CPDFViewer e)
- {
- this.pdfViewer = TitleBarControl.pdfViewer;
- LoadDocument();
- }
- private void LogoButton_Click(object sender, RoutedEventArgs e)
- {
- Button button = sender as Button;
- if (button.ContextMenu.IsOpen)
- {
- button.ContextMenu.IsOpen = false;
- }
- else
- {
- button.ContextMenu.IsOpen = true;
- }
- }
-
-
-
- private void SearchToolButton_Click(object sender, RoutedEventArgs e)
- {
- UIElement botaTool = GetBotaTool();
- if (botaTool == null || !(botaTool is CPDFSearchControl))
- {
- CPDFSearchControl searchControl = new CPDFSearchControl();
- if (pdfViewer != null && pdfViewer.Document != null)
- {
- searchControl.SetPDFView(pdfViewer);
- }
- SetBotaTool(searchControl);
- }
- ExpandTool(SearchToolButton.IsChecked == true);
- ClearToolState(SearchToolButton);
- }
-
-
-
- private void ThumbToolButton_Click(object sender, RoutedEventArgs e)
- {
- UIElement botaTool = GetBotaTool();
- if (botaTool == null || !(botaTool is CPDFThumbnailControl))
- {
- CPDFThumbnailControl thumbControl = new CPDFThumbnailControl();
- if (pdfViewer != null && pdfViewer.Document != null)
- {
- thumbControl.SetPDFView(pdfViewer);
- thumbControl.LoadThumb();
- }
- SetBotaTool(thumbControl);
- }
- ExpandTool(ThumbToolButton.IsChecked == true);
- ClearToolState(ThumbToolButton);
- }
-
-
-
- private void OutlineToolButton_Click(object sender, RoutedEventArgs e)
- {
- UIElement botaTool = GetBotaTool();
- if (botaTool == null||!(botaTool is CPDFOutlineControl))
- {
- CPDFOutlineUI outlineControl = new CPDFOutlineUI();
- if (pdfViewer != null && pdfViewer.Document != null)
- {
- }
- SetBotaTool(outlineControl);
- }
- ExpandTool(OutlineToolButton.IsChecked == true);
- ClearToolState(OutlineToolButton);
- }
-
-
-
-
- private void SetBotaTool(UIElement newChild)
- {
- BotaToolContainer.Child = newChild;
- }
-
-
-
-
- private UIElement GetBotaTool()
- {
- return BotaToolContainer.Child;
- }
-
-
-
-
- private void ExpandTool(bool isExpand)
- {
- BotaToolContainer.Width = isExpand ? 200 : 0;
- BotaToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
- }
-
-
-
- private void ClearToolState(UIElement ignoreTool)
- {
- foreach (UIElement child in BotaSideTool.Children)
- {
- if (child != ignoreTool && child is ToggleButton buttonTool)
- {
- buttonTool.IsChecked = false;
- }
- }
- }
- private void ShowPDFInfoDialog()
- {
- CPDFInfoControl pdfInfoControl = new CPDFInfoControl();
- pdfInfoControl.PDFDocument = pdfViewer.Document;
- Window dialog = new Window
- {
- Title = "PDF Info",
- Content = pdfInfoControl,
- Width = 600,
- Height = 300,
- ResizeMode = ResizeMode.NoResize,
- WindowStartupLocation = WindowStartupLocation.CenterScreen,
- WindowStyle = WindowStyle.ToolWindow,
- Owner = Application.Current.MainWindow
- };
- dialog.ShowDialog();
- }
- private void PDFInfoButton_Click(object sender, RoutedEventArgs e)
- {
- ShowPDFInfoDialog();
- }
- }
- }
|