MainWindow.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. using ComPDFKit.PDFDocument;
  2. using Compdfkit_Tools.Helper;
  3. using Compdfkit_Tools.PDFControl;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using Microsoft.Win32;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Runtime.CompilerServices;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Controls.Primitives;
  18. using System.Windows.Input;
  19. using System.Windows.Media.Imaging;
  20. namespace Viewer
  21. {
  22. /// <summary>
  23. /// Interaction logic for MainWindow.xaml
  24. /// </summary>
  25. public partial class MainWindow : Window, INotifyPropertyChanged
  26. {
  27. #region Property
  28. private PDFViewControl passwordViewer;
  29. private PDFViewControl pdfViewControl;
  30. CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
  31. private int[] zoomLevelList = { 10, 25, 50, 100, 150, 200, 300, 400, 500, 1000 };
  32. public event PropertyChangedEventHandler PropertyChanged;
  33. private KeyEventHandler KeyDownHandler;
  34. public bool CanSave
  35. {
  36. get
  37. {
  38. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  39. {
  40. return pdfViewControl.PDFView.UndoManager.CanSave;
  41. }
  42. return false;
  43. }
  44. }
  45. #endregion
  46. public MainWindow()
  47. {
  48. InitializeComponent();
  49. Loaded += MainWindow_Loaded;
  50. DataContext = this;
  51. }
  52. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  53. {
  54. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search);
  55. LoadDefaultDocument();
  56. }
  57. #region Load Document
  58. private void LoadDocument()
  59. {
  60. if (pdfViewControl.PDFView.Document == null)
  61. {
  62. return;
  63. }
  64. pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
  65. pdfViewControl.PDFView?.Load();
  66. pdfViewControl.PDFView?.SetShowLink(true);
  67. PDFGrid.Child = pdfViewControl;
  68. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  69. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  70. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  71. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  72. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  73. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  74. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  75. PasswordUI.Closed -= PasswordUI_Closed;
  76. PasswordUI.Canceled -= PasswordUI_Canceled;
  77. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  78. PasswordUI.Closed += PasswordUI_Closed;
  79. PasswordUI.Canceled += PasswordUI_Canceled;
  80. PasswordUI.Confirmed += PasswordUI_Confirmed;
  81. pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
  82. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  83. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  84. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  85. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  86. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  87. ViewSettingBtn.IsChecked = false;
  88. PropertyContainer.Child = null;
  89. PropertyContainer.Visibility = Visibility.Collapsed;
  90. }
  91. private void LoadDefaultDocument()
  92. {
  93. string defaultFilePath = "PDF32000_2008.pdf";
  94. pdfViewControl = new PDFViewControl();
  95. pdfViewControl.PDFView.InitDocument(defaultFilePath);
  96. LoadDocument();
  97. }
  98. #endregion
  99. #region Password
  100. private void PasswordUI_Confirmed(object sender, string e)
  101. {
  102. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  103. {
  104. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  105. if (passwordViewer.PDFView.Document.IsLocked == false)
  106. {
  107. PasswordUI.SetShowError("", Visibility.Collapsed);
  108. PasswordUI.ClearPassword();
  109. PasswordUI.Visibility = Visibility.Collapsed;
  110. PopupBorder.Visibility = Visibility.Collapsed;
  111. pdfViewControl = passwordViewer;
  112. LoadDocument();
  113. }
  114. else
  115. {
  116. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  117. }
  118. }
  119. }
  120. private void PasswordUI_Canceled(object sender, EventArgs e)
  121. {
  122. PopupBorder.Visibility = Visibility.Collapsed;
  123. PasswordUI.Visibility = Visibility.Collapsed;
  124. }
  125. private void PasswordUI_Closed(object sender, EventArgs e)
  126. {
  127. PopupBorder.Visibility = Visibility.Collapsed;
  128. PasswordUI.Visibility = Visibility.Collapsed;
  129. }
  130. #endregion
  131. #region Expand or Hide Panel
  132. private void ControlLeftPanel()
  133. {
  134. if (LeftToolPanelButton != null)
  135. {
  136. bool isExpand = LeftToolPanelButton.IsChecked == true;
  137. ExpandLeftPanel(isExpand);
  138. }
  139. }
  140. private void ExpandLeftPanel(bool isExpand)
  141. {
  142. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  143. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  144. if (isExpand)
  145. {
  146. BodyGrid.ColumnDefinitions[0].Width = new GridLength(260);
  147. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  148. }
  149. else
  150. {
  151. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  152. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  153. }
  154. }
  155. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  156. {
  157. ExpandLeftPanel(true);
  158. BotaSideTool.SelectBotaTool(BOTATools.Search);
  159. }
  160. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  161. {
  162. ToggleButton expandBtn = sender as ToggleButton;
  163. if (expandBtn != null)
  164. {
  165. bool isExpand = expandBtn.IsChecked == true;
  166. ExpandLeftPanel(isExpand);
  167. }
  168. }
  169. #endregion
  170. #region UI
  171. private double CheckZoomLevel(double zoom, bool IsGrowth)
  172. {
  173. double standardZoom = 100;
  174. if (zoom <= 0.01)
  175. {
  176. return 0.01;
  177. }
  178. if (zoom >= 10)
  179. {
  180. return 10;
  181. }
  182. zoom *= 100;
  183. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  184. {
  185. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  186. {
  187. standardZoom = zoomLevelList[i + 1];
  188. break;
  189. }
  190. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  191. {
  192. standardZoom = zoomLevelList[i];
  193. break;
  194. }
  195. }
  196. return standardZoom / 100;
  197. }
  198. private void ShowViewSettings()
  199. {
  200. if (ViewSettingBtn != null)
  201. {
  202. if (ViewSettingBtn.IsChecked == true)
  203. {
  204. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  205. PropertyContainer.Child = displayPanel;
  206. PropertyContainer.Visibility = Visibility.Visible;
  207. }
  208. else
  209. {
  210. PropertyContainer.Child = null;
  211. PropertyContainer.Visibility = Visibility.Collapsed;
  212. }
  213. }
  214. }
  215. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  216. {
  217. ShowViewSettings();
  218. }
  219. private void ZoomInBtn_Click(object sender, RoutedEventArgs e)
  220. {
  221. if (pdfViewControl != null)
  222. {
  223. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  224. pdfViewControl.PDFView.Zoom(newZoom);
  225. }
  226. }
  227. private void ZoomOutBtn_Click(object sender, RoutedEventArgs e)
  228. {
  229. if (pdfViewControl != null)
  230. {
  231. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  232. pdfViewControl.PDFView.Zoom(newZoom);
  233. }
  234. }
  235. private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  236. {
  237. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex + 1);
  238. }
  239. private void PrevPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  240. {
  241. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex - 1);
  242. }
  243. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  244. {
  245. PasswordUI.Visibility = Visibility.Collapsed;
  246. FileInfoUI.Visibility = Visibility.Visible;
  247. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  248. PopupBorder.Visibility = Visibility.Visible;
  249. }
  250. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  251. {
  252. PopupBorder.Visibility = Visibility.Collapsed;
  253. }
  254. #endregion
  255. #region Open and save file
  256. /// <summary>
  257. /// Save the file to another PDF file.
  258. /// </summary>
  259. public void SaveAsFile()
  260. {
  261. {
  262. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  263. {
  264. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  265. SaveFileDialog saveDialog = new SaveFileDialog();
  266. saveDialog.Filter = "(*.pdf)|*.pdf";
  267. saveDialog.DefaultExt = ".pdf";
  268. saveDialog.OverwritePrompt = true;
  269. if (saveDialog.ShowDialog() == true)
  270. {
  271. pdfDoc.WriteToFilePath(saveDialog.FileName);
  272. }
  273. }
  274. }
  275. }
  276. private void SaveFile()
  277. {
  278. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  279. {
  280. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  281. if (pdfDoc.WriteToLoadedPath())
  282. {
  283. pdfViewControl.PDFView.UndoManager.CanSave = false;
  284. return;
  285. }
  286. SaveFileDialog saveDialog = new SaveFileDialog();
  287. saveDialog.Filter = "(*.pdf)|*.pdf";
  288. saveDialog.DefaultExt = ".pdf";
  289. saveDialog.OverwritePrompt = true;
  290. if (saveDialog.ShowDialog() == true)
  291. {
  292. if (pdfDoc.WriteToFilePath(saveDialog.FileName))
  293. {
  294. pdfViewControl.PDFView.UndoManager.CanSave = false;
  295. }
  296. }
  297. }
  298. }
  299. private void OpenFile()
  300. {
  301. string filePath = CommonHelper.GetExistedPathOrEmpty();
  302. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  303. {
  304. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  305. {
  306. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  307. if (oldFilePath.ToLower() == filePath.ToLower())
  308. {
  309. return;
  310. }
  311. }
  312. passwordViewer = new PDFViewControl();
  313. passwordViewer.PDFView.InitDocument(filePath);
  314. if (passwordViewer.PDFView.Document == null)
  315. {
  316. MessageBox.Show("Open File Failed");
  317. return;
  318. }
  319. if (passwordViewer.PDFView.Document.IsLocked)
  320. {
  321. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  322. PasswordUI.ClearPassword();
  323. PopupBorder.Visibility = Visibility.Visible;
  324. PasswordUI.Visibility = Visibility.Visible;
  325. }
  326. else
  327. {
  328. pdfViewControl.PDFView.Document.Release();
  329. pdfViewControl = passwordViewer;
  330. LoadDocument();
  331. }
  332. }
  333. }
  334. private void OpenFile_Click(object sender, RoutedEventArgs e)
  335. {
  336. OpenFile();
  337. }
  338. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  339. {
  340. SaveFile();
  341. }
  342. #endregion
  343. #region Context Menu
  344. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  345. {
  346. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  347. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  348. {
  349. string choosePath = folderDialog.SelectedPath;
  350. string openPath = choosePath;
  351. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  352. if (imageDict != null && imageDict.Count > 0)
  353. {
  354. foreach (int pageIndex in imageDict.Keys)
  355. {
  356. List<Bitmap> imageList = imageDict[pageIndex];
  357. foreach (Bitmap image in imageList)
  358. {
  359. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  360. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  361. openPath = savePath;
  362. }
  363. }
  364. }
  365. Process.Start("explorer", "/select,\"" + openPath + "\"");
  366. }
  367. }
  368. private void CopyImage_Click(object sender, RoutedEventArgs e)
  369. {
  370. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  371. if (imageDict != null && imageDict.Count > 0)
  372. {
  373. foreach (int pageIndex in imageDict.Keys)
  374. {
  375. List<Bitmap> imageList = imageDict[pageIndex];
  376. foreach (Bitmap image in imageList)
  377. {
  378. MemoryStream ms = new MemoryStream();
  379. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  380. BitmapImage imageData = new BitmapImage();
  381. imageData.BeginInit();
  382. imageData.StreamSource = ms;
  383. imageData.CacheOption = BitmapCacheOption.OnLoad;
  384. imageData.EndInit();
  385. imageData.Freeze();
  386. Clipboard.SetImage(imageData);
  387. break;
  388. }
  389. }
  390. }
  391. }
  392. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  393. {
  394. if (e != null && e.CommandType == CommandType.Context)
  395. {
  396. if (e.PressOnSelectedText)
  397. {
  398. e.Handle = true;
  399. e.PopupMenu = new ContextMenu();
  400. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  401. }
  402. else if (e.CommandTarget == TargetType.ImageSelection)
  403. {
  404. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  405. {
  406. e.Handle = true;
  407. e.PopupMenu = new ContextMenu();
  408. MenuItem imageCopyMenu = new MenuItem();
  409. imageCopyMenu = new MenuItem();
  410. imageCopyMenu.Header = "Copy Images";
  411. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  412. imageCopyMenu.CommandParameter = e;
  413. e.PopupMenu.Items.Add(imageCopyMenu);
  414. MenuItem imageExtraMenu = new MenuItem();
  415. imageExtraMenu = new MenuItem();
  416. imageExtraMenu.Header = "Extract Images";
  417. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  418. imageExtraMenu.CommandParameter = e;
  419. e.PopupMenu.Items.Add(imageExtraMenu);
  420. }
  421. }
  422. else
  423. {
  424. e.Handle = true;
  425. e.PopupMenu = new ContextMenu();
  426. //if (pdfViewControl.CheckHasForm())
  427. MenuItem fitWidthMenu = new MenuItem();
  428. fitWidthMenu.Header = "Automatically Resize";
  429. fitWidthMenu.Click += (o, p) =>
  430. {
  431. if (pdfViewControl != null)
  432. {
  433. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  434. }
  435. };
  436. e.PopupMenu.Items.Add(fitWidthMenu);
  437. MenuItem fitSizeMenu = new MenuItem();
  438. fitSizeMenu.Header = "Actual Size";
  439. fitSizeMenu.Click += (o, p) =>
  440. {
  441. if (pdfViewControl != null)
  442. {
  443. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  444. }
  445. };
  446. e.PopupMenu.Items.Add(fitSizeMenu);
  447. MenuItem zoomInMenu = new MenuItem();
  448. zoomInMenu.Header = "Zoom In";
  449. zoomInMenu.Click += (o, p) =>
  450. {
  451. if (pdfViewControl != null)
  452. {
  453. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  454. pdfViewControl.PDFView?.Zoom(newZoom);
  455. }
  456. };
  457. e.PopupMenu.Items.Add(zoomInMenu);
  458. MenuItem zoomOutMenu = new MenuItem();
  459. zoomOutMenu.Header = "Zoom Out";
  460. zoomOutMenu.Click += (o, p) =>
  461. {
  462. if (pdfViewControl != null)
  463. {
  464. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  465. pdfViewControl.PDFView?.Zoom(newZoom);
  466. }
  467. };
  468. e.PopupMenu.Items.Add(zoomOutMenu);
  469. e.PopupMenu.Items.Add(new Separator());
  470. MenuItem singleView = new MenuItem();
  471. singleView.Header = "Single Page";
  472. singleView.Click += (o, p) =>
  473. {
  474. if (pdfViewControl != null)
  475. {
  476. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  477. }
  478. };
  479. e.PopupMenu.Items.Add(singleView);
  480. MenuItem singleContinuousView = new MenuItem();
  481. singleContinuousView.Header = "Single Page Continuous";
  482. singleContinuousView.Click += (o, p) =>
  483. {
  484. if (pdfViewControl != null)
  485. {
  486. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  487. }
  488. };
  489. e.PopupMenu.Items.Add(singleContinuousView);
  490. MenuItem doubleView = new MenuItem();
  491. doubleView.Header = "Two Pages";
  492. doubleView.Click += (o, p) =>
  493. {
  494. if (pdfViewControl != null)
  495. {
  496. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  497. }
  498. };
  499. e.PopupMenu.Items.Add(doubleView);
  500. MenuItem doubleContinuousView = new MenuItem();
  501. doubleContinuousView.Header = "Two Pages Continuous";
  502. doubleContinuousView.Click += (o, p) =>
  503. {
  504. if (pdfViewControl != null)
  505. {
  506. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  507. }
  508. };
  509. e.PopupMenu.Items.Add(doubleContinuousView);
  510. {
  511. MenuItem resetForms = new MenuItem();
  512. resetForms.Header = "Reset Forms";
  513. resetForms.Click += (o, p) =>
  514. {
  515. if (pdfViewControl != null)
  516. {
  517. pdfViewControl.PDFView?.ResetForm(null);
  518. }
  519. };
  520. e.PopupMenu.Items.Add(new Separator());
  521. e.PopupMenu.Items.Add(resetForms);
  522. }
  523. }
  524. }
  525. if (e != null && e.CommandType == CommandType.Copy)
  526. {
  527. e.DoCommand();
  528. }
  529. }
  530. #endregion
  531. #region Close Window
  532. protected override void OnClosing(CancelEventArgs e)
  533. {
  534. if (pdfViewControl.PDFView.UndoManager.CanSave)
  535. {
  536. MessageBoxResult result = MessageBox.Show("Do you want to save your changes before closing the application?", "Message", MessageBoxButton.YesNoCancel);
  537. if (result == MessageBoxResult.Yes)
  538. {
  539. SaveFile();
  540. }
  541. else if (result == MessageBoxResult.No)
  542. {
  543. }
  544. else
  545. {
  546. e.Cancel = true;
  547. }
  548. }
  549. }
  550. #endregion
  551. #region PropertyChanged
  552. /// <summary>
  553. /// Zoom
  554. /// </summary>
  555. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  556. {
  557. if (e.Key == "Zoom")
  558. {
  559. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  560. }
  561. }
  562. /// <summary>
  563. /// Undo Redo Event Noitfy
  564. /// </summary>
  565. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  566. {
  567. OnPropertyChanged(e.PropertyName);
  568. }
  569. protected void OnPropertyChanged([CallerMemberName] string name = null)
  570. {
  571. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  572. }
  573. #endregion
  574. #region Shortcut
  575. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  576. {
  577. OpenFile();
  578. }
  579. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  580. {
  581. if (CanSave)
  582. {
  583. SaveFile();
  584. }
  585. }
  586. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  587. {
  588. SaveAsFile();
  589. }
  590. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  591. {
  592. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  593. ControlLeftPanel();
  594. }
  595. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  596. {
  597. ExpandLeftPanel(true);
  598. LeftToolPanelButton.IsChecked = true;
  599. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  600. }
  601. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  602. {
  603. ExpandLeftPanel(true);
  604. LeftToolPanelButton.IsChecked = true;
  605. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  606. }
  607. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  608. {
  609. ExpandLeftPanel(true);
  610. LeftToolPanelButton.IsChecked = true;
  611. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  612. }
  613. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  614. {
  615. ExpandLeftPanel(true);
  616. LeftToolPanelButton.IsChecked = true;
  617. BotaSideTool.SelectBotaTool(BOTATools.Search);
  618. }
  619. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  620. {
  621. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  622. pdfViewControl.PDFView?.Zoom(newZoom);
  623. }
  624. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  625. {
  626. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  627. pdfViewControl.PDFView?.Zoom(newZoom);
  628. }
  629. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  630. {
  631. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  632. ShowViewSettings();
  633. }
  634. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  635. {
  636. if (PopupBorder.Visibility != Visibility.Visible)
  637. {
  638. PasswordUI.Visibility = Visibility.Collapsed;
  639. FileInfoUI.Visibility = Visibility.Visible;
  640. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  641. PopupBorder.Visibility = Visibility.Visible;
  642. }
  643. else
  644. {
  645. FileInfoUI.Visibility = Visibility.Collapsed;
  646. PopupBorder.Visibility = Visibility.Collapsed;
  647. }
  648. }
  649. #endregion
  650. }
  651. }