|
@@ -1,5 +1,7 @@
|
|
|
-using ComPDFKit.PDFPage;
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
using compdfkit_tools.Edit;
|
|
|
+using compdfkit_tools.Helper;
|
|
|
using compdfkit_tools.PDFControl;
|
|
|
using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
@@ -9,21 +11,11 @@ using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Diagnostics;
|
|
|
using System.Drawing;
|
|
|
-using System.Linq;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
-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;
|
|
|
-using System.Xml.Linq;
|
|
|
|
|
|
namespace edit_ctrl_demo
|
|
|
{
|
|
@@ -39,9 +31,9 @@ namespace edit_ctrl_demo
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- if (PDFView != null)
|
|
|
+ if (pdfViewControl != null&& pdfViewControl.PDFView!=null)
|
|
|
{
|
|
|
- return PDFView.UndoManager.CanUndo;
|
|
|
+ return pdfViewControl.PDFView.UndoManager.CanUndo;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -54,9 +46,9 @@ namespace edit_ctrl_demo
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- if (PDFView != null)
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null)
|
|
|
{
|
|
|
- return PDFView.UndoManager.CanRedo;
|
|
|
+ return pdfViewControl.PDFView.UndoManager.CanRedo;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -70,8 +62,10 @@ namespace edit_ctrl_demo
|
|
|
/// <summary>
|
|
|
/// 缩放比例
|
|
|
/// </summary>
|
|
|
- private double[] zoomLevel = { 1.00f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
|
|
|
+ private PDFViewControl passwordViewer;
|
|
|
+ private PDFViewControl pdfViewControl;
|
|
|
|
|
|
+ private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -95,20 +89,104 @@ namespace edit_ctrl_demo
|
|
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
LoadDefaultDocument();
|
|
|
- TitleBarTool.OpenFileEvent += TitleBarTool_OpenFileEvent;
|
|
|
- PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
|
|
|
- PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
|
|
|
- PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
|
|
|
- PDFView.MouseWheelZoomHandler += PDFView_MouseWheelZoomHandler;
|
|
|
+ BindZoomLevel();
|
|
|
+
|
|
|
+ if(pdfViewControl!=null)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
|
|
|
+ pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
|
|
|
+ pdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 鼠标滚轮缩放事件
|
|
|
- /// </summary>
|
|
|
- private void PDFView_MouseWheelZoomHandler(object sender, bool e)
|
|
|
+ private void BindZoomLevel()
|
|
|
+ {
|
|
|
+ foreach (double zoomLevel in zoomLevelList)
|
|
|
+ {
|
|
|
+ ComboBoxItem zoomItem = new ComboBoxItem();
|
|
|
+ zoomItem.Content = zoomLevel + "%";
|
|
|
+ ZoomComboBox.Items.Add(zoomItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadDocument()
|
|
|
{
|
|
|
- double newZoom = CheckZoomLevel(PDFView.ZoomFactor + (e ? 0.01 : -0.01), e);
|
|
|
- PDFView?.Zoom(newZoom);
|
|
|
+ pdfViewControl.PDFView?.Load();
|
|
|
+ PDFGrid.Child = pdfViewControl;
|
|
|
+ pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
|
|
|
+ pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
|
|
|
+ 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)) + "%";
|
|
|
+
|
|
|
+ SetEditMode();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Confirmed(object sender, string e)
|
|
|
+ {
|
|
|
+ if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ passwordViewer.PDFView.Document.UnlockWithPassword(e);
|
|
|
+ if (passwordViewer.PDFView.Document.IsLocked == false)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("", Visibility.Collapsed);
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ pdfViewControl = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("error", Visibility.Visible);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Canceled(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
+ {
|
|
|
+ if (e.Key == "PageNum")
|
|
|
+ {
|
|
|
+ PageRangeText.Text = string.Format("{0}/{1}", e.Value, pdfViewControl.PDFView.Document.PageCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e.Key == "Zoom")
|
|
|
+ {
|
|
|
+ ZoomTextBox.Text = string.Format("{0}", (int)((double)e.Value * 100)) + "%";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -127,16 +205,16 @@ namespace edit_ctrl_demo
|
|
|
}
|
|
|
|
|
|
zoom *= 100;
|
|
|
- for (int i = 0; i < zoomLevel.Length - 1; i++)
|
|
|
+ for (int i = 0; i < zoomLevelList.Length - 1; i++)
|
|
|
{
|
|
|
- if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
|
|
|
+ if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
|
|
|
{
|
|
|
- standardZoom = zoomLevel[i + 1];
|
|
|
+ standardZoom = zoomLevelList[i + 1];
|
|
|
break;
|
|
|
}
|
|
|
- if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
|
|
|
+ if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
|
|
|
{
|
|
|
- standardZoom = zoomLevel[i];
|
|
|
+ standardZoom = zoomLevelList[i];
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -183,7 +261,8 @@ namespace edit_ctrl_demo
|
|
|
lastPDFEditEvent = e;
|
|
|
if (e == null)
|
|
|
{
|
|
|
- PDFEditContainer.Child= null;
|
|
|
+ PropertyContainer.Child= null;
|
|
|
+ PropertyContainer.Visibility= Visibility.Collapsed;
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -196,40 +275,343 @@ namespace edit_ctrl_demo
|
|
|
{
|
|
|
PDFTextEditControl textEditControl = new PDFTextEditControl();
|
|
|
textEditControl.SetPDFTextEditData(e);
|
|
|
- PDFEditContainer.Child = textEditControl;
|
|
|
+ PropertyContainer.Child = textEditControl;
|
|
|
+ PropertyContainer.Visibility = Visibility.Visible;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (e.EditType == CPDFEditType.EditImage)
|
|
|
+ if (e.EditType == CPDFEditType.EditImage && pdfViewControl!=null)
|
|
|
{
|
|
|
PDFImageEditControl imageEditControl = new PDFImageEditControl();
|
|
|
- imageEditControl.InitWithPDFViewer(PDFView);
|
|
|
+ imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
imageEditControl.SetPDFImageEditData(e);
|
|
|
- PDFEditContainer.Child = imageEditControl;
|
|
|
+ PropertyContainer.Child = imageEditControl;
|
|
|
+ PropertyContainer.Visibility = Visibility.Visible;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 工具栏选择文件对话框事件通知
|
|
|
+ /// 加载显示默认文档
|
|
|
/// </summary>
|
|
|
- private void TitleBarTool_OpenFileEvent(object sender, string filePath)
|
|
|
+ private void LoadDefaultDocument()
|
|
|
{
|
|
|
- ClearPDFEditState();
|
|
|
- PDFView?.CloseDocument();
|
|
|
- PDFView?.InitDocument(filePath);
|
|
|
- PDFView?.Load();
|
|
|
- PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
+ string defaultFilePath = "..\\..\\..\\..\\developer_guide_windows.pdf";
|
|
|
+ pdfViewControl = new PDFViewControl();
|
|
|
+ pdfViewControl.PDFView.InitDocument(defaultFilePath);
|
|
|
+ LoadDocument();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 加载显示默认文档
|
|
|
+ /// 搜索工具点击处理
|
|
|
/// </summary>
|
|
|
- private void LoadDefaultDocument()
|
|
|
+ private void SearchToolButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- string defaultFilePath = "..\\..\\..\\..\\developer_guide_windows.pdf";
|
|
|
- PDFView?.InitDocument(defaultFilePath);
|
|
|
- PDFView?.Load();
|
|
|
+ UIElement botaTool = GetBotaTool();
|
|
|
+ if (botaTool == null || !(botaTool is CPDFSearchControl))
|
|
|
+ {
|
|
|
+ CPDFSearchControl searchControl = new CPDFSearchControl();
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ searchControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ }
|
|
|
+ SetBotaTool(searchControl);
|
|
|
+ }
|
|
|
+ ExpandBotaTool(SearchToolButton.IsChecked == true);
|
|
|
+ ClearToolState(SearchToolButton);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 缩略图列表点击处理
|
|
|
+ /// </summary>
|
|
|
+ private void ThumbToolButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ UIElement botaTool = GetBotaTool();
|
|
|
+ if (botaTool == null || !(botaTool is CPDFThumbnailControl))
|
|
|
+ {
|
|
|
+ CPDFThumbnailControl thumbControl = new CPDFThumbnailControl();
|
|
|
+
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ thumbControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ thumbControl.LoadThumb();
|
|
|
+ }
|
|
|
+ SetBotaTool(thumbControl);
|
|
|
+ }
|
|
|
+ ExpandBotaTool(ThumbToolButton.IsChecked == true);
|
|
|
+ ClearToolState(ThumbToolButton);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 书签列表点击处理
|
|
|
+ /// </summary>
|
|
|
+ private void BookmarkToolButtonn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ UIElement botaTool = GetBotaTool();
|
|
|
+ if (botaTool == null || !(botaTool is CPDFBookmarkControl))
|
|
|
+ {
|
|
|
+ CPDFBookmarkControl bookmarkControl = new CPDFBookmarkControl();
|
|
|
+
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ bookmarkControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ bookmarkControl.LoadBookmark();
|
|
|
+ }
|
|
|
+ SetBotaTool(bookmarkControl);
|
|
|
+ }
|
|
|
+ ExpandBotaTool(BookmarkToolButton.IsChecked == true);
|
|
|
+ ClearToolState(BookmarkToolButton);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 大纲列表处理
|
|
|
+ /// </summary>
|
|
|
+ private void OutlineToolButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ UIElement botaTool = GetBotaTool();
|
|
|
+ if (botaTool == null || !(botaTool is CPDFOutlineControl))
|
|
|
+ {
|
|
|
+ CPDFOutlineControl outlineControl = new CPDFOutlineControl();
|
|
|
+
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ outlineControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ }
|
|
|
+ SetBotaTool(outlineControl);
|
|
|
+ }
|
|
|
+ ExpandBotaTool(OutlineToolButton.IsChecked == true);
|
|
|
+ ClearToolState(OutlineToolButton);
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 设置Bota工具内容
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="newChild"></param>
|
|
|
+ private void SetBotaTool(UIElement newChild)
|
|
|
+ {
|
|
|
+ BotaToolContainer.Child = newChild;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取Bota工具
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private UIElement GetBotaTool()
|
|
|
+ {
|
|
|
+ return BotaToolContainer.Child;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 展开Bota工具
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="isExpand"></param>
|
|
|
+ private void ExpandBotaTool(bool isExpand)
|
|
|
+ {
|
|
|
+ BotaToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 清除左边工具栏状态
|
|
|
+ /// </summary>
|
|
|
+ private void ClearToolState(UIElement ignoreTool)
|
|
|
+ {
|
|
|
+ foreach (UIElement child in BotaSideTool.Children)
|
|
|
+ {
|
|
|
+ if (child != ignoreTool && child is ToggleButton buttonTool)
|
|
|
+ {
|
|
|
+ buttonTool.IsChecked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ToolExpand_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton expandBtn = sender as ToggleButton;
|
|
|
+ if (expandBtn != null)
|
|
|
+ {
|
|
|
+ bool isExpand = expandBtn.IsChecked == true;
|
|
|
+ ExpandLeftPanel(isExpand);
|
|
|
+ if (isExpand)
|
|
|
+ {
|
|
|
+ ThumbToolButton.IsChecked = isExpand;
|
|
|
+ ThumbToolButton_Click(ThumbToolButton, new RoutedEventArgs());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ExpandLeftPanel(true);
|
|
|
+ SearchToolButton.IsChecked = true;
|
|
|
+ SearchToolButton_Click(SearchToolButton, new RoutedEventArgs());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExpandLeftPanel(bool isExpand)
|
|
|
+ {
|
|
|
+ ExpandToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ if (isExpand)
|
|
|
+ {
|
|
|
+ BodyGrid.ColumnDefinitions[0].Width = new GridLength(260);
|
|
|
+ BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
|
|
|
+ BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Border_MouseEnter(object sender, MouseEventArgs e)
|
|
|
+ {
|
|
|
+ FloatPageTool.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PDFGrid_MouseMove(object sender, MouseEventArgs e)
|
|
|
+ {
|
|
|
+ FloatPageTool.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton toggleButton = sender as ToggleButton;
|
|
|
+ if (toggleButton != null)
|
|
|
+ {
|
|
|
+ if (toggleButton.IsChecked == true)
|
|
|
+ {
|
|
|
+ CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
|
|
|
+ displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ PropertyContainer.Child = displayPanel;
|
|
|
+ PropertyContainer.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PropertyContainer.Child = null;
|
|
|
+ PropertyContainer.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ZoomComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ ComboBoxItem selectItem = ZoomComboBox.SelectedItem as ComboBoxItem;
|
|
|
+ if (selectItem != null && selectItem.Content != null && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double zoomLevel))
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.Zoom(zoomLevel / 100D);
|
|
|
+ ZoomTextBox.Text = string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)) + "%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ZoomInBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null)
|
|
|
+ {
|
|
|
+ double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
|
|
|
+ pdfViewControl.PDFView.Zoom(newZoom);
|
|
|
+ ZoomTextBox.Text = string.Format("{0}", (int)(newZoom * 100)) + "%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ZoomOutBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null)
|
|
|
+ {
|
|
|
+ double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
|
|
|
+ pdfViewControl.PDFView.Zoom(newZoom);
|
|
|
+ ZoomTextBox.Text = string.Format("{0}", (int)(newZoom * 100)) + "%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PrevPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ FileInfoUI.Visibility = Visibility.Visible;
|
|
|
+ FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
|
|
|
+ PopupBorder.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OpenFile_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string filePath = CommonHelper.GetFilePathOrEmpty();
|
|
|
+ if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ passwordViewer = new PDFViewControl();
|
|
|
+ passwordViewer.PDFView.InitDocument(filePath);
|
|
|
+ if (passwordViewer.PDFView.Document == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Open File Failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (passwordViewer.PDFView.Document.IsLocked)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PopupBorder.Visibility = Visibility.Visible;
|
|
|
+ PasswordUI.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pdfViewControl = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
|
|
|
+ if (pdfDoc.WriteToLoadedPath())
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
+ saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
+ saveDialog.DefaultExt = ".pdf";
|
|
|
+ saveDialog.OverwritePrompt = true;
|
|
|
+
|
|
|
+ if (saveDialog.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -238,21 +620,21 @@ namespace edit_ctrl_demo
|
|
|
private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ToggleButton senderBtn=sender as ToggleButton;
|
|
|
- if(senderBtn != null)
|
|
|
+ if(senderBtn != null && pdfViewControl!=null)
|
|
|
{
|
|
|
ClearPDFEditState(senderBtn);
|
|
|
if (senderBtn.IsChecked == true)
|
|
|
{
|
|
|
- PDFView?.SetPDFEditType(CPDFEditType.EditText);
|
|
|
- PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
|
|
|
- PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
- PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- PDFView?.SetPDFEditType(CPDFEditType.None);
|
|
|
- PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
- PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -263,19 +645,19 @@ namespace edit_ctrl_demo
|
|
|
private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ToggleButton senderBtn = sender as ToggleButton;
|
|
|
- if (senderBtn != null)
|
|
|
+ if (senderBtn != null && pdfViewControl!=null)
|
|
|
{
|
|
|
ClearPDFEditState(senderBtn);
|
|
|
senderBtn.IsChecked = false;
|
|
|
- PDFView?.SetPDFEditType(CPDFEditType.EditImage);
|
|
|
- PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
- PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
|
|
|
if (openFileDialog.ShowDialog() == true)
|
|
|
{
|
|
|
- PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
|
|
|
- PDFView?.AddPDFEditImage(openFileDialog.FileName);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
|
|
|
+ pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -288,8 +670,7 @@ namespace edit_ctrl_demo
|
|
|
List<ToggleButton> clearBtnList = new List<ToggleButton>()
|
|
|
{
|
|
|
PDFTextEditButton,
|
|
|
- PDFImageEditButton,
|
|
|
- PDFEditBtn,
|
|
|
+ PDFImageEditButton
|
|
|
};
|
|
|
|
|
|
foreach (ToggleButton item in clearBtnList)
|
|
@@ -300,8 +681,11 @@ namespace edit_ctrl_demo
|
|
|
}
|
|
|
item.IsChecked = false;
|
|
|
}
|
|
|
-
|
|
|
- PDFEditContainer.Child = null;
|
|
|
+
|
|
|
+ if(PropertyContainer!=null)
|
|
|
+ {
|
|
|
+ PropertyContainer.Child = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -309,7 +693,10 @@ namespace edit_ctrl_demo
|
|
|
/// </summary>
|
|
|
private void UndoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- PDFView?.UndoManager?.Undo();
|
|
|
+ if(pdfViewControl!=null && pdfViewControl.PDFView!=null)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Undo();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -317,7 +704,10 @@ namespace edit_ctrl_demo
|
|
|
/// </summary>
|
|
|
private void RedoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- PDFView?.UndoManager?.Redo();
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ pdfViewControl.PDFView.UndoManager?.Redo();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -341,7 +731,7 @@ namespace edit_ctrl_demo
|
|
|
{
|
|
|
PDFTextEditControl textEditControl = new PDFTextEditControl();
|
|
|
textEditControl.SetPDFTextEditData(lastPDFEditEvent);
|
|
|
- PDFEditContainer.Child = textEditControl;
|
|
|
+ PropertyContainer.Child = textEditControl;
|
|
|
}
|
|
|
};
|
|
|
editCommand.PopupMenu.Items.Add(propertyMenu);
|
|
@@ -400,7 +790,7 @@ namespace edit_ctrl_demo
|
|
|
{
|
|
|
lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
|
|
|
lastPDFEditEvent.UpdatePDFEditByEventArgs();
|
|
|
- PDFView?.ClearSelectPDFEdit();
|
|
|
+ pdfViewControl.PDFView?.ClearSelectPDFEdit();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -410,9 +800,9 @@ namespace edit_ctrl_demo
|
|
|
exportMenu.Header = "导出";
|
|
|
exportMenu.Click += (o, p) =>
|
|
|
{
|
|
|
- if (PDFView != null)
|
|
|
+ if (pdfViewControl != null && pdfViewControl.PDFView!=null)
|
|
|
{
|
|
|
- Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
|
|
|
+ Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView.GetSelectedImages();
|
|
|
if (imageDict != null && imageDict.Count > 0)
|
|
|
{
|
|
|
System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
|
|
@@ -528,24 +918,31 @@ namespace edit_ctrl_demo
|
|
|
/// <summary>
|
|
|
/// 进入文字和图片编辑
|
|
|
/// </summary>
|
|
|
- private void PDFEditBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
- ToggleButton senderBtn = sender as ToggleButton;
|
|
|
- if (senderBtn != null)
|
|
|
+ SetEditMode();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetEditMode()
|
|
|
+ {
|
|
|
+ ClearPDFEditState(null);
|
|
|
+
|
|
|
+ if (pdfViewControl != null && ViewComboBox != null)
|
|
|
{
|
|
|
- ClearPDFEditState(senderBtn);
|
|
|
- if (senderBtn.IsChecked == true)
|
|
|
+ if (ViewComboBox.SelectedIndex == 0)
|
|
|
{
|
|
|
- PDFView?.SetPDFEditType(CPDFEditType.EditText|CPDFEditType.EditImage);
|
|
|
- PDFView?.SetPDFEditCreateType(CPDFEditType.None);
|
|
|
- PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
- PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
+ return;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ if (ViewComboBox.SelectedIndex == 1)
|
|
|
{
|
|
|
- PDFView?.SetPDFEditType(CPDFEditType.None);
|
|
|
- PDFView?.SetMouseMode(MouseModes.PanTool);
|
|
|
- PDFView?.ReloadDocument();
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
|
|
|
+ pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
|
|
|
+ pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewControl.PDFView?.ReloadDocument();
|
|
|
}
|
|
|
}
|
|
|
}
|