|
@@ -2,7 +2,9 @@
|
|
|
using Compdfkit_Tools.PDFControl;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
using System.Linq;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
@@ -15,82 +17,80 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
+using Compdfkit_Tools.PDFView;
|
|
|
+using ComPDFKit.PDFDocument;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
+using ComPDFKitViewer;
|
|
|
+using ComPDFKitViewer.PdfViewer;
|
|
|
+using Microsoft.Win32;
|
|
|
|
|
|
namespace ContentEditorViewControl
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// MainWindow.xaml 的交互逻辑
|
|
|
+ /// Interaction logic for MainWindow.xaml
|
|
|
/// </summary>
|
|
|
- public partial class MainWindow : Window
|
|
|
+ public partial class MainWindow: Window, INotifyPropertyChanged
|
|
|
{
|
|
|
- private PDFViewControl passwordViewer;
|
|
|
-
|
|
|
+ private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
|
|
|
+ private RegularViewerControl regularViewerControl = new RegularViewerControl();
|
|
|
private PDFViewControl pdfViewer;
|
|
|
-
|
|
|
+ private PDFViewControl passwordViewer;
|
|
|
private ContentEditControl contentEditControl = new ContentEditControl();
|
|
|
private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
|
|
|
-
|
|
|
- public bool CanUndo
|
|
|
+
|
|
|
+ private bool _canSave = false;
|
|
|
+ public bool CanSave
|
|
|
{
|
|
|
- get
|
|
|
- {
|
|
|
- if (pdfViewer != null && pdfViewer.PDFView != null)
|
|
|
- {
|
|
|
- return pdfViewer.PDFView.UndoManager.CanUndo;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- public bool CanRedo
|
|
|
- {
|
|
|
- get
|
|
|
+ get => _canSave;
|
|
|
+ set
|
|
|
{
|
|
|
- if (pdfViewer != null && pdfViewer.PDFView != null)
|
|
|
- {
|
|
|
- return pdfViewer.PDFView.UndoManager.CanRedo;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ _canSave = value;
|
|
|
+ OnPropertyChanged();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public bool CanSave
|
|
|
+
|
|
|
+ public MainWindow()
|
|
|
{
|
|
|
- get
|
|
|
- {
|
|
|
- if (pdfViewer != null && pdfViewer.PDFView != null)
|
|
|
- {
|
|
|
- return pdfViewer.PDFView.UndoManager.CanSave;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
+ InitializeComponent();
|
|
|
+ DataContext = this;
|
|
|
}
|
|
|
- private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
+
|
|
|
+ #region Load document
|
|
|
+
|
|
|
+ private void LoadDefaultDocument()
|
|
|
{
|
|
|
- if (e.Key == "Zoom")
|
|
|
- {
|
|
|
- CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
|
|
|
- }
|
|
|
+ string defaultFilePath = "PDF32000_2008.pdf";
|
|
|
+ pdfViewer.PDFView.InitDocument(defaultFilePath);
|
|
|
+ LoadDocument();
|
|
|
}
|
|
|
-
|
|
|
- public MainWindow()
|
|
|
+
|
|
|
+ private void LoadCustomControl()
|
|
|
{
|
|
|
- InitializeComponent();
|
|
|
+ regularViewerControl.PdfViewControl = pdfViewer;
|
|
|
+ regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
|
|
|
+ regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
|
|
|
}
|
|
|
|
|
|
- #region Load Document
|
|
|
private void LoadDocument()
|
|
|
{
|
|
|
- if (pdfViewer.PDFView.Document == null)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
pdfViewer.PDFView.Load();
|
|
|
pdfViewer.PDFView.SetShowLink(true);
|
|
|
-
|
|
|
+
|
|
|
pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
|
|
|
pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
|
|
|
+ PDFGrid.Child = contentEditControl;
|
|
|
+
|
|
|
+ contentEditControl.PdfViewControl = pdfViewer;
|
|
|
+ contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ InitialPDFViewControl();
|
|
|
|
|
|
+ contentEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
|
|
|
+ contentEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
|
|
|
+ contentEditControl.OnAnnotEditHandler -= PdfContentEditControlRefreshAnnotList;
|
|
|
+ contentEditControl.OnAnnotEditHandler += PdfContentEditControlRefreshAnnotList;
|
|
|
+
|
|
|
+ contentEditControl.PdfViewControl.PDFView.SetFormFieldHighlight(true);
|
|
|
PasswordUI.Closed -= PasswordUI_Closed;
|
|
|
PasswordUI.Canceled -= PasswordUI_Canceled;
|
|
|
PasswordUI.Confirmed -= PasswordUI_Confirmed;
|
|
@@ -98,20 +98,32 @@ namespace ContentEditorViewControl
|
|
|
PasswordUI.Canceled += PasswordUI_Canceled;
|
|
|
PasswordUI.Confirmed += PasswordUI_Confirmed;
|
|
|
|
|
|
- contentEditControl.PdfViewControl = pdfViewer;
|
|
|
- contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
-
|
|
|
+ contentEditControl.PdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
|
|
|
CPDFSaclingControl.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
|
|
|
-
|
|
|
CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(contentEditControl.PdfViewControl.PDFView.ZoomFactor * 100)));
|
|
|
|
|
|
- PDFGrid.Child = contentEditControl;
|
|
|
+ ViewSettingBtn.IsChecked = false;
|
|
|
botaBarControl.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
|
|
|
botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
|
|
|
contentEditControl.SetBOTAContainer(botaBarControl);
|
|
|
- contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ displaySettingsControl.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
|
|
|
+ LoadCustomControl();
|
|
|
}
|
|
|
|
|
|
+ private void PdfContentEditControlRefreshAnnotList(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ botaBarControl.LoadAnnotationList();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ControlOnCanSaveChanged(object sender, bool e)
|
|
|
+ {
|
|
|
+ this.CanSave = e;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Password
|
|
|
+
|
|
|
private void PasswordUI_Confirmed(object sender, string e)
|
|
|
{
|
|
|
if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
|
|
@@ -145,29 +157,54 @@ namespace ContentEditorViewControl
|
|
|
PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
- private void LoadDefaultDocument()
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Load Unload custom control
|
|
|
+
|
|
|
+
|
|
|
+ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- string defaultFilePath = "PDF32000_2008.pdf";
|
|
|
- pdfViewer.PDFView.InitDocument(defaultFilePath);
|
|
|
- LoadDocument();
|
|
|
+ pdfViewer = new PDFViewControl();
|
|
|
+ LoadDefaultDocument();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Annotation
|
|
|
+
|
|
|
+ private void InitialPDFViewControl()
|
|
|
+ {
|
|
|
+ contentEditControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region Event handle
|
|
|
|
|
|
+ private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
+ {
|
|
|
+ if (e.Key == "Zoom")
|
|
|
+ {
|
|
|
+ CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
|
|
|
pdfViewer = new PDFViewControl();
|
|
|
LoadDefaultDocument();
|
|
|
}
|
|
|
-
|
|
|
- private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+
|
|
|
+ private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
- FileInfoUI.Visibility = Visibility.Visible;
|
|
|
- FileInfoControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
- PopupBorder.Visibility = Visibility.Visible;
|
|
|
+ SaveFile();
|
|
|
+ pdfViewer.PDFView.UndoManager.CanSave = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void OpenFile()
|
|
|
{
|
|
|
string filePath = CommonHelper.GetExistedPathOrEmpty();
|
|
@@ -207,12 +244,110 @@ namespace ContentEditorViewControl
|
|
|
|
|
|
private void OpenFile_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- OpenFile();
|
|
|
+ OpenFile();
|
|
|
}
|
|
|
|
|
|
- private void ControlRightPanel()
|
|
|
+ private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ToggleButton expandBtn = sender as ToggleButton;
|
|
|
+ if (expandBtn != null)
|
|
|
+ {
|
|
|
+ bool isExpand = expandBtn.IsChecked == true;
|
|
|
+ contentEditControl.ExpandLeftPanel(isExpand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
|
|
|
+ if ((string)item.Content == "Viewer")
|
|
|
+ {
|
|
|
+ regularViewerControl.IsActive = true;
|
|
|
+ contentEditControl.IsActive = false;
|
|
|
+ if (regularViewerControl.PdfViewControl != null && regularViewerControl.PdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ contentEditControl.ClearViewerControl();
|
|
|
+ PDFGrid.Child = regularViewerControl;
|
|
|
+ regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
|
|
|
+ regularViewerControl.PdfViewControl = pdfViewer;
|
|
|
+ regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
|
|
|
+ regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
|
|
|
+ regularViewerControl.SetBOTAContainer(botaBarControl);
|
|
|
+ regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ((string)item.Content == "Content Edit")
|
|
|
+ {
|
|
|
+ contentEditControl.IsActive = true;
|
|
|
+ regularViewerControl.IsActive = false;
|
|
|
+ if (contentEditControl.PdfViewControl != null && contentEditControl.PdfViewControl.PDFView != null)
|
|
|
+ {
|
|
|
+ regularViewerControl.ClearViewerControl();
|
|
|
+ pdfViewer.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
|
|
|
+ pdfViewer.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
|
|
|
+ pdfViewer.PDFView?.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ pdfViewer.PDFView?.ReloadDocument();
|
|
|
+
|
|
|
+ pdfViewer.PDFView?.SetSplitMode(SplitMode.None);
|
|
|
+
|
|
|
+ PDFGrid.Child = contentEditControl;
|
|
|
+ contentEditControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.PDFEdit);
|
|
|
+ contentEditControl.PdfViewControl = pdfViewer;
|
|
|
+ contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ contentEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
|
|
|
+ contentEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
|
|
|
+ contentEditControl.SetBOTAContainer(botaBarControl);
|
|
|
+ contentEditControl.SetDisplaySettingsControl(displaySettingsControl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ FileInfoUI.Visibility = Visibility.Visible;
|
|
|
+ FileInfoControl.InitWithPDFViewer(pdfViewer.PDFView);
|
|
|
+ PopupBorder.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ShowViewSettings();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowViewSettings()
|
|
|
+ {
|
|
|
+ if (ViewSettingBtn != null)
|
|
|
+ {
|
|
|
+ if (ViewSettingBtn.IsChecked == true)
|
|
|
+ {
|
|
|
+ contentEditControl.SetViewSettings(Visibility.Visible, displaySettingsControl);
|
|
|
+ if ((bool)RightPanelButton.IsChecked)
|
|
|
+ {
|
|
|
+ RightPanelButton.IsChecked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ contentEditControl.SetViewSettings(Visibility.Collapsed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void RightPanelButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (RightPanelButton != null)
|
|
|
+ ControlRightPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ contentEditControl.ExpandLeftPanel(true);
|
|
|
+ botaBarControl.SelectBotaTool(BOTATools.Search);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ControlRightPanel()
|
|
|
+ {
|
|
|
+ if (RightPanelButton != null)
|
|
|
{
|
|
|
if (RightPanelButton.IsChecked == true)
|
|
|
{
|
|
@@ -232,45 +367,72 @@ namespace ContentEditorViewControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RightPanelButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ #region Save file
|
|
|
+ /// <summary>
|
|
|
+ /// Save the file to another PDF file.
|
|
|
+ /// </summary>
|
|
|
+ public void SaveAsFile()
|
|
|
{
|
|
|
- ControlRightPanel();
|
|
|
+ {
|
|
|
+ if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
|
|
|
+ {
|
|
|
+ CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
|
|
|
+ SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
+ saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
+ saveDialog.DefaultExt = ".pdf";
|
|
|
+ saveDialog.OverwritePrompt = true;
|
|
|
+
|
|
|
+ if (saveDialog.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- private void ShowViewSettings()
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Save the file in the current path.
|
|
|
+ /// </summary>
|
|
|
+ private void SaveFile()
|
|
|
{
|
|
|
- if (ViewSettingBtn != null)
|
|
|
+ if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
|
|
|
{
|
|
|
- if (ViewSettingBtn.IsChecked == true)
|
|
|
+ try
|
|
|
{
|
|
|
- CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
|
|
|
- displayPanel.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
|
|
|
- contentEditControl.SetViewSettings(Visibility.Visible, displayPanel);
|
|
|
- if ((bool)RightPanelButton.IsChecked)
|
|
|
+ CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
|
|
|
+ if (pdfDoc.WriteToLoadedPath())
|
|
|
{
|
|
|
- RightPanelButton.IsChecked = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
+ saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
+ saveDialog.DefaultExt = ".pdf";
|
|
|
+ saveDialog.OverwritePrompt = true;
|
|
|
+
|
|
|
+ if (saveDialog.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- contentEditControl.SetViewSettings(Visibility.Collapsed);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
- private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- ShowViewSettings();
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
- private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ public event PropertyChangedEventHandler PropertyChanged;
|
|
|
+
|
|
|
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
{
|
|
|
- ToggleButton expandBtn = sender as ToggleButton;
|
|
|
- if (expandBtn != null)
|
|
|
- {
|
|
|
- bool isExpand = expandBtn.IsChecked == true;
|
|
|
- contentEditControl.ExpandLeftPanel(isExpand);
|
|
|
- }
|
|
|
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
}
|
|
|
}
|
|
|
}
|