MainWindow.xaml.cs 28 KB

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