123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- using Compdfkit_Tools.Helper;
- using Compdfkit_Tools.PDFControl;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- 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;
- namespace ContentEditorViewControl
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- private PDFViewControl passwordViewer;
- private PDFViewControl pdfViewer;
- private ContentEditControl contentEditControl = new ContentEditControl();
- 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;
- }
- }
- public bool CanSave
- {
- get
- {
- if (pdfViewer != null && pdfViewer.PDFView != null)
- {
- return pdfViewer.PDFView.UndoManager.CanSave;
- }
- return false;
- }
- }
- private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
- {
- if (e.Key == "Zoom")
- {
- CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
- }
- }
- public MainWindow()
- {
- InitializeComponent();
- }
- #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;
- PasswordUI.Closed -= PasswordUI_Closed;
- PasswordUI.Canceled -= PasswordUI_Canceled;
- PasswordUI.Confirmed -= PasswordUI_Confirmed;
- PasswordUI.Closed += PasswordUI_Closed;
- PasswordUI.Canceled += PasswordUI_Canceled;
- PasswordUI.Confirmed += PasswordUI_Confirmed;
- contentEditControl.PdfViewControl = pdfViewer;
- contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
- CPDFSaclingControl.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
- CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(contentEditControl.PdfViewControl.PDFView.ZoomFactor * 100)));
- PDFGrid.Child = contentEditControl;
- botaBarControl.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
- botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
- contentEditControl.SetBOTAContainer(botaBarControl);
- contentEditControl.InitWithPDFViewer(pdfViewer.PDFView);
- }
- 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;
- }
- private void LoadDefaultDocument()
- {
- string defaultFilePath = "PDF32000_2008.pdf";
- pdfViewer.PDFView.InitDocument(defaultFilePath);
- LoadDocument();
- }
- #endregion
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- pdfViewer = new PDFViewControl();
- LoadDefaultDocument();
- }
- 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 OpenFile()
- {
- string filePath = CommonHelper.GetExistedPathOrEmpty();
- if (!string.IsNullOrEmpty(filePath) && contentEditControl.PdfViewControl != null)
- {
- if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
- {
- string oldFilePath = pdfViewer.PDFView.Document.FilePath;
- if (oldFilePath.ToLower() == filePath.ToLower())
- {
- return;
- }
- }
- 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
- {
- pdfViewer = passwordViewer;
- LoadDocument();
- }
- }
- }
- private void OpenFile_Click(object sender, RoutedEventArgs e)
- {
- OpenFile();
- }
- private void ControlRightPanel()
- {
- if (RightPanelButton != null)
- {
- if (RightPanelButton.IsChecked == true)
- {
- if (contentEditControl.pdfContentEditControl != null)
- {
- contentEditControl.ExpandRightPropertyPanel(contentEditControl.pdfContentEditControl, Visibility.Visible);
- if ((bool)ViewSettingBtn.IsChecked)
- {
- ViewSettingBtn.IsChecked = false;
- }
- }
- }
- else
- {
- contentEditControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
- }
- }
- }
- private void RightPanelButton_Click(object sender, RoutedEventArgs e)
- {
- ControlRightPanel();
- }
-
- private void ShowViewSettings()
- {
- if (ViewSettingBtn != null)
- {
- if (ViewSettingBtn.IsChecked == true)
- {
- CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
- displayPanel.InitWithPDFViewer(contentEditControl.PdfViewControl.PDFView);
- contentEditControl.SetViewSettings(Visibility.Visible, displayPanel);
- if ((bool)RightPanelButton.IsChecked)
- {
- RightPanelButton.IsChecked = false;
- }
- }
- else
- {
- contentEditControl.SetViewSettings(Visibility.Collapsed);
- }
- }
- }
- private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
- {
- ShowViewSettings();
- }
- private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
- {
- ToggleButton expandBtn = sender as ToggleButton;
- if (expandBtn != null)
- {
- bool isExpand = expandBtn.IsChecked == true;
- contentEditControl.ExpandLeftPanel(isExpand);
- }
- }
- }
- }
|