|
@@ -1,6 +1,11 @@
|
|
|
using ComPDFKit.PDFDocument;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
+using compdfkit_tools.Data;
|
|
|
+using compdfkit_tools.Edit;
|
|
|
using compdfkit_tools.Helper;
|
|
|
using compdfkit_tools.PDFControl;
|
|
|
+using ComPDFKitViewer;
|
|
|
+using ComPDFKitViewer.PdfViewer;
|
|
|
using Microsoft.Win32;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -29,6 +34,11 @@ namespace compdfkit
|
|
|
private PDFViewControl passwordViewer;
|
|
|
private PDFViewControl pdfViewControl = new PDFViewControl();
|
|
|
private CPDFAnnotationControl pdfAnnotationControl = null;
|
|
|
+ private UIElement pdfEditControl = null;
|
|
|
+ /// <summary>
|
|
|
+ /// The last edit object
|
|
|
+ /// </summary>
|
|
|
+ private PDFEditEvent lastPDFEditEvent = null;
|
|
|
|
|
|
private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
|
|
|
|
|
@@ -41,6 +51,7 @@ namespace compdfkit
|
|
|
|
|
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ pdfAnnotationControl = new CPDFAnnotationControl();
|
|
|
LoadDefaultDocument();
|
|
|
BindZoomLevel();
|
|
|
}
|
|
@@ -149,7 +160,7 @@ namespace compdfkit
|
|
|
((CPDFBookmarkControl)currentBotaTool).InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
((CPDFBookmarkControl)currentBotaTool).LoadBookmark();
|
|
|
}
|
|
|
-
|
|
|
+ pdfAnnotationControl.SetPDFViewer(pdfViewControl.PDFView);
|
|
|
ViewSettingBtn.IsChecked = false;
|
|
|
PropertyContainer.Child = null;
|
|
|
PropertyContainer.Visibility = Visibility.Collapsed;
|
|
@@ -200,7 +211,6 @@ namespace compdfkit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
@@ -488,6 +498,10 @@ namespace compdfkit
|
|
|
PropertyContainer.Width = 260;
|
|
|
PropertyContainer.Child = properytPanel;
|
|
|
PropertyContainer.Visibility = visible;
|
|
|
+ if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
|
|
|
+ {
|
|
|
+ RightPanelButton.IsChecked = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void RightPanelButton_Click(object sender, RoutedEventArgs e)
|
|
@@ -497,7 +511,18 @@ namespace compdfkit
|
|
|
{
|
|
|
if (toggleButton.IsChecked == true)
|
|
|
{
|
|
|
- ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
|
|
|
+ if (currentMode == "Annotation")
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
|
|
|
+ }
|
|
|
+ else if (currentMode == "Edit")
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(null, Visibility.Visible);
|
|
|
+ }
|
|
|
if ((bool)ViewSettingBtn.IsChecked)
|
|
|
{
|
|
|
ViewSettingBtn.IsChecked = false;
|
|
@@ -510,50 +535,297 @@ namespace compdfkit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
- /// 每一项退出时执行操作
|
|
|
- /// 每一项进入时执行操作
|
|
|
+ /// Actions performed when switching modes:
|
|
|
+ /// Separated into actions performed upon entering and exiting the mode.
|
|
|
/// </summary>
|
|
|
- /// <param name="sender"></param>
|
|
|
- /// <param name="e"></param>
|
|
|
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
if (isFirstLoad)
|
|
|
{
|
|
|
isFirstLoad = false;
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
|
|
|
switch (currentMode)
|
|
|
{
|
|
|
case "Viewer":
|
|
|
-
|
|
|
+
|
|
|
break;
|
|
|
+ //Behavior when exit Edit mode
|
|
|
+ // Clear the ToolBar
|
|
|
+ // Collapse the ToolBar
|
|
|
+ // Clear And Collapse the property panel.
|
|
|
case "Annotation":
|
|
|
- ToolBarContainer.Visibility = Visibility.Collapsed;
|
|
|
+ AnnotationBarControl.Visibility = Visibility.Collapsed;
|
|
|
+ AnnotationBarControl.ClearAllToolState();
|
|
|
+ ExpandRightPropertyPanel(null, Visibility.Collapsed);
|
|
|
+
|
|
|
break;
|
|
|
+
|
|
|
+ // Behavior when exit Edit mode:
|
|
|
+ // Collapsed the ToolBar
|
|
|
+ // Set the mode to allow editing None
|
|
|
+ // Set the mouse mode to PanTool
|
|
|
+ // Reload Document
|
|
|
+ // Unsubscribe click event.
|
|
|
+ // Clear And Collapse the property panel.
|
|
|
case "Edit":
|
|
|
- ToolBarContainer.Visibility = Visibility.Collapsed;
|
|
|
+ PDFEditTool.Visibility = Visibility.Collapsed;
|
|
|
+ pdfViewControl.PDFView?.SetShowLink(true);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
+
|
|
|
+ pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
|
|
|
+ ExpandRightPropertyPanel(null, Visibility.Collapsed);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ // Behavior when switching to Viewer mode:
|
|
|
+ // Hide the ToolBar
|
|
|
if ((string)item.Content == "Viewer")
|
|
|
{
|
|
|
-
|
|
|
+ ToolBarContainer.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
+
|
|
|
+ // Behavior when switching to Annotation mode:
|
|
|
+ // Show the ToolBar
|
|
|
+ // Show the AnnotationBar
|
|
|
else if ((string)item.Content == "Annotation")
|
|
|
{
|
|
|
ToolBarContainer.Visibility = Visibility.Visible;
|
|
|
+ AnnotationBarControl.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
+
|
|
|
+ // Behavior when switching to Edit mode:
|
|
|
+ // Show the ToolBar
|
|
|
+ // Show the EditBar
|
|
|
+ // Set the mode to allow editing of both text and images
|
|
|
+ // Set the mouse mode to PDFEdit
|
|
|
+ // Reload Document
|
|
|
else if ((string)item.Content == "Edit")
|
|
|
{
|
|
|
ToolBarContainer.Visibility = Visibility.Visible;
|
|
|
- }
|
|
|
+ PDFEditTool.Visibility = Visibility.Visible;
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
|
|
|
+ pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
|
|
|
+ }
|
|
|
currentMode = (string)item.Content;
|
|
|
}
|
|
|
+
|
|
|
+ #region Annotation Mode
|
|
|
+
|
|
|
+ private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ CPDFAnnotationType[] annotationProperties = { CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout, CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText, CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square, CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link, CPDFAnnotationType.Audio };
|
|
|
+ AnnotationBarControl.InitAnnotationBar(annotationProperties);
|
|
|
+ AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
|
|
|
+ AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
|
|
|
+ AnnotationBarControl.UndoRedoEvent += AnnotationBarControl_UndoRedoEvent;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AnnotationBarControl_UndoRedoEvent(object sender, string e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ if (e == "Undo")
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Undo();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Redo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton toggleButton = sender as ToggleButton;
|
|
|
+ if (toggleButton != null)
|
|
|
+ {
|
|
|
+ if (toggleButton.IsChecked == true)
|
|
|
+ {
|
|
|
+ if (pdfAnnotationControl != null)
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
|
|
|
+ if ((bool)ViewSettingBtn.IsChecked)
|
|
|
+ {
|
|
|
+ ViewSettingBtn.IsChecked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(null, Visibility.Collapsed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
|
|
|
+ {
|
|
|
+ pdfAnnotationControl.LoadAnnotationPanel(e);
|
|
|
+ if (e != CPDFAnnotationType.Audio)
|
|
|
+ {
|
|
|
+ ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
|
|
|
+ RightPanelButton.IsChecked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
|
|
|
+ AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Edit Mode
|
|
|
+ /// <summary>
|
|
|
+ /// Clear the selected state of editing-related buttons.
|
|
|
+ /// </summary>
|
|
|
+ private void ClearPDFEditState(ToggleButton ignoreBtn = null)
|
|
|
+ {
|
|
|
+ List<ToggleButton> clearBtnList = new List<ToggleButton>()
|
|
|
+ {
|
|
|
+ PDFTextEditButton,
|
|
|
+ PDFImageEditButton
|
|
|
+ };
|
|
|
+
|
|
|
+ foreach (ToggleButton item in clearBtnList)
|
|
|
+ {
|
|
|
+ if (ignoreBtn == item)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ item.IsChecked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton senderBtn = sender as ToggleButton;
|
|
|
+ if (senderBtn != null && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ ClearPDFEditState(senderBtn);
|
|
|
+ if (senderBtn.IsChecked == true)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton senderBtn = sender as ToggleButton;
|
|
|
+ if (senderBtn != null && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ senderBtn.IsChecked = false;
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+ openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
|
|
|
+ if (openFileDialog.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ ClearPDFEditState(senderBtn);
|
|
|
+ pdfViewControl.PDFView?.ClearSelectPDFEdit();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
|
|
|
+ pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UndoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Undo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RedoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Redo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Text and Image Selected Event
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
|
|
|
+ {
|
|
|
+ lastPDFEditEvent = e;
|
|
|
+ ViewSettingBtn.IsChecked = false;
|
|
|
+ if (e == null)
|
|
|
+ {
|
|
|
+ pdfEditControl = null;
|
|
|
+ PropertyContainer.Child = pdfEditControl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Mouse.RightButton == MouseButtonState.Pressed)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (e.EditType == CPDFEditType.EditText)
|
|
|
+ {
|
|
|
+ PDFTextEditControl textEditControl = new PDFTextEditControl();
|
|
|
+ textEditControl.SetPDFTextEditData(e);
|
|
|
+ pdfEditControl = textEditControl as UIElement;
|
|
|
+ PropertyContainer.Child = pdfEditControl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ UIElement pageView = sender as UIElement;
|
|
|
+ if (pageView != null)
|
|
|
+ {
|
|
|
+ pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp; ;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ UIElement pageView = sender as UIElement;
|
|
|
+ if (pageView != null)
|
|
|
+ {
|
|
|
+ pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
|
|
|
+ }
|
|
|
+ if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
|
|
|
+ {
|
|
|
+ PDFImageEditControl imageEditControl = new PDFImageEditControl();
|
|
|
+ imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
|
|
|
+ pdfEditControl = imageEditControl as UIElement;
|
|
|
+ PropertyContainer.Child = pdfEditControl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|