using Compdfkit_Tools.Helper; using Compdfkit_Tools.PDFControl; using ComPDFKitViewer.PdfViewer; 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; using System.Windows.Controls; 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 DocsEditControl { public partial class MainWindow : Window, INotifyPropertyChanged { private PDFViewControl pdfViewer; private PDFViewControl passwordViewer; private PageEditControl pageEditControl = new PageEditControl(); private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation); public bool CanUndo { get { if (pdfViewer != null && pdfViewer.PDFView != null) { return pdfViewer.PDFView.UndoManager.CanUndo; } return false; } } public bool CanRedo { get { if (pdfViewer != null && pdfViewer.PDFView != null) { return pdfViewer.PDFView.UndoManager.CanRedo; } return false; } } private bool _canSave = false; public bool CanSave { get => _canSave; set { _canSave = value; OnPropertyChanged(); } } public MainWindow() { InitializeComponent(); LoadDefaultDocument(); } #region Load document private void LoadDefaultDocument() { string defaultFilePath = "PDF32000_2008.pdf"; pdfViewer = new PDFViewControl(); pdfViewer.PDFView.InitDocument(defaultFilePath); LoadDocument(); } private void LoadDocument() { pdfViewer.PDFView.Load(); pdfViewer.PDFView.SetShowLink(true); pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged; pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged; PDFGrid.Child = pageEditControl; pageEditControl.PDFViewControl = pdfViewer; pageEditControl.OnAnnotEditHandler -= PageEditControlRefreshAnnotList; pageEditControl.OnAnnotEditHandler += PageEditControlRefreshAnnotList; pageEditControl.PageMoved -= PageEditControl_PageMoved; pageEditControl.PageMoved += PageEditControl_PageMoved; PasswordUI.Closed -= PasswordUI_Closed; PasswordUI.Canceled -= PasswordUI_Canceled; PasswordUI.Confirmed -= PasswordUI_Confirmed; PasswordUI.Closed += PasswordUI_Closed; PasswordUI.Canceled += PasswordUI_Canceled; PasswordUI.Confirmed += PasswordUI_Confirmed; CPDFSaclingControl.InitWithPDFViewer(pdfViewer.PDFView); CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.PDFView.ZoomFactor * 100))); ViewSettingBtn.IsChecked = false; botaBarControl.InitWithPDFViewer(pdfViewer.PDFView); botaBarControl.SelectBotaTool(BOTATools.Thumbnail); } private void PageEditControlRefreshAnnotList(object sender, EventArgs e) { botaBarControl.LoadAnnotationList(); } 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; pdfViewer = passwordViewer; LoadDocument(); } else { PasswordUI.SetShowError("Wrong Password", 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; } #endregion private void PdfViewer_InfoChanged(object sender, KeyValuePair e) { if (e.Key == "Zoom") { CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100))); } } private void PageEditControl_PageMoved(object sender, RoutedEventArgs e) { if (pdfViewer == null || pdfViewer.PDFView == null) { return; } BotaSideTool.InitWithPDFViewer(pdfViewer.PDFView); } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }