ContentEditControl.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using ComPDFKit.Tool;
  5. using Compdfkit_Tools.Edit;
  6. using Compdfkit_Tools.Helper;
  7. using ComPDFKitViewer;
  8. using Microsoft.Win32;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Diagnostics;
  13. using System.Drawing;
  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;
  20. namespace Compdfkit_Tools.PDFControl
  21. {
  22. public partial class ContentEditControl : UserControl, INotifyPropertyChanged
  23. {
  24. #region Property
  25. public PDFViewControl PdfViewControl = new PDFViewControl();
  26. public PDFContentEditControl pdfContentEditControl = new PDFContentEditControl();
  27. private CPDFDisplaySettingsControl displaySettingsControl = null;
  28. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  29. private TextEditParam pdfTextCreateParam;
  30. private PDFEditParam lastPDFEditEvent = null;
  31. private PanelState panelState = PanelState.GetInstance();
  32. private KeyEventHandler KeyDownHandler;
  33. public event PropertyChangedEventHandler PropertyChanged;
  34. public ICommand CloseTabCommand;
  35. public ICommand ExpandPropertyPanelCommand;
  36. public bool CanUndo
  37. {
  38. get
  39. {
  40. try
  41. {
  42. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  43. {
  44. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  45. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  46. return pdfViewer.UndoManager.CanUndo;
  47. }
  48. }
  49. catch(Exception ex)
  50. {
  51. }
  52. return false;
  53. }
  54. }
  55. public bool CanRedo
  56. {
  57. get
  58. {
  59. try
  60. {
  61. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  62. {
  63. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  64. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  65. return pdfViewer.UndoManager.CanRedo;
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. }
  71. return false;
  72. }
  73. }
  74. private bool CanSave
  75. {
  76. get
  77. {
  78. try
  79. {
  80. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  81. {
  82. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  83. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  84. return (pdfViewer.UndoManager.CanUndo | pdfViewer.UndoManager.CanRedo);
  85. }
  86. }
  87. catch (Exception ex)
  88. {
  89. }
  90. return false;
  91. }
  92. }
  93. public event EventHandler<bool> OnCanSaveChanged;
  94. public event EventHandler OnAnnotEditHandler;
  95. #endregion
  96. public ContentEditControl()
  97. {
  98. InitializeComponent();
  99. panelState.PropertyChanged += PanelState_PropertyChanged;
  100. }
  101. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  102. {
  103. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  104. {
  105. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  106. }
  107. else if (e.PropertyName == nameof(PanelState.RightPanel))
  108. {
  109. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  110. {
  111. ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
  112. }
  113. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  114. {
  115. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  116. }
  117. else
  118. {
  119. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  120. }
  121. }
  122. }
  123. public void ClearPDFEditState(ToggleButton ignoreBtn = null)
  124. {
  125. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  126. {
  127. PDFTextEditButton,
  128. PDFImageEditButton
  129. };
  130. foreach (ToggleButton item in clearBtnList)
  131. {
  132. if (ignoreBtn == item)
  133. {
  134. continue;
  135. }
  136. item.IsChecked = false;
  137. }
  138. }
  139. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  140. {
  141. ToggleButton senderBtn = sender as ToggleButton;
  142. if (senderBtn != null && PdfViewControl != null)
  143. {
  144. ClearPDFEditState(senderBtn);
  145. if (senderBtn.IsChecked == true)
  146. {
  147. PDFEditEvent createParam = new PDFEditEvent();
  148. createParam.EditType = CPDFEditType.EditText;
  149. createParam.IsBold = false;
  150. createParam.IsItalic = false;
  151. createParam.FontSize = 14;
  152. createParam.FontName = "Helvetica";
  153. createParam.FontColor = Colors.Black;
  154. createParam.TextAlign = TextAlignType.AlignLeft;
  155. createParam.Transparency = 255;
  156. if (PdfViewControl.PDFView != null && PdfViewControl.PDFView.Document != null)
  157. {
  158. CPDFDocument pdfDoc = PdfViewControl.PDFView.Document;
  159. PdfViewControl.PDFView.ToolManager.EnableClickCreate = true;
  160. PdfViewControl.PDFView.ToolManager.ClickCreateWidth = 100;
  161. if (pdfDoc.PageCount > 0)
  162. {
  163. CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  164. CPDFEditPage editPage = pdfPage.GetEditPage();
  165. editPage.BeginEdit(CPDFEditType.EditText);
  166. createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  167. editPage.EndEdit();
  168. }
  169. }
  170. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  171. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  172. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  173. PdfViewControl.PDFView?.ReloadDocument();
  174. PdfViewControl.PDFView?.SetPDFEditParam(createParam);
  175. pdfContentEditControl.SetPDFTextEditData(createParam);
  176. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  177. pdfTextCreateParam = createParam;
  178. }
  179. else
  180. {
  181. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  182. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  183. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  184. PdfViewControl.PDFView?.ReloadDocument();
  185. pdfContentEditControl.ClearContentControl();
  186. panelState.RightPanel = PanelState.RightPanelState.None;
  187. }
  188. }
  189. }
  190. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  191. {
  192. ToggleButton senderBtn = sender as ToggleButton;
  193. if (senderBtn != null && PdfViewControl != null)
  194. {
  195. panelState.RightPanel = PanelState.RightPanelState.None;
  196. senderBtn.IsChecked = false;
  197. OpenFileDialog openFileDialog = new OpenFileDialog();
  198. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  199. if (openFileDialog.ShowDialog() == true)
  200. {
  201. ClearPDFEditState(senderBtn);
  202. PdfViewControl.PDFView?.ClearSelectPDFEdit();
  203. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  204. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  205. PdfViewControl.PDFView?.ReloadDocument();
  206. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  207. PdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  208. }
  209. }
  210. }
  211. public void ExpandLeftPanel(bool isExpand)
  212. {
  213. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  214. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  215. if (isExpand)
  216. {
  217. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  218. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  219. }
  220. else
  221. {
  222. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  223. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  224. }
  225. }
  226. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  227. {
  228. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  229. {
  230. PdfViewControl.PDFView.UndoManager?.Undo();
  231. }
  232. }
  233. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  234. {
  235. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  236. {
  237. PdfViewControl.PDFView.UndoManager?.Redo();
  238. }
  239. }
  240. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  241. {
  242. this.PropertyContainer.Child = displaySettingsControl;
  243. this.PropertyContainer.Visibility = visibility;
  244. }
  245. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  246. {
  247. this.BotaContainer.Child = botaControl;
  248. }
  249. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  250. {
  251. this.displaySettingsControl = displaySettingsControl;
  252. }
  253. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  254. {
  255. PdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  256. }
  257. private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
  258. {
  259. PdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  260. }
  261. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  262. {
  263. PropertyContainer.Width = 260;
  264. PropertyContainer.Child = propertytPanel;
  265. PropertyContainer.Visibility = visible;
  266. }
  267. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  268. {
  269. PdfViewControl.PDFView = pdfViewer;
  270. PDFGrid.Child = PdfViewControl;
  271. FloatPageTool.InitWithPDFViewer(pdfViewer);
  272. pdfContentEditControl.InitWithPDFViewer(pdfViewer);
  273. DataContext = this;
  274. }
  275. /// <summary>
  276. /// Text and Image Selected Event
  277. /// </summary>
  278. private void PDFView_PDFEditActiveHandler(object sender, PDFEditEvent e)
  279. {
  280. lastPDFEditEvent = e;
  281. if (e == null)
  282. {
  283. PropertyContainer.Child = pdfContentEditControl;
  284. if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  285. {
  286. if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  287. {
  288. pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
  289. }
  290. else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
  291. {
  292. pdfContentEditControl.ClearContentControl();
  293. }
  294. }
  295. else
  296. {
  297. pdfContentEditControl.ClearContentControl();
  298. }
  299. return;
  300. }
  301. if (e.EditType == CPDFEditType.EditText)
  302. {
  303. pdfContentEditControl.SetPDFTextEditData(e, true);
  304. return;
  305. }
  306. if (e.EditType == CPDFEditType.EditImage && PdfViewControl != null)
  307. {
  308. UIElement pageView = sender as UIElement;
  309. if (pageView != null)
  310. {
  311. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  312. }
  313. pdfContentEditControl.SetPDFImageEditData(e);
  314. return;
  315. }
  316. }
  317. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  318. {
  319. UIElement pageView = sender as UIElement;
  320. if (pageView != null)
  321. {
  322. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  323. }
  324. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  325. {
  326. pdfContentEditControl.SetPDFImageEditData(lastPDFEditEvent);
  327. }
  328. }
  329. public void ClearViewerControl()
  330. {
  331. PDFGrid.Child = null;
  332. BotaContainer.Child = null;
  333. PropertyContainer.Child = null;
  334. displaySettingsControl = null;
  335. }
  336. #region Property changed
  337. protected void OnPropertyChanged([CallerMemberName] string name = null)
  338. {
  339. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  340. }
  341. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  342. {
  343. OnPropertyChanged(e.PropertyName);
  344. if (e.PropertyName == "CanSave")
  345. {
  346. OnCanSaveChanged?.Invoke(this, CanSave);
  347. }
  348. }
  349. #endregion
  350. #region Context menu
  351. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  352. {
  353. if (e == null)
  354. {
  355. return;
  356. }
  357. if (e.EditType == CPDFEditType.EditText)
  358. {
  359. e.Handle = true;
  360. PDFEditTextContextMenu(sender, e);
  361. }
  362. if (e.EditType == CPDFEditType.EditImage)
  363. {
  364. e.Handle = true;
  365. PDFEditImageContextMenu(sender, e);
  366. }
  367. }
  368. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  369. {
  370. editCommand.PopupMenu = new ContextMenu();
  371. if (lastPDFEditEvent != null)
  372. {
  373. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  374. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  375. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  376. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  377. }
  378. else
  379. {
  380. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  381. if (editCommand.TextAreaCopied)
  382. {
  383. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  384. }
  385. }
  386. }
  387. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  388. {
  389. editCommand.PopupMenu = new ContextMenu();
  390. if (lastPDFEditEvent != null)
  391. {
  392. MenuItem rotateLeftMenu = new MenuItem();
  393. rotateLeftMenu.Header = "Left Rotate";
  394. rotateLeftMenu.Click += (o, p) =>
  395. {
  396. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  397. {
  398. lastPDFEditEvent.Rotate = -90;
  399. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  400. pdfContentEditControl.RefreshThumb();
  401. }
  402. };
  403. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  404. MenuItem rotateRightMenu = new MenuItem();
  405. rotateRightMenu.Header = "Right Rotate";
  406. rotateRightMenu.Click += (o, p) =>
  407. {
  408. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  409. {
  410. lastPDFEditEvent.Rotate = 90;
  411. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  412. pdfContentEditControl.RefreshThumb();
  413. }
  414. };
  415. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  416. MenuItem replaceMenu = new MenuItem();
  417. replaceMenu.Header = "Replace";
  418. replaceMenu.Click += (o, p) =>
  419. {
  420. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  421. {
  422. OpenFileDialog openFileDialog = new OpenFileDialog();
  423. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  424. if (openFileDialog.ShowDialog() == true)
  425. {
  426. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  427. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  428. PdfViewControl.PDFView?.ClearSelectPDFEdit();
  429. pdfContentEditControl.RefreshThumb();
  430. }
  431. }
  432. };
  433. editCommand.PopupMenu.Items.Add(replaceMenu);
  434. MenuItem exportMenu = new MenuItem();
  435. exportMenu.Header = "Export";
  436. exportMenu.Click += (o, p) =>
  437. {
  438. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  439. {
  440. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView.GetSelectedImages();
  441. if (imageDict != null && imageDict.Count > 0)
  442. {
  443. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  444. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  445. {
  446. string choosePath = folderBrowser.SelectedPath;
  447. string openPath = choosePath;
  448. foreach (int pageIndex in imageDict.Keys)
  449. {
  450. List<Bitmap> imageList = imageDict[pageIndex];
  451. foreach (Bitmap image in imageList)
  452. {
  453. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  454. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  455. openPath = savePath;
  456. }
  457. }
  458. Process.Start("explorer", "/select,\"" + openPath + "\"");
  459. }
  460. }
  461. }
  462. };
  463. editCommand.PopupMenu.Items.Add(exportMenu);
  464. MenuItem opacityMenu = new MenuItem();
  465. opacityMenu.Header = "Opacity";
  466. editCommand.PopupMenu.Items.Add(opacityMenu);
  467. AppendOpacityMenu(opacityMenu);
  468. MenuItem horizonMirror = new MenuItem();
  469. horizonMirror.Header = "HMirror";
  470. horizonMirror.Click += (o, p) =>
  471. {
  472. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  473. {
  474. lastPDFEditEvent.HorizontalMirror = true;
  475. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  476. }
  477. };
  478. editCommand.PopupMenu.Items.Add(horizonMirror);
  479. MenuItem verticalMirror = new MenuItem();
  480. verticalMirror.Header = "VMirror";
  481. verticalMirror.Click += (o, p) =>
  482. {
  483. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  484. {
  485. lastPDFEditEvent.VerticalMirror = true;
  486. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  487. }
  488. };
  489. editCommand.PopupMenu.Items.Add(verticalMirror);
  490. MenuItem cropMenu = new MenuItem();
  491. cropMenu.Header = "Crop";
  492. cropMenu.Click += (o, p) =>
  493. {
  494. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  495. {
  496. lastPDFEditEvent.ClipImage = true;
  497. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  498. }
  499. };
  500. editCommand.PopupMenu.Items.Add(cropMenu);
  501. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  502. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  503. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  504. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  505. if (editCommand.TextAreaCopied)
  506. {
  507. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  508. }
  509. }
  510. else
  511. {
  512. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  513. }
  514. }
  515. private void AppendOpacityMenu(MenuItem parentMenu)
  516. {
  517. List<int> opacityList = new List<int>()
  518. {
  519. 25,50,75,100
  520. };
  521. foreach (int opacity in opacityList)
  522. {
  523. MenuItem opacityMenu = new MenuItem();
  524. opacityMenu.Header = string.Format("{0}%", opacity);
  525. opacityMenu.Click += (o, p) =>
  526. {
  527. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  528. {
  529. lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
  530. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  531. }
  532. };
  533. parentMenu.Items.Add(opacityMenu);
  534. }
  535. }
  536. #endregion
  537. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  538. {
  539. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  540. {
  541. PdfViewControl.PDFView.UndoManager?.Undo();
  542. }
  543. }
  544. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  545. {
  546. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanRedo)
  547. {
  548. PdfViewControl.PDFView.UndoManager?.Redo();
  549. }
  550. }
  551. }
  552. }