MainWindow.xaml.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using Compdfkit_Tools.Edit;
  5. using Compdfkit_Tools.Helper;
  6. using Compdfkit_Tools.PDFControl;
  7. using ComPDFKitViewer;
  8. using ComPDFKitViewer.AnnotEvent;
  9. using ComPDFKitViewer.PdfViewer;
  10. using Microsoft.Win32;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Diagnostics;
  15. using System.Drawing;
  16. using System.IO;
  17. using System.Runtime.CompilerServices;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Controls.Primitives;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using Point = System.Windows.Point;
  25. namespace ContentEditor
  26. {
  27. public partial class MainWindow : Window, INotifyPropertyChanged
  28. {
  29. #region Property
  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. public 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. /// <summary>
  64. /// The last PDF edit object
  65. /// </summary>
  66. private PDFEditEvent lastPDFEditEvent = null;
  67. private PDFViewControl passwordViewer;
  68. private PDFViewControl pdfViewControl;
  69. private PDFImageEditControl imageEditControl = new PDFImageEditControl();
  70. private PDFTextEditControl textEditControl = new PDFTextEditControl();
  71. private Border empytPanel = new Border();
  72. private UIElement prevPanel = null;
  73. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  74. public event PropertyChangedEventHandler PropertyChanged;
  75. private PDFEditEvent pdfTextCreateParam;
  76. private KeyEventHandler KeyDownHandler;
  77. #endregion
  78. public MainWindow()
  79. {
  80. InitializeComponent();
  81. Loaded += MainWindow_Loaded;
  82. DataContext = this;
  83. }
  84. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  85. {
  86. TextBlock emptyBlock = new TextBlock();
  87. emptyBlock.HorizontalAlignment = HorizontalAlignment.Center;
  88. emptyBlock.VerticalAlignment = VerticalAlignment.Center;
  89. empytPanel.Child = emptyBlock;
  90. empytPanel.Width = 260;
  91. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search);
  92. LoadDefaultDocument();
  93. }
  94. #region Load document
  95. private void LoadDocument()
  96. {
  97. pdfViewControl.PDFView?.Load();
  98. PDFGrid.Child = pdfViewControl;
  99. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  100. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  101. PasswordUI.Closed -= PasswordUI_Closed;
  102. PasswordUI.Canceled -= PasswordUI_Canceled;
  103. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  104. PasswordUI.Closed += PasswordUI_Closed;
  105. PasswordUI.Canceled += PasswordUI_Canceled;
  106. PasswordUI.Confirmed += PasswordUI_Confirmed;
  107. pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  108. pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  109. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  110. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  111. pdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  112. pdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  113. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  114. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  115. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  116. pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
  117. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  118. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  119. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  120. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  121. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  122. ViewSettingBtn.IsChecked = false;
  123. PropertyContainer.Child = null;
  124. PropertyContainer.Visibility = Visibility.Collapsed;
  125. SetEditMode();
  126. if (KeyDownHandler != null)
  127. {
  128. pdfViewControl.PDFView.RemoveHandler(KeyDownEvent, KeyDownHandler);
  129. }
  130. KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
  131. pdfViewControl.PDFView.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
  132. }
  133. private void LoadDefaultDocument()
  134. {
  135. string defaultFilePath = "PDF32000_2008.pdf";
  136. pdfViewControl = new PDFViewControl();
  137. pdfViewControl.PDFView.InitDocument(defaultFilePath);
  138. LoadDocument();
  139. }
  140. #endregion
  141. #region Password
  142. private void PasswordUI_Confirmed(object sender, string e)
  143. {
  144. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  145. {
  146. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  147. if (passwordViewer.PDFView.Document.IsLocked == false)
  148. {
  149. PasswordUI.SetShowError("", Visibility.Collapsed);
  150. PasswordUI.ClearPassword();
  151. PasswordUI.Visibility = Visibility.Collapsed;
  152. PopupBorder.Visibility = Visibility.Collapsed;
  153. pdfViewControl = passwordViewer;
  154. LoadDocument();
  155. }
  156. else
  157. {
  158. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  159. }
  160. }
  161. }
  162. private void PasswordUI_Canceled(object sender, EventArgs e)
  163. {
  164. PopupBorder.Visibility = Visibility.Collapsed;
  165. PasswordUI.Visibility = Visibility.Collapsed;
  166. }
  167. private void PasswordUI_Closed(object sender, EventArgs e)
  168. {
  169. PopupBorder.Visibility = Visibility.Collapsed;
  170. PasswordUI.Visibility = Visibility.Collapsed;
  171. }
  172. #endregion
  173. #region Expand and collapse Panel
  174. private void ExpandLeftPanel(bool isExpand)
  175. {
  176. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  177. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  178. if (isExpand)
  179. {
  180. BodyGrid.ColumnDefinitions[0].Width = new GridLength(260);
  181. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  182. }
  183. else
  184. {
  185. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  186. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  187. }
  188. }
  189. #endregion
  190. #region Context menu
  191. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  192. {
  193. if (e != null && e.CommandType == CommandType.Context)
  194. {
  195. if (e.PressOnSelectedText)
  196. {
  197. e.Handle = true;
  198. e.PopupMenu = new ContextMenu();
  199. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  200. }
  201. else if (e.CommandTarget == TargetType.ImageSelection)
  202. {
  203. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  204. {
  205. e.Handle = true;
  206. e.PopupMenu = new ContextMenu();
  207. MenuItem imageCopyMenu = new MenuItem();
  208. imageCopyMenu = new MenuItem();
  209. imageCopyMenu.Header = "Copy Images";
  210. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  211. imageCopyMenu.CommandParameter = e;
  212. e.PopupMenu.Items.Add(imageCopyMenu);
  213. MenuItem imageExtraMenu = new MenuItem();
  214. imageExtraMenu = new MenuItem();
  215. imageExtraMenu.Header = "Extract Images";
  216. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  217. imageExtraMenu.CommandParameter = e;
  218. e.PopupMenu.Items.Add(imageExtraMenu);
  219. }
  220. }
  221. else
  222. {
  223. e.Handle = true;
  224. e.PopupMenu = new ContextMenu();
  225. MenuItem fitWidthMenu = new MenuItem();
  226. fitWidthMenu.Header = "Automatically Resize";
  227. fitWidthMenu.Click += (o, p) =>
  228. {
  229. if (pdfViewControl != null)
  230. {
  231. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  232. }
  233. };
  234. e.PopupMenu.Items.Add(fitWidthMenu);
  235. MenuItem fitSizeMenu = new MenuItem();
  236. fitSizeMenu.Header = "Actual Size";
  237. fitSizeMenu.Click += (o, p) =>
  238. {
  239. if (pdfViewControl != null)
  240. {
  241. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  242. }
  243. };
  244. e.PopupMenu.Items.Add(fitSizeMenu);
  245. MenuItem zoomInMenu = new MenuItem();
  246. zoomInMenu.Header = "Zoom In";
  247. zoomInMenu.Click += (o, p) =>
  248. {
  249. if (pdfViewControl != null)
  250. {
  251. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  252. pdfViewControl.PDFView?.Zoom(newZoom);
  253. }
  254. };
  255. e.PopupMenu.Items.Add(zoomInMenu);
  256. MenuItem zoomOutMenu = new MenuItem();
  257. zoomOutMenu.Header = "Zoom Out";
  258. zoomOutMenu.Click += (o, p) =>
  259. {
  260. if (pdfViewControl != null)
  261. {
  262. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  263. pdfViewControl.PDFView?.Zoom(newZoom);
  264. }
  265. };
  266. e.PopupMenu.Items.Add(zoomOutMenu);
  267. e.PopupMenu.Items.Add(new Separator());
  268. MenuItem singleView = new MenuItem();
  269. singleView.Header = "Single Page";
  270. singleView.Click += (o, p) =>
  271. {
  272. if (pdfViewControl != null)
  273. {
  274. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  275. }
  276. };
  277. e.PopupMenu.Items.Add(singleView);
  278. MenuItem singleContinuousView = new MenuItem();
  279. singleContinuousView.Header = "Single Page Continuous";
  280. singleContinuousView.Click += (o, p) =>
  281. {
  282. if (pdfViewControl != null)
  283. {
  284. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  285. }
  286. };
  287. e.PopupMenu.Items.Add(singleContinuousView);
  288. MenuItem doubleView = new MenuItem();
  289. doubleView.Header = "Two Pages";
  290. doubleView.Click += (o, p) =>
  291. {
  292. if (pdfViewControl != null)
  293. {
  294. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  295. }
  296. };
  297. e.PopupMenu.Items.Add(doubleView);
  298. MenuItem doubleContinuousView = new MenuItem();
  299. doubleContinuousView.Header = "Two Pages Continuous";
  300. doubleContinuousView.Click += (o, p) =>
  301. {
  302. if (pdfViewControl != null)
  303. {
  304. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  305. }
  306. };
  307. e.PopupMenu.Items.Add(doubleContinuousView);
  308. }
  309. }
  310. if (e != null && e.CommandType == CommandType.Copy)
  311. {
  312. e.DoCommand();
  313. }
  314. }
  315. private void CopyImage_Click(object sender, RoutedEventArgs e)
  316. {
  317. try
  318. {
  319. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  320. if (imageDict != null && imageDict.Count > 0)
  321. {
  322. foreach (int pageIndex in imageDict.Keys)
  323. {
  324. List<Bitmap> imageList = imageDict[pageIndex];
  325. foreach (Bitmap image in imageList)
  326. {
  327. MemoryStream ms = new MemoryStream();
  328. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  329. BitmapImage imageData = new BitmapImage();
  330. imageData.BeginInit();
  331. imageData.StreamSource = ms;
  332. imageData.CacheOption = BitmapCacheOption.OnLoad;
  333. imageData.EndInit();
  334. imageData.Freeze();
  335. Clipboard.SetImage(imageData);
  336. break;
  337. }
  338. }
  339. }
  340. }
  341. catch (Exception ex)
  342. {
  343. }
  344. }
  345. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  346. {
  347. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  348. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  349. {
  350. string choosePath = folderDialog.SelectedPath;
  351. string openPath = choosePath;
  352. try
  353. {
  354. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  355. if (imageDict != null && imageDict.Count > 0)
  356. {
  357. foreach (int pageIndex in imageDict.Keys)
  358. {
  359. List<Bitmap> imageList = imageDict[pageIndex];
  360. foreach (Bitmap image in imageList)
  361. {
  362. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  363. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  364. openPath = savePath;
  365. }
  366. }
  367. }
  368. Process.Start("explorer", "/select,\"" + openPath + "\"");
  369. }
  370. catch (Exception ex)
  371. {
  372. }
  373. }
  374. }
  375. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  376. {
  377. editCommand.PopupMenu = new ContextMenu();
  378. if (ApplicationCommands.Copy.CanExecute(null, (UIElement)sender) && lastPDFEditEvent != null)
  379. {
  380. MenuItem rotateLeftMenu = new MenuItem();
  381. rotateLeftMenu.Header = "Rotate Left";
  382. rotateLeftMenu.Click += (o, p) =>
  383. {
  384. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  385. {
  386. lastPDFEditEvent.Rotate = -90;
  387. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  388. imageEditControl?.SetImageThumb();
  389. }
  390. };
  391. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  392. MenuItem rotateRightMenu = new MenuItem();
  393. rotateRightMenu.Header = "Rotate Right";
  394. rotateRightMenu.Click += (o, p) =>
  395. {
  396. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  397. {
  398. lastPDFEditEvent.Rotate = 90;
  399. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  400. imageEditControl?.SetImageThumb();
  401. }
  402. };
  403. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  404. MenuItem replaceMenu = new MenuItem();
  405. replaceMenu.Header = "Replace";
  406. replaceMenu.Click += (o, p) =>
  407. {
  408. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  409. {
  410. OpenFileDialog openFileDialog = new OpenFileDialog();
  411. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  412. if (openFileDialog.ShowDialog() == true)
  413. {
  414. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  415. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  416. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  417. }
  418. }
  419. };
  420. editCommand.PopupMenu.Items.Add(replaceMenu);
  421. MenuItem exportMenu = new MenuItem();
  422. exportMenu.Header = "Export";
  423. exportMenu.Click += (o, p) =>
  424. {
  425. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  426. {
  427. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView.GetSelectedImages();
  428. if (imageDict != null && imageDict.Count > 0)
  429. {
  430. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  431. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  432. {
  433. string choosePath = folderBrowser.SelectedPath;
  434. string openPath = choosePath;
  435. try
  436. {
  437. foreach (int pageIndex in imageDict.Keys)
  438. {
  439. List<Bitmap> imageList = imageDict[pageIndex];
  440. foreach (Bitmap image in imageList)
  441. {
  442. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  443. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  444. openPath = savePath;
  445. }
  446. }
  447. Process.Start("explorer", "/select,\"" + openPath + "\"");
  448. }
  449. catch (Exception ex)
  450. {
  451. }
  452. }
  453. }
  454. }
  455. };
  456. editCommand.PopupMenu.Items.Add(exportMenu);
  457. MenuItem opacityMenu = new MenuItem();
  458. opacityMenu.Header = "Opacity";
  459. editCommand.PopupMenu.Items.Add(opacityMenu);
  460. AppendOpacityMenu(opacityMenu);
  461. MenuItem horizonMirror = new MenuItem();
  462. horizonMirror.Header = "Flip horizontal";
  463. horizonMirror.Click += (o, p) =>
  464. {
  465. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  466. {
  467. lastPDFEditEvent.HorizontalMirror = true;
  468. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  469. imageEditControl?.SetImageThumb();
  470. }
  471. };
  472. editCommand.PopupMenu.Items.Add(horizonMirror);
  473. MenuItem verticalMirror = new MenuItem();
  474. verticalMirror.Header = "Flip vertical";
  475. verticalMirror.Click += (o, p) =>
  476. {
  477. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  478. {
  479. lastPDFEditEvent.VerticalMirror = true;
  480. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  481. imageEditControl?.SetImageThumb();
  482. }
  483. };
  484. editCommand.PopupMenu.Items.Add(verticalMirror);
  485. MenuItem cropMenu = new MenuItem();
  486. cropMenu.Header = "Crop";
  487. cropMenu.Click += (o, p) =>
  488. {
  489. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  490. {
  491. lastPDFEditEvent.ClipImage = true;
  492. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  493. }
  494. };
  495. editCommand.PopupMenu.Items.Add(cropMenu);
  496. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  497. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  498. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  499. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  500. }
  501. else
  502. {
  503. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  504. }
  505. }
  506. private void AppendOpacityMenu(MenuItem parentMenu)
  507. {
  508. List<int> opacityList = new List<int>()
  509. {
  510. 25,50,75,100
  511. };
  512. foreach (int opacity in opacityList)
  513. {
  514. MenuItem opacityMenu = new MenuItem();
  515. opacityMenu.Header = string.Format("{0}%", opacity);
  516. opacityMenu.Click += (o, p) =>
  517. {
  518. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  519. {
  520. lastPDFEditEvent.Transparency = (int)(opacity * 255 / 100D);
  521. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  522. imageEditControl?.SetImageTransparency(lastPDFEditEvent.Transparency);
  523. imageEditControl?.SetImageThumb();
  524. }
  525. };
  526. parentMenu.Items.Add(opacityMenu);
  527. }
  528. }
  529. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  530. {
  531. editCommand.PopupMenu = new ContextMenu();
  532. if (lastPDFEditEvent != null)
  533. {
  534. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  535. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  536. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  537. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  538. }
  539. else
  540. {
  541. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  542. if (editCommand.TextAreaCopied)
  543. {
  544. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  545. }
  546. }
  547. }
  548. #endregion
  549. #region UI
  550. /// <summary>
  551. /// Check the zoom factor
  552. /// </summary>
  553. private double CheckZoomLevel(double zoom, bool IsGrowth)
  554. {
  555. double standardZoom = 100;
  556. if (zoom <= 0.01)
  557. {
  558. return 0.01;
  559. }
  560. if (zoom >= 10)
  561. {
  562. return 10;
  563. }
  564. zoom *= 100;
  565. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  566. {
  567. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  568. {
  569. standardZoom = zoomLevelList[i + 1];
  570. break;
  571. }
  572. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  573. {
  574. standardZoom = zoomLevelList[i];
  575. break;
  576. }
  577. }
  578. return standardZoom / 100;
  579. }
  580. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  581. {
  582. UIElement pageView = sender as UIElement;
  583. if (pageView != null)
  584. {
  585. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  586. }
  587. SetImageEditProperty();
  588. }
  589. private void RightPanelBtn_Click(object sender, RoutedEventArgs e)
  590. {
  591. ViewSettingBtn.IsChecked = false;
  592. ToggleButton toggleButton = sender as ToggleButton;
  593. if (toggleButton != null)
  594. {
  595. if (toggleButton.IsChecked == true)
  596. {
  597. if (PropertyContainer.Child is CPDFDisplaySettingsControl)
  598. {
  599. PropertyContainer.Child = prevPanel;
  600. }
  601. if (PropertyContainer.Child == null)
  602. {
  603. PropertyContainer.Child = empytPanel;
  604. }
  605. PropertyContainer.Visibility = Visibility.Visible;
  606. }
  607. else
  608. {
  609. PropertyContainer.Visibility = Visibility.Collapsed;
  610. }
  611. }
  612. }
  613. private void ToolExpand_Click(object sender, RoutedEventArgs e)
  614. {
  615. ToggleButton expandBtn = sender as ToggleButton;
  616. if (expandBtn != null)
  617. {
  618. bool isExpand = expandBtn.IsChecked == true;
  619. ExpandLeftPanel(isExpand);
  620. }
  621. }
  622. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  623. {
  624. ToolExpandBtn.IsChecked = true;
  625. ExpandLeftPanel(true);
  626. BotaSideTool.SelectBotaTool(BOTATools.Search);
  627. }
  628. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  629. {
  630. RightPanelBtn.IsChecked = false;
  631. ToggleButton toggleButton = sender as ToggleButton;
  632. if (toggleButton != null)
  633. {
  634. if (toggleButton.IsChecked == true)
  635. {
  636. CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
  637. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  638. if (ViewComboBox.SelectedIndex == 1)
  639. {
  640. displayPanel.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  641. }
  642. else
  643. {
  644. displayPanel.SetVisibilityWhenContentEdit(Visibility.Visible);
  645. }
  646. prevPanel = PropertyContainer.Child;
  647. PropertyContainer.Child = displayPanel;
  648. PropertyContainer.Visibility = Visibility.Visible;
  649. }
  650. else
  651. {
  652. PropertyContainer.Child = null;
  653. PropertyContainer.Visibility = Visibility.Collapsed;
  654. }
  655. }
  656. }
  657. private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  658. {
  659. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex + 1);
  660. }
  661. private void PrevPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  662. {
  663. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex - 1);
  664. }
  665. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  666. {
  667. PasswordUI.Visibility = Visibility.Collapsed;
  668. FileInfoUI.Visibility = Visibility.Visible;
  669. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  670. PopupBorder.Visibility = Visibility.Visible;
  671. }
  672. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  673. {
  674. PopupBorder.Visibility = Visibility.Collapsed;
  675. }
  676. private void OpenFile_Click(object sender, RoutedEventArgs e)
  677. {
  678. try
  679. {
  680. string filePath = CommonHelper.GetFilePathOrEmpty();
  681. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  682. {
  683. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  684. {
  685. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  686. if (oldFilePath.ToLower() == filePath.ToLower())
  687. {
  688. return;
  689. }
  690. }
  691. passwordViewer = new PDFViewControl();
  692. passwordViewer.PDFView.InitDocument(filePath);
  693. if (passwordViewer.PDFView.Document == null)
  694. {
  695. MessageBox.Show("Open File Failed");
  696. return;
  697. }
  698. if (passwordViewer.PDFView.Document.IsLocked)
  699. {
  700. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  701. PasswordUI.ClearPassword();
  702. PopupBorder.Visibility = Visibility.Visible;
  703. PasswordUI.Visibility = Visibility.Visible;
  704. }
  705. else
  706. {
  707. pdfViewControl = passwordViewer;
  708. LoadDocument();
  709. }
  710. }
  711. }
  712. catch (Exception ex)
  713. {
  714. }
  715. }
  716. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  717. {
  718. SaveFile();
  719. }
  720. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  721. {
  722. ToggleButton senderBtn = sender as ToggleButton;
  723. if (senderBtn != null && pdfViewControl != null)
  724. {
  725. ClearPDFEditState(senderBtn);
  726. if (senderBtn.IsChecked == true)
  727. {
  728. PDFEditEvent createParam = new PDFEditEvent();
  729. createParam.EditType = CPDFEditType.EditText;
  730. createParam.IsBold = false;
  731. createParam.IsItalic = false;
  732. createParam.FontSize = 14;
  733. createParam.FontName = "Helvetica";
  734. createParam.FontColor = Colors.Black;
  735. createParam.TextAlign = TextAlignType.AlignLeft;
  736. createParam.Transparency = 255;
  737. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  738. {
  739. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  740. if (pdfDoc.PageCount > 0)
  741. {
  742. CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  743. CPDFEditPage editPage = pdfPage.GetEditPage();
  744. editPage.BeginEdit(CPDFEditType.EditText);
  745. createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  746. editPage.EndEdit();
  747. }
  748. }
  749. pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
  750. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  751. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  752. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  753. pdfViewControl.PDFView?.ReloadDocument();
  754. pdfViewControl.PDFView?.SetPDFEditParam(createParam);
  755. if (textEditControl == null)
  756. {
  757. textEditControl = new PDFTextEditControl();
  758. }
  759. textEditControl.SetPDFTextEditData(createParam);
  760. PropertyContainer.Child = textEditControl;
  761. PropertyContainer.Visibility = Visibility.Visible;
  762. if ((bool)ViewSettingBtn.IsChecked)
  763. {
  764. ViewSettingBtn.IsChecked = false;
  765. }
  766. RightPanelBtn.IsChecked = true;
  767. pdfTextCreateParam = createParam;
  768. }
  769. else
  770. {
  771. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  772. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  773. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  774. pdfViewControl.PDFView?.ReloadDocument();
  775. RightPanelBtn.IsChecked = false;
  776. if ((bool)ViewSettingBtn.IsChecked)
  777. {
  778. return;
  779. }
  780. else
  781. {
  782. if (PropertyContainer.Child != null)
  783. {
  784. PropertyContainer.Child = empytPanel;
  785. }
  786. }
  787. PropertyContainer.Visibility = Visibility.Collapsed;
  788. }
  789. }
  790. }
  791. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  792. {
  793. ToggleButton senderBtn = sender as ToggleButton;
  794. if (senderBtn != null && pdfViewControl != null)
  795. {
  796. senderBtn.IsChecked = false;
  797. OpenFileDialog openFileDialog = new OpenFileDialog();
  798. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  799. if (openFileDialog.ShowDialog() == true)
  800. {
  801. ClearPDFEditState(senderBtn);
  802. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  803. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  804. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  805. pdfViewControl.PDFView?.ReloadDocument();
  806. RightPanelBtn.IsChecked = false;
  807. if (PropertyContainer.Child != null && !(bool)ViewSettingBtn.IsChecked)
  808. {
  809. PropertyContainer.Child = empytPanel;
  810. PropertyContainer.Visibility = Visibility.Collapsed;
  811. }
  812. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  813. pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  814. }
  815. }
  816. }
  817. private void ClearPDFEditState(ToggleButton ignoreBtn = null)
  818. {
  819. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  820. {
  821. PDFTextEditButton,
  822. PDFImageEditButton
  823. };
  824. foreach (ToggleButton item in clearBtnList)
  825. {
  826. if (ignoreBtn == item)
  827. {
  828. continue;
  829. }
  830. item.IsChecked = false;
  831. }
  832. }
  833. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  834. {
  835. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  836. {
  837. pdfViewControl.PDFView.UndoManager?.Undo();
  838. }
  839. }
  840. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  841. {
  842. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  843. {
  844. pdfViewControl.PDFView.UndoManager?.Redo();
  845. }
  846. }
  847. #endregion
  848. #region Property changed
  849. protected void OnPropertyChanged([CallerMemberName] string name = null)
  850. {
  851. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  852. }
  853. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  854. {
  855. OnPropertyChanged(e.PropertyName);
  856. }
  857. #endregion
  858. #region Event handle
  859. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  860. {
  861. if (e == null)
  862. {
  863. return;
  864. }
  865. if (e.EditType == CPDFEditType.EditText)
  866. {
  867. e.Handle = true;
  868. PDFEditTextContextMenu(sender, e);
  869. }
  870. if (e.EditType == CPDFEditType.EditImage)
  871. {
  872. e.Handle = true;
  873. PDFEditImageContextMenu(sender, e);
  874. }
  875. }
  876. private void PDFView_PDFEditActiveHandler(object sender, PDFEditEvent e)
  877. {
  878. PDFEditEvent tempEvent = lastPDFEditEvent;
  879. lastPDFEditEvent = e;
  880. if ((bool)ViewSettingBtn.IsChecked)
  881. {
  882. ViewSettingBtn.IsChecked = false;
  883. RightPanelBtn.IsChecked = true;
  884. }
  885. if (e == null)
  886. {
  887. PropertyContainer.Child = empytPanel;
  888. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  889. {
  890. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  891. {
  892. if (textEditControl == null)
  893. {
  894. textEditControl = new PDFTextEditControl();
  895. }
  896. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  897. PropertyContainer.Child = textEditControl;
  898. }
  899. }
  900. return;
  901. }
  902. if (Mouse.RightButton == MouseButtonState.Pressed && PropertyContainer.Visibility != Visibility.Visible)
  903. {
  904. return;
  905. }
  906. if (e.EditType == CPDFEditType.EditText)
  907. {
  908. if (textEditControl == null)
  909. {
  910. textEditControl = new PDFTextEditControl();
  911. }
  912. textEditControl.SetPDFTextEditData(e);
  913. PropertyContainer.Child = textEditControl;
  914. return;
  915. }
  916. if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
  917. {
  918. UIElement pageView = sender as UIElement;
  919. if (pageView != null)
  920. {
  921. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  922. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  923. }
  924. if (Mouse.RightButton == MouseButtonState.Pressed)
  925. {
  926. SetImageEditProperty();
  927. }
  928. return;
  929. }
  930. }
  931. #endregion
  932. #region Save file
  933. private void SaveFile()
  934. {
  935. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  936. {
  937. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  938. if (pdfDoc.WriteToLoadedPath())
  939. {
  940. return;
  941. }
  942. SaveFileDialog saveDialog = new SaveFileDialog();
  943. saveDialog.Filter = "(*.pdf)|*.pdf";
  944. saveDialog.DefaultExt = ".pdf";
  945. saveDialog.OverwritePrompt = true;
  946. if (saveDialog.ShowDialog() == true)
  947. {
  948. pdfDoc.WriteToFilePath(saveDialog.FileName);
  949. }
  950. }
  951. }
  952. #endregion
  953. #region Selected changed
  954. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  955. {
  956. if (e.Key == "Zoom")
  957. {
  958. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  959. }
  960. }
  961. private void SetImageEditProperty()
  962. {
  963. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  964. {
  965. if (imageEditControl == null)
  966. {
  967. imageEditControl = new PDFImageEditControl();
  968. }
  969. imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
  970. imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
  971. PropertyContainer.Child = imageEditControl;
  972. }
  973. }
  974. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  975. {
  976. SetEditMode();
  977. }
  978. private void SetEditMode()
  979. {
  980. ClearPDFEditState(null);
  981. if (pdfViewControl != null && ViewComboBox != null)
  982. {
  983. if (ViewComboBox.SelectedIndex == 0)
  984. {
  985. PDFEditTool.Visibility = Visibility.Collapsed;
  986. pdfViewControl.PDFView?.SetShowLink(true);
  987. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
  988. pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
  989. pdfViewControl.PDFView?.ReloadDocument();
  990. }
  991. if (ViewComboBox.SelectedIndex == 1)
  992. {
  993. PDFEditTool.Visibility = Visibility.Visible;
  994. pdfViewControl.PDFView?.SetShowLink(false);
  995. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
  996. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  997. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  998. pdfViewControl.PDFView?.ReloadDocument();
  999. }
  1000. RightPanelBtn.IsChecked = false;
  1001. ViewSettingBtn.IsChecked = false;
  1002. PropertyContainer.Visibility = Visibility.Collapsed;
  1003. if (PropertyContainer != null)
  1004. {
  1005. PropertyContainer.Child = null;
  1006. }
  1007. }
  1008. }
  1009. public void PDFView_KeyDown(object sender, KeyEventArgs e)
  1010. {
  1011. if (pdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
  1012. {
  1013. return;
  1014. }
  1015. if (Keyboard.Modifiers == ModifierKeys.Control)
  1016. {
  1017. if (e.Key == Key.Left)
  1018. {
  1019. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
  1020. e.Handled = true;
  1021. }
  1022. if (e.Key == Key.Right)
  1023. {
  1024. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
  1025. e.Handled = true;
  1026. }
  1027. if (e.Key == Key.Up)
  1028. {
  1029. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
  1030. e.Handled = true;
  1031. }
  1032. if (e.Key == Key.Down)
  1033. {
  1034. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
  1035. e.Handled = true;
  1036. }
  1037. }
  1038. if (Keyboard.Modifiers == ModifierKeys.Shift)
  1039. {
  1040. if (e.Key == Key.Left)
  1041. {
  1042. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, false);
  1043. e.Handled = true;
  1044. }
  1045. if (e.Key == Key.Right)
  1046. {
  1047. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, false);
  1048. e.Handled = true;
  1049. }
  1050. if (e.Key == Key.Up)
  1051. {
  1052. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, false);
  1053. e.Handled = true;
  1054. }
  1055. if (e.Key == Key.Down)
  1056. {
  1057. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, false);
  1058. e.Handled = true;
  1059. }
  1060. }
  1061. if (Keyboard.Modifiers == ModifierKeys.Alt)
  1062. {
  1063. if (e.SystemKey == Key.Up)
  1064. {
  1065. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
  1066. e.Handled = true;
  1067. }
  1068. if (e.SystemKey == Key.Down)
  1069. {
  1070. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
  1071. e.Handled = true;
  1072. }
  1073. }
  1074. if (Keyboard.Modifiers == ModifierKeys.None)
  1075. {
  1076. if (e.Key == Key.Left)
  1077. {
  1078. pdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
  1079. e.Handled = true;
  1080. }
  1081. if (e.Key == Key.Right)
  1082. {
  1083. pdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
  1084. e.Handled = true;
  1085. }
  1086. if (e.Key == Key.Up)
  1087. {
  1088. pdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
  1089. e.Handled = true;
  1090. }
  1091. if (e.Key == Key.Down)
  1092. {
  1093. pdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
  1094. e.Handled = true;
  1095. }
  1096. }
  1097. }
  1098. #endregion
  1099. #region Close window
  1100. protected override void OnClosing(CancelEventArgs e)
  1101. {
  1102. if (pdfViewControl.PDFView.UndoManager.CanSave)
  1103. {
  1104. MessageBoxResult result = MessageBox.Show("Do you want to save your changes before closing the application?", "Message", MessageBoxButton.YesNoCancel);
  1105. if (result == MessageBoxResult.Yes)
  1106. {
  1107. SaveFile();
  1108. }
  1109. else if (result == MessageBoxResult.No)
  1110. {
  1111. }
  1112. else
  1113. {
  1114. e.Cancel = true;
  1115. }
  1116. }
  1117. }
  1118. #endregion
  1119. }
  1120. }