123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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<string, object> 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));
- }
- }
- }
|