ContentEditControl.xaml.cs 25 KB

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