using ComPDFKit.PDFDocument;
using compdfkit_tools.Data;
using compdfkit_tools.Helper;
using compdfkit_tools.PDFControl;
using compdfkit_tools.PDFControlUI;
using ComPDFKitViewer;
using ComPDFKitViewer.PdfViewer;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Annotations;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media.Animation;
namespace viewer_ctrl_demo
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
private PDFViewControl passwordViewer;
private PDFViewControl pdfViewControl;
private CPDFAnnotationControl pdfAnnotationControl = null;
private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
pdfAnnotationControl = new CPDFAnnotationControl();
LoadDefaultDocument();
BindZoomLevel();
}
private void BindZoomLevel()
{
foreach (double zoomLevel in zoomLevelList)
{
ComboBoxItem zoomItem = new ComboBoxItem();
zoomItem.Content = zoomLevel + "%";
ZoomComboBox.Items.Add(zoomItem);
}
}
private void LoadDocument()
{
pdfViewControl.PDFView?.Load();
PDFGrid.Child = pdfViewControl;
pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
PasswordUI.Closed += PasswordUI_Closed;
PasswordUI.Canceled += PasswordUI_Canceled;
PasswordUI.Confirmed += PasswordUI_Confirmed;
UIElement currentBotaTool = GetBotaTool();
if (currentBotaTool is CPDFSearchControl)
{
((CPDFSearchControl)currentBotaTool).InitWithPDFViewer(pdfViewControl.PDFView);
}
if (currentBotaTool is CPDFThumbnailControl)
{
((CPDFThumbnailControl)currentBotaTool).InitWithPDFViewer(pdfViewControl.PDFView);
((CPDFThumbnailControl)currentBotaTool).ThumbLoaded = false;
((CPDFThumbnailControl)currentBotaTool).LoadThumb();
}
if (currentBotaTool is CPDFBookmarkControl)
{
((CPDFBookmarkControl)currentBotaTool).InitWithPDFViewer(pdfViewControl.PDFView);
((CPDFBookmarkControl)currentBotaTool).LoadBookmark();
}
ZoomTextBox.Text = string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)) + "%";
InitialPDFViewControl(pdfViewControl);
}
private void PDFView_AnnotCommandHandler(object sender, ComPDFKitViewer.AnnotEvent.AnnotCommandArgs e)
{
switch (e.CommandType)
{
case CommandType.Context:
e.Handle = true;
if (e.CommandTarget == TargetType.Annot)
{
e.Handle = true;
e.PopupMenu = new ContextMenu();
if (e.PressOnLink)
{
e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
MenuItem propertyMenu = new MenuItem();
propertyMenu = new MenuItem();
propertyMenu.Header = "Edit";
WeakEventManager