MainWindow.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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 = passwordViewer;
  329. LoadDocument();
  330. }
  331. }
  332. }
  333. private void OpenFile_Click(object sender, RoutedEventArgs e)
  334. {
  335. OpenFile();
  336. }
  337. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  338. {
  339. SaveFile();
  340. }
  341. #endregion
  342. #region Context Menu
  343. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  344. {
  345. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  346. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  347. {
  348. string choosePath = folderDialog.SelectedPath;
  349. string openPath = choosePath;
  350. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  351. if (imageDict != null && imageDict.Count > 0)
  352. {
  353. foreach (int pageIndex in imageDict.Keys)
  354. {
  355. List<Bitmap> imageList = imageDict[pageIndex];
  356. foreach (Bitmap image in imageList)
  357. {
  358. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  359. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  360. openPath = savePath;
  361. }
  362. }
  363. }
  364. Process.Start("explorer", "/select,\"" + openPath + "\"");
  365. }
  366. }
  367. private void CopyImage_Click(object sender, RoutedEventArgs e)
  368. {
  369. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  370. if (imageDict != null && imageDict.Count > 0)
  371. {
  372. foreach (int pageIndex in imageDict.Keys)
  373. {
  374. List<Bitmap> imageList = imageDict[pageIndex];
  375. foreach (Bitmap image in imageList)
  376. {
  377. MemoryStream ms = new MemoryStream();
  378. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  379. BitmapImage imageData = new BitmapImage();
  380. imageData.BeginInit();
  381. imageData.StreamSource = ms;
  382. imageData.CacheOption = BitmapCacheOption.OnLoad;
  383. imageData.EndInit();
  384. imageData.Freeze();
  385. Clipboard.SetImage(imageData);
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  392. {
  393. if (e != null && e.CommandType == CommandType.Context)
  394. {
  395. if (e.PressOnSelectedText)
  396. {
  397. e.Handle = true;
  398. e.PopupMenu = new ContextMenu();
  399. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  400. }
  401. else if (e.CommandTarget == TargetType.ImageSelection)
  402. {
  403. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  404. {
  405. e.Handle = true;
  406. e.PopupMenu = new ContextMenu();
  407. MenuItem imageCopyMenu = new MenuItem();
  408. imageCopyMenu = new MenuItem();
  409. imageCopyMenu.Header = "Copy Images";
  410. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  411. imageCopyMenu.CommandParameter = e;
  412. e.PopupMenu.Items.Add(imageCopyMenu);
  413. MenuItem imageExtraMenu = new MenuItem();
  414. imageExtraMenu = new MenuItem();
  415. imageExtraMenu.Header = "Extract Images";
  416. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  417. imageExtraMenu.CommandParameter = e;
  418. e.PopupMenu.Items.Add(imageExtraMenu);
  419. }
  420. }
  421. else
  422. {
  423. e.Handle = true;
  424. e.PopupMenu = new ContextMenu();
  425. //if (pdfViewControl.CheckHasForm())
  426. MenuItem fitWidthMenu = new MenuItem();
  427. fitWidthMenu.Header = "Automatically Resize";
  428. fitWidthMenu.Click += (o, p) =>
  429. {
  430. if (pdfViewControl != null)
  431. {
  432. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  433. }
  434. };
  435. e.PopupMenu.Items.Add(fitWidthMenu);
  436. MenuItem fitSizeMenu = new MenuItem();
  437. fitSizeMenu.Header = "Actual Size";
  438. fitSizeMenu.Click += (o, p) =>
  439. {
  440. if (pdfViewControl != null)
  441. {
  442. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  443. }
  444. };
  445. e.PopupMenu.Items.Add(fitSizeMenu);
  446. MenuItem zoomInMenu = new MenuItem();
  447. zoomInMenu.Header = "Zoom In";
  448. zoomInMenu.Click += (o, p) =>
  449. {
  450. if (pdfViewControl != null)
  451. {
  452. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  453. pdfViewControl.PDFView?.Zoom(newZoom);
  454. }
  455. };
  456. e.PopupMenu.Items.Add(zoomInMenu);
  457. MenuItem zoomOutMenu = new MenuItem();
  458. zoomOutMenu.Header = "Zoom Out";
  459. zoomOutMenu.Click += (o, p) =>
  460. {
  461. if (pdfViewControl != null)
  462. {
  463. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  464. pdfViewControl.PDFView?.Zoom(newZoom);
  465. }
  466. };
  467. e.PopupMenu.Items.Add(zoomOutMenu);
  468. e.PopupMenu.Items.Add(new Separator());
  469. MenuItem singleView = new MenuItem();
  470. singleView.Header = "Single Page";
  471. singleView.Click += (o, p) =>
  472. {
  473. if (pdfViewControl != null)
  474. {
  475. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  476. }
  477. };
  478. e.PopupMenu.Items.Add(singleView);
  479. MenuItem singleContinuousView = new MenuItem();
  480. singleContinuousView.Header = "Single Page Continuous";
  481. singleContinuousView.Click += (o, p) =>
  482. {
  483. if (pdfViewControl != null)
  484. {
  485. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  486. }
  487. };
  488. e.PopupMenu.Items.Add(singleContinuousView);
  489. MenuItem doubleView = new MenuItem();
  490. doubleView.Header = "Two Pages";
  491. doubleView.Click += (o, p) =>
  492. {
  493. if (pdfViewControl != null)
  494. {
  495. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  496. }
  497. };
  498. e.PopupMenu.Items.Add(doubleView);
  499. MenuItem doubleContinuousView = new MenuItem();
  500. doubleContinuousView.Header = "Two Pages Continuous";
  501. doubleContinuousView.Click += (o, p) =>
  502. {
  503. if (pdfViewControl != null)
  504. {
  505. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  506. }
  507. };
  508. e.PopupMenu.Items.Add(doubleContinuousView);
  509. {
  510. MenuItem resetForms = new MenuItem();
  511. resetForms.Header = "Reset Forms";
  512. resetForms.Click += (o, p) =>
  513. {
  514. if (pdfViewControl != null)
  515. {
  516. pdfViewControl.PDFView?.ResetForm(null);
  517. }
  518. };
  519. e.PopupMenu.Items.Add(new Separator());
  520. e.PopupMenu.Items.Add(resetForms);
  521. }
  522. }
  523. }
  524. if (e != null && e.CommandType == CommandType.Copy)
  525. {
  526. e.DoCommand();
  527. }
  528. }
  529. #endregion
  530. #region Close Window
  531. protected override void OnClosing(CancelEventArgs e)
  532. {
  533. if (pdfViewControl.PDFView.UndoManager.CanSave)
  534. {
  535. MessageBoxResult result = MessageBox.Show("Do you want to save your changes before closing the application?", "Message", MessageBoxButton.YesNoCancel);
  536. if (result == MessageBoxResult.Yes)
  537. {
  538. SaveFile();
  539. }
  540. else if (result == MessageBoxResult.No)
  541. {
  542. }
  543. else
  544. {
  545. e.Cancel = true;
  546. }
  547. }
  548. }
  549. #endregion
  550. #region PropertyChanged
  551. /// <summary>
  552. /// Zoom
  553. /// </summary>
  554. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  555. {
  556. if (e.Key == "Zoom")
  557. {
  558. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  559. }
  560. }
  561. /// <summary>
  562. /// Undo Redo Event Noitfy
  563. /// </summary>
  564. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  565. {
  566. OnPropertyChanged(e.PropertyName);
  567. }
  568. protected void OnPropertyChanged([CallerMemberName] string name = null)
  569. {
  570. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  571. }
  572. #endregion
  573. #region Shortcut
  574. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  575. {
  576. OpenFile();
  577. }
  578. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  579. {
  580. if (CanSave)
  581. {
  582. SaveFile();
  583. }
  584. }
  585. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  586. {
  587. SaveAsFile();
  588. }
  589. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  590. {
  591. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  592. ControlLeftPanel();
  593. }
  594. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  595. {
  596. ExpandLeftPanel(true);
  597. LeftToolPanelButton.IsChecked = true;
  598. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  599. }
  600. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  601. {
  602. ExpandLeftPanel(true);
  603. LeftToolPanelButton.IsChecked = true;
  604. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  605. }
  606. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  607. {
  608. ExpandLeftPanel(true);
  609. LeftToolPanelButton.IsChecked = true;
  610. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  611. }
  612. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  613. {
  614. ExpandLeftPanel(true);
  615. LeftToolPanelButton.IsChecked = true;
  616. BotaSideTool.SelectBotaTool(BOTATools.Search);
  617. }
  618. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  619. {
  620. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  621. pdfViewControl.PDFView?.Zoom(newZoom);
  622. }
  623. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  624. {
  625. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  626. pdfViewControl.PDFView?.Zoom(newZoom);
  627. }
  628. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  629. {
  630. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  631. ShowViewSettings();
  632. }
  633. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  634. {
  635. if (PopupBorder.Visibility != Visibility.Visible)
  636. {
  637. PasswordUI.Visibility = Visibility.Collapsed;
  638. FileInfoUI.Visibility = Visibility.Visible;
  639. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  640. PopupBorder.Visibility = Visibility.Visible;
  641. }
  642. else
  643. {
  644. FileInfoUI.Visibility = Visibility.Collapsed;
  645. PopupBorder.Visibility = Visibility.Collapsed;
  646. }
  647. }
  648. #endregion
  649. private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  650. {
  651. }
  652. }
  653. }