AnnotationControl.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. using System.Windows.Controls;
  2. using Compdfkit_Tools.Data;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Win32;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Runtime.CompilerServices;
  14. using System.Windows;
  15. using System.Windows.Controls.Primitives;
  16. using System.Windows.Input;
  17. using System.Windows.Media.Imaging;
  18. namespace Compdfkit_Tools.PDFControl
  19. {
  20. public partial class AnnotationControl : UserControl, INotifyPropertyChanged
  21. {
  22. #region Property
  23. private bool isFirstLoad = true;
  24. public PDFViewControl PdfViewControl;
  25. public CPDFAnnotationControl PDFAnnotationControl = null;
  26. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  27. public event PropertyChangedEventHandler PropertyChanged;
  28. public ICommand CloseTabCommand;
  29. public ICommand ExpandPropertyPanelCommand;
  30. public bool CanUndo
  31. {
  32. get
  33. {
  34. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  35. {
  36. return PdfViewControl.PDFView.UndoManager.CanUndo;
  37. }
  38. return false;
  39. }
  40. }
  41. public bool CanRedo
  42. {
  43. get
  44. {
  45. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  46. {
  47. return PdfViewControl.PDFView.UndoManager.CanRedo;
  48. }
  49. return false;
  50. }
  51. }
  52. private bool CanSave
  53. {
  54. get
  55. {
  56. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  57. {
  58. return PdfViewControl.PDFView.UndoManager.CanSave;
  59. }
  60. return false;
  61. }
  62. }
  63. public event EventHandler<bool> OnCanSaveChanged;
  64. public event EventHandler OnAnnotEditHandler;
  65. #endregion
  66. public AnnotationControl()
  67. {
  68. InitializeComponent();
  69. DataContext = this;
  70. PDFAnnotationControl = new CPDFAnnotationControl();
  71. }
  72. #region Init PDFViewer
  73. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  74. {
  75. PdfViewControl.PDFView = pdfViewer;
  76. PDFGrid.Child = PdfViewControl;
  77. FloatPageTool.InitWithPDFViewer(pdfViewer);
  78. DataContext = this;
  79. }
  80. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  81. {
  82. this.BotaContainer.Child = botaControl;
  83. }
  84. public void ClearAllToolState()
  85. {
  86. this.AnnotationBarControl.ClearAllToolState();
  87. }
  88. public void SetToolBarContainerVisibility(Visibility visibility)
  89. {
  90. this.ToolBarContainer.Visibility = visibility;
  91. }
  92. #endregion
  93. #region Load Unload custom control
  94. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  95. {
  96. InitialPDFViewControl(PdfViewControl);
  97. }
  98. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  99. {
  100. if (isFirstLoad)
  101. {
  102. CPDFAnnotationType[] annotationProperties =
  103. {
  104. CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout,
  105. CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText,
  106. CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square,
  107. CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image,
  108. CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link,
  109. CPDFAnnotationType.Audio
  110. };
  111. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  112. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  113. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  114. isFirstLoad = false;
  115. }
  116. }
  117. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  118. {
  119. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  120. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  121. }
  122. #endregion
  123. #region Annotation
  124. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  125. {
  126. PDFAnnotationControl.SetPDFViewer(newPDFViewer.PDFView);
  127. PDFAnnotationControl.AnnotationCancel();
  128. AnnotationBarControl.ClearAllToolState();
  129. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  130. PDFAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  131. PdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  132. PdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  133. PdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  134. PdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  135. PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  136. PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  137. PdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  138. PdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  139. }
  140. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  141. {
  142. AnnotationBarControl.ClearAllToolState();
  143. }
  144. public void SetViewSettings(Visibility visibility ,CPDFDisplaySettingsControl displaySettingsControl = null)
  145. {
  146. this.PropertyContainer.Child = displaySettingsControl;
  147. this.PropertyContainer.Visibility = visibility;
  148. }
  149. #endregion
  150. #region Expand and collapse Panel
  151. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  152. {
  153. PropertyContainer.Width = 260;
  154. PropertyContainer.Child = propertytPanel;
  155. PropertyContainer.Visibility = visible;
  156. if (visible == Visibility.Collapsed || visible == Visibility.Hidden)
  157. {
  158. //RightPanelButton.IsChecked = false;
  159. }
  160. }
  161. public void ExpandLeftPanel(bool isExpand)
  162. {
  163. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  164. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  165. if (isExpand)
  166. {
  167. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  168. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  169. }
  170. else
  171. {
  172. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  173. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  174. }
  175. }
  176. #endregion
  177. #region Context menu
  178. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  179. {
  180. switch (e.CommandType)
  181. {
  182. case CommandType.Context:
  183. e.Handle = true;
  184. if (e.CommandTarget == TargetType.Annot)
  185. {
  186. e.Handle = true;
  187. e.PopupMenu = new ContextMenu();
  188. if (e.PressOnLink && AnnotationBarControl.CurrentMode == "Link")
  189. {
  190. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  191. MenuItem propertyMenu = new MenuItem();
  192. propertyMenu = new MenuItem();
  193. propertyMenu.Header = "Edit";
  194. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
  195. propertyMenu.CommandParameter = e;
  196. e.PopupMenu.Items.Add(propertyMenu);
  197. }
  198. else if (e.PressOnAnnot)
  199. {
  200. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  201. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  202. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  203. }
  204. else if (e.PressOnMedia || e.PressOnSound)
  205. {
  206. e.Handle = true;
  207. e.PopupMenu.Items.Add(new MenuItem() { Header = "Play", Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = e });
  208. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  209. }
  210. else if (e.PressOnSelectedText)
  211. {
  212. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  213. MenuItem highLightMenu = new MenuItem();
  214. highLightMenu.Header = "HighLight";
  215. highLightMenu.Click += (o, p) =>
  216. {
  217. TextHighlightAnnotArgs highLightArgs = new TextHighlightAnnotArgs();
  218. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  219. if (PDFAnnotationControl != null)
  220. {
  221. highLightArgs.Color = System.Windows.Media.Colors.Red;
  222. highLightArgs.Transparency = 1;
  223. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  224. PdfViewControl.PDFView.SetToolParam(highLightArgs);
  225. PdfViewControl.PDFView.SetMouseMode(oldMode);
  226. }
  227. };
  228. e.PopupMenu.Items.Add(highLightMenu);
  229. MenuItem underlineMenu = new MenuItem();
  230. underlineMenu.Header = "UnderLine";
  231. underlineMenu.Click += (o, p) =>
  232. {
  233. TextUnderlineAnnotArgs underlineArgs = new TextUnderlineAnnotArgs();
  234. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  235. if (PDFAnnotationControl != null)
  236. {
  237. underlineArgs.Color = System.Windows.Media.Colors.Red;
  238. underlineArgs.Transparency = 1;
  239. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  240. PdfViewControl.PDFView.SetToolParam(underlineArgs);
  241. PdfViewControl.PDFView.SetMouseMode(oldMode);
  242. }
  243. };
  244. e.PopupMenu.Items.Add(underlineMenu);
  245. MenuItem strikeOutMenu = new MenuItem();
  246. strikeOutMenu.Header = "StrikeOut";
  247. strikeOutMenu.Click += (o, p) =>
  248. {
  249. TextStrikeoutAnnotArgs strikeoutAnnotArgs = new TextStrikeoutAnnotArgs();
  250. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  251. if (PDFAnnotationControl != null)
  252. {
  253. strikeoutAnnotArgs.Color = System.Windows.Media.Colors.Red;
  254. strikeoutAnnotArgs.Transparency = 1;
  255. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  256. PdfViewControl.PDFView.SetToolParam(strikeoutAnnotArgs);
  257. PdfViewControl.PDFView.SetMouseMode(oldMode);
  258. }
  259. };
  260. e.PopupMenu.Items.Add(strikeOutMenu);
  261. MenuItem SquiggleMenu = new MenuItem();
  262. SquiggleMenu.Header = "Squiggle";
  263. SquiggleMenu.Click += (o, p) =>
  264. {
  265. TextSquigglyAnnotArgs squigglyAnnotArgs = new TextSquigglyAnnotArgs();
  266. MouseModes oldMode = PdfViewControl.PDFView.MouseMode;
  267. if (PDFAnnotationControl != null)
  268. {
  269. squigglyAnnotArgs.Color = System.Windows.Media.Colors.Red;
  270. squigglyAnnotArgs.Transparency = 1;
  271. PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
  272. PdfViewControl.PDFView.SetToolParam(squigglyAnnotArgs);
  273. PdfViewControl.PDFView.SetMouseMode(oldMode);
  274. }
  275. };
  276. e.PopupMenu.Items.Add(SquiggleMenu);
  277. }
  278. else
  279. {
  280. e.Handle = true;
  281. e.PopupMenu = new ContextMenu();
  282. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  283. e.PopupMenu.Items.Add(new Separator());
  284. MenuItem fitWidthMenu = new MenuItem();
  285. fitWidthMenu.Header = "Automatically Resize";
  286. fitWidthMenu.Click += (o, p) =>
  287. {
  288. if (PdfViewControl != null)
  289. {
  290. PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  291. }
  292. };
  293. e.PopupMenu.Items.Add(fitWidthMenu);
  294. MenuItem fitSizeMenu = new MenuItem();
  295. fitSizeMenu.Header = "Actual Size";
  296. fitSizeMenu.Click += (o, p) =>
  297. {
  298. if (PdfViewControl != null)
  299. {
  300. PdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  301. }
  302. };
  303. e.PopupMenu.Items.Add(fitSizeMenu);
  304. MenuItem zoomInMenu = new MenuItem();
  305. zoomInMenu.Header = "Zoom In";
  306. zoomInMenu.Click += (o, p) =>
  307. {
  308. if (PdfViewControl != null)
  309. {
  310. double newZoom = CheckZoomLevel(PdfViewControl.PDFView.ZoomFactor + 0.01, true);
  311. PdfViewControl.PDFView?.Zoom(newZoom);
  312. }
  313. };
  314. e.PopupMenu.Items.Add(zoomInMenu);
  315. MenuItem zoomOutMenu = new MenuItem();
  316. zoomOutMenu.Header = "Zoom Out";
  317. zoomOutMenu.Click += (o, p) =>
  318. {
  319. if (PdfViewControl != null)
  320. {
  321. double newZoom = CheckZoomLevel(PdfViewControl.PDFView.ZoomFactor - 0.01, false);
  322. PdfViewControl.PDFView?.Zoom(newZoom);
  323. }
  324. };
  325. e.PopupMenu.Items.Add(zoomOutMenu);
  326. e.PopupMenu.Items.Add(new Separator());
  327. MenuItem singleView = new MenuItem();
  328. singleView.Header = "Single Page";
  329. singleView.Click += (o, p) =>
  330. {
  331. if (PdfViewControl != null)
  332. {
  333. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  334. }
  335. };
  336. e.PopupMenu.Items.Add(singleView);
  337. MenuItem singleContinuousView = new MenuItem();
  338. singleContinuousView.Header = "Single Page Continuous";
  339. singleContinuousView.Click += (o, p) =>
  340. {
  341. if (PdfViewControl != null)
  342. {
  343. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  344. }
  345. };
  346. e.PopupMenu.Items.Add(singleContinuousView);
  347. MenuItem doubleView = new MenuItem();
  348. doubleView.Header = "Two Pages";
  349. doubleView.Click += (o, p) =>
  350. {
  351. if (PdfViewControl != null)
  352. {
  353. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  354. }
  355. };
  356. e.PopupMenu.Items.Add(doubleView);
  357. MenuItem doubleContinuousView = new MenuItem();
  358. doubleContinuousView.Header = "Two Pages Continuous";
  359. doubleContinuousView.Click += (o, p) =>
  360. {
  361. if (PdfViewControl != null)
  362. {
  363. PdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  364. }
  365. };
  366. e.PopupMenu.Items.Add(doubleContinuousView);
  367. }
  368. }
  369. else if (e.CommandTarget == TargetType.ImageSelection)
  370. {
  371. if (PdfViewControl != null && PdfViewControl.PDFView != null && PdfViewControl.PDFView.GetSelectImageCount() > 0)
  372. {
  373. e.Handle = true;
  374. e.PopupMenu = new ContextMenu();
  375. MenuItem imageCopyMenu = new MenuItem();
  376. imageCopyMenu = new MenuItem();
  377. imageCopyMenu.Header = "Copy Images";
  378. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  379. imageCopyMenu.CommandParameter = e;
  380. e.PopupMenu.Items.Add(imageCopyMenu);
  381. MenuItem imageExtraMenu = new MenuItem();
  382. imageExtraMenu = new MenuItem();
  383. imageExtraMenu.Header = "Extract Images";
  384. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  385. imageExtraMenu.CommandParameter = e;
  386. e.PopupMenu.Items.Add(imageExtraMenu);
  387. }
  388. }
  389. break;
  390. case CommandType.Copy:
  391. e.DoCommand();
  392. break;
  393. case CommandType.Cut:
  394. case CommandType.Paste:
  395. case CommandType.Delete:
  396. e.DoCommand();
  397. break;
  398. default:
  399. break;
  400. }
  401. }
  402. private void CopyImage_Click(object sender, RoutedEventArgs e)
  403. {
  404. try
  405. {
  406. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView?.GetSelectedImages();
  407. if (imageDict != null && imageDict.Count > 0)
  408. {
  409. foreach (int pageIndex in imageDict.Keys)
  410. {
  411. List<Bitmap> imageList = imageDict[pageIndex];
  412. foreach (Bitmap image in imageList)
  413. {
  414. MemoryStream ms = new MemoryStream();
  415. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  416. BitmapImage imageData = new BitmapImage();
  417. imageData.BeginInit();
  418. imageData.StreamSource = ms;
  419. imageData.CacheOption = BitmapCacheOption.OnLoad;
  420. imageData.EndInit();
  421. imageData.Freeze();
  422. Clipboard.SetImage(imageData);
  423. break;
  424. }
  425. }
  426. }
  427. }
  428. catch (Exception ex)
  429. {
  430. }
  431. }
  432. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  433. {
  434. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  435. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  436. {
  437. string choosePath = folderDialog.SelectedPath;
  438. string openPath = choosePath;
  439. try
  440. {
  441. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView?.GetSelectedImages();
  442. if (imageDict != null && imageDict.Count > 0)
  443. {
  444. foreach (int pageIndex in imageDict.Keys)
  445. {
  446. List<Bitmap> imageList = imageDict[pageIndex];
  447. foreach (Bitmap image in imageList)
  448. {
  449. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  450. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  451. openPath = savePath;
  452. }
  453. }
  454. }
  455. Process.Start("explorer", "/select,\"" + openPath + "\"");
  456. }
  457. catch (Exception ex)
  458. {
  459. }
  460. }
  461. }
  462. #endregion
  463. #region UI
  464. private double CheckZoomLevel(double zoom, bool IsGrowth)
  465. {
  466. double standardZoom = 100;
  467. if (zoom <= 0.01)
  468. {
  469. return 0.01;
  470. }
  471. if (zoom >= 10)
  472. {
  473. return 10;
  474. }
  475. zoom *= 100;
  476. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  477. {
  478. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  479. {
  480. standardZoom = zoomLevelList[i + 1];
  481. break;
  482. }
  483. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  484. {
  485. standardZoom = zoomLevelList[i];
  486. break;
  487. }
  488. }
  489. return standardZoom / 100;
  490. }
  491. private void ToolExpand_Click(object sender, RoutedEventArgs e)
  492. {
  493. ToggleButton expandBtn = sender as ToggleButton;
  494. if (expandBtn != null)
  495. {
  496. bool isExpand = expandBtn.IsChecked == true;
  497. ExpandLeftPanel(isExpand);
  498. }
  499. }
  500. private void EditLink_Click(object sender, RoutedEventArgs e)
  501. {
  502. PropertyContainer.Visibility = Visibility.Visible;
  503. }
  504. private void UndoButton_Click(object sender, RoutedEventArgs e)
  505. {
  506. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  507. {
  508. PdfViewControl.PDFView.UndoManager?.Undo();
  509. }
  510. }
  511. private void RedoButton_Click(object sender, RoutedEventArgs e)
  512. {
  513. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  514. {
  515. PdfViewControl.PDFView.UndoManager?.Redo();
  516. }
  517. }
  518. #endregion
  519. #region Property changed
  520. protected void OnPropertyChanged([CallerMemberName] string name = null)
  521. {
  522. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  523. }
  524. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  525. {
  526. OnPropertyChanged(e.PropertyName);
  527. if (e.PropertyName == "CanSave")
  528. {
  529. OnCanSaveChanged?.Invoke(this, CanSave);
  530. }
  531. }
  532. #endregion
  533. #region Event handle
  534. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  535. {
  536. PDFAnnotationControl.AnnotationCancel();
  537. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  538. //AnnotationBarBtn.IsChecked = false;
  539. //ViewSettingBtn.IsChecked = false;
  540. }
  541. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  542. {
  543. PDFAnnotationControl.LoadAnnotationPanel(e);
  544. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  545. {
  546. ExpandRightPropertyPanel(PDFAnnotationControl, Visibility.Visible);
  547. //AnnotationBarBtn.IsChecked = true;
  548. }
  549. }
  550. private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  551. {
  552. PropertyContainer.Child = PDFAnnotationControl;
  553. PDFAnnotationControl.SetAnnotEventData(e);
  554. }
  555. private void PDFView_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  556. {
  557. //BotaSideTool.LoadAnnotationList();
  558. OnAnnotEditHandler.Invoke(this, null);
  559. }
  560. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  561. {
  562. if (e.Key == "Zoom")
  563. {
  564. //CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  565. }
  566. }
  567. #endregion
  568. public void ClearViewerControl()
  569. {
  570. PDFGrid.Child = null;
  571. BotaContainer.Child = null;
  572. }
  573. }
  574. }