MainPage.xaml.cs 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using Compdfkit_Tools.Data;
  5. using Compdfkit_Tools.Edit;
  6. using Compdfkit_Tools.Helper;
  7. using Compdfkit_Tools.PDFControl;
  8. using ComPDFKitViewer;
  9. using ComPDFKitViewer.AnnotEvent;
  10. using ComPDFKitViewer.PdfViewer;
  11. using Microsoft.Win32;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Runtime.CompilerServices;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Controls.Primitives;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using Path = System.IO.Path;
  27. using Point = System.Windows.Point;
  28. namespace PDFViewer
  29. {
  30. public partial class MainPage : UserControl, INotifyPropertyChanged
  31. {
  32. #region Property
  33. private bool isFirstLoad = true;
  34. private string currentMode = "Viewer";
  35. private PDFViewControl passwordViewer;
  36. private PDFViewControl pdfViewControl = new PDFViewControl();
  37. private CPDFAnnotationControl pdfAnnotationControl = null;
  38. private UIElement pdfEditControl = null;
  39. private CPDFPageEditControl pageEditControl = null;
  40. private FromPropertyControl pdfFormControl = new FromPropertyControl();
  41. private PDFImageEditControl imageEditControl = null;
  42. private CPDFDisplaySettingsControl displayPanel = null;
  43. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  44. public bool CanSave
  45. {
  46. get
  47. {
  48. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  49. {
  50. return pdfViewControl.PDFView.UndoManager.CanSave;
  51. }
  52. return false;
  53. }
  54. }
  55. public bool CanUndo
  56. {
  57. get
  58. {
  59. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  60. {
  61. return pdfViewControl.PDFView.UndoManager.CanUndo;
  62. }
  63. return false;
  64. }
  65. }
  66. public bool CanRedo
  67. {
  68. get
  69. {
  70. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  71. {
  72. return pdfViewControl.PDFView.UndoManager.CanRedo;
  73. }
  74. return false;
  75. }
  76. }
  77. private PDFEditEvent lastPDFEditEvent = null;
  78. public event Func<string[], bool> CheckExistBeforeOpenFileEvent;
  79. public event PropertyChangedEventHandler PropertyChanged;
  80. public event EventHandler FileChangeEvent;
  81. private PDFEditEvent pdfTextCreateParam;
  82. private PDFTextEditControl textEditControl = new PDFTextEditControl();
  83. private KeyEventHandler KeyDownHandler;
  84. #endregion
  85. public MainPage()
  86. {
  87. InitializeComponent();
  88. DataContext = this;
  89. if (pdfFormControl != null)
  90. {
  91. pdfFormControl = new FromPropertyControl();
  92. }
  93. }
  94. #region Initial Load Unload
  95. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  96. {
  97. pdfAnnotationControl.SetPDFViewer(newPDFViewer.PDFView);
  98. FormBarControl.InitWithPDFViewer(newPDFViewer.PDFView, pdfFormControl);
  99. pdfFormControl.SetPDFViewer(newPDFViewer.PDFView);
  100. pdfAnnotationControl.AnnotationCancel();
  101. AnnotationBarControl.ClearAllToolState();
  102. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  103. newPDFViewer.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
  104. newPDFViewer.CustomSignHandle = true;
  105. }
  106. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  107. {
  108. pdfAnnotationControl = new CPDFAnnotationControl();
  109. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
  110. LoadDocument();
  111. }
  112. public void SetPDFViewer(PDFViewControl newPdfViewer)
  113. {
  114. if (newPdfViewer != null)
  115. {
  116. pdfViewControl = newPdfViewer;
  117. }
  118. }
  119. private void CPDFTitleBarControl_Loaded(object sender, RoutedEventArgs e)
  120. {
  121. CPDFTitleBarControl.OpenFileEvent -= CPDFTitleBarControl_OpenFileEvent;
  122. CPDFTitleBarControl.OpenFileEvent += CPDFTitleBarControl_OpenFileEvent;
  123. CPDFTitleBarControl.SaveAsFileEvent -= CPDFTitleBarControl_SaveAsFileEvent;
  124. CPDFTitleBarControl.SaveAsFileEvent += CPDFTitleBarControl_SaveAsFileEvent;
  125. CPDFTitleBarControl.SaveFileEvent -= CPDFTitleBarControl_SaveFileEvent;
  126. CPDFTitleBarControl.SaveFileEvent += CPDFTitleBarControl_SaveFileEvent; ;
  127. }
  128. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  129. {
  130. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  131. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  132. }
  133. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  134. {
  135. CPDFAnnotationType[] annotationProperties = { CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout, CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText, CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square, CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image, CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link, CPDFAnnotationType.Audio };
  136. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  137. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  138. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  139. }
  140. #endregion
  141. #region UI
  142. /// <summary>
  143. /// InfoChanged
  144. /// When the PDF zoom ratio changes, the value of the zoom control also changes.
  145. /// </summary>
  146. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  147. {
  148. if (e.Key == "Zoom")
  149. {
  150. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  151. }
  152. }
  153. private void EditLink_Click(object sender, RoutedEventArgs e)
  154. {
  155. RightPanelButton.IsChecked = true;
  156. PropertyContainer.Visibility = Visibility.Visible;
  157. }
  158. private double CheckZoomLevel(double zoom, bool IsGrowth)
  159. {
  160. double standardZoom = 100;
  161. if (zoom <= 0.01)
  162. {
  163. return 0.01;
  164. }
  165. if (zoom >= 10)
  166. {
  167. return 10;
  168. }
  169. zoom *= 100;
  170. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  171. {
  172. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  173. {
  174. standardZoom = zoomLevelList[i + 1];
  175. break;
  176. }
  177. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  178. {
  179. standardZoom = zoomLevelList[i];
  180. break;
  181. }
  182. }
  183. return standardZoom / 100;
  184. }
  185. private void PDFView_AnnotEditHandler(object sender, List<ComPDFKitViewer.AnnotEvent.AnnotEditEvent> e)
  186. {
  187. BotaSideTool.LoadAnnotationList();
  188. }
  189. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  190. {
  191. OnPropertyChanged(e.PropertyName);
  192. }
  193. private void PasswordUI_Closed(object sender, EventArgs e)
  194. {
  195. PopupBorder.Visibility = Visibility.Collapsed;
  196. PasswordUI.Visibility = Visibility.Collapsed;
  197. }
  198. private void PasswordUI_Canceled(object sender, EventArgs e)
  199. {
  200. PopupBorder.Visibility = Visibility.Collapsed;
  201. PasswordUI.Visibility = Visibility.Collapsed;
  202. }
  203. private void PasswordUI_Confirmed(object sender, string e)
  204. {
  205. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  206. {
  207. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  208. if (passwordViewer.PDFView.Document.IsLocked == false)
  209. {
  210. PasswordUI.SetShowError("", Visibility.Collapsed);
  211. PasswordUI.ClearPassword();
  212. PasswordUI.Visibility = Visibility.Collapsed;
  213. PopupBorder.Visibility = Visibility.Collapsed;
  214. pdfViewControl = passwordViewer;
  215. LoadDocument();
  216. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  217. }
  218. else
  219. {
  220. PasswordUI.SetShowError("error", Visibility.Visible);
  221. }
  222. }
  223. }
  224. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  225. {
  226. SaveFile();
  227. }
  228. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  229. {
  230. UIElement pageView = sender as UIElement;
  231. if (pageView != null)
  232. {
  233. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  234. }
  235. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  236. {
  237. if (imageEditControl == null)
  238. {
  239. imageEditControl = new PDFImageEditControl();
  240. }
  241. imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
  242. imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
  243. pdfEditControl = imageEditControl as UIElement;
  244. PropertyContainer.Child = pdfEditControl;
  245. }
  246. }
  247. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  248. {
  249. PasswordUI.Visibility = Visibility.Collapsed;
  250. FileInfoUI.Visibility = Visibility.Visible;
  251. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  252. PopupBorder.Visibility = Visibility.Visible;
  253. }
  254. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  255. {
  256. PopupBorder.Visibility = Visibility.Collapsed;
  257. }
  258. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  259. {
  260. ToggleButton senderBtn = sender as ToggleButton;
  261. if (senderBtn != null && pdfViewControl != null)
  262. {
  263. ClearPDFEditState(senderBtn);
  264. if (senderBtn.IsChecked == true)
  265. {
  266. PDFEditEvent createParam = new PDFEditEvent();
  267. createParam.EditType = CPDFEditType.EditText;
  268. createParam.IsBold = false;
  269. createParam.IsItalic = false;
  270. createParam.FontSize = 14;
  271. createParam.FontName = "Helvetica";
  272. createParam.FontColor = Colors.Black;
  273. createParam.TextAlign = TextAlignType.AlignLeft;
  274. createParam.Transparency = 255;
  275. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  276. {
  277. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  278. if (pdfDoc.PageCount > 0)
  279. {
  280. CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  281. CPDFEditPage editPage = pdfPage.GetEditPage();
  282. editPage.BeginEdit(CPDFEditType.EditText);
  283. createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  284. editPage.EndEdit();
  285. }
  286. }
  287. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  288. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  289. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  290. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  291. pdfViewControl.PDFView?.ReloadDocument();
  292. pdfViewControl.PDFView?.SetPDFEditParam(createParam);
  293. if (textEditControl == null)
  294. {
  295. textEditControl = new PDFTextEditControl();
  296. }
  297. textEditControl.SetPDFTextEditData(createParam);
  298. ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
  299. if ((bool)ViewSettingBtn.IsChecked)
  300. {
  301. ViewSettingBtn.IsChecked = false;
  302. }
  303. RightPanelButton.IsChecked = true;
  304. pdfTextCreateParam = createParam;
  305. }
  306. else
  307. {
  308. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  309. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  310. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  311. pdfViewControl.PDFView?.ReloadDocument();
  312. LeftToolPanelButton.IsChecked = false;
  313. if ((bool)ViewSettingBtn.IsChecked)
  314. {
  315. return;
  316. }
  317. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  318. }
  319. }
  320. }
  321. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  322. {
  323. ToggleButton senderBtn = sender as ToggleButton;
  324. if (senderBtn != null && pdfViewControl != null)
  325. {
  326. senderBtn.IsChecked = false;
  327. OpenFileDialog openFileDialog = new OpenFileDialog();
  328. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  329. if (openFileDialog.ShowDialog() == true)
  330. {
  331. ClearPDFEditState(senderBtn);
  332. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  333. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  334. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  335. pdfViewControl.PDFView?.ReloadDocument();
  336. RightPanelButton.IsChecked = false;
  337. if (PropertyContainer.Child != null && !(bool)ViewSettingBtn.IsChecked)
  338. {
  339. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  340. }
  341. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  342. pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  343. }
  344. }
  345. }
  346. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  347. {
  348. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  349. {
  350. pdfViewControl.PDFView.UndoManager?.Undo();
  351. }
  352. }
  353. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  354. {
  355. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  356. {
  357. pdfViewControl.PDFView.UndoManager?.Redo();
  358. }
  359. }
  360. private void ClearPDFEditState(ToggleButton ignoreBtn = null)
  361. {
  362. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  363. {
  364. PDFTextEditButton,
  365. PDFImageEditButton
  366. };
  367. foreach (ToggleButton item in clearBtnList)
  368. {
  369. if (ignoreBtn == item)
  370. {
  371. continue;
  372. }
  373. item.IsChecked = false;
  374. }
  375. }
  376. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  377. {
  378. AnnotationBarControl.ClearAllToolState();
  379. }
  380. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  381. {
  382. pdfAnnotationControl.AnnotationCancel();
  383. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  384. RightPanelButton.IsChecked = false;
  385. ViewSettingBtn.IsChecked = false;
  386. }
  387. #endregion
  388. #region ContextMenu
  389. /// <summary>
  390. /// Annotation Context menu
  391. /// </summary>
  392. private void PDFView_AnnotCommandHandler(object sender, ComPDFKitViewer.AnnotEvent.AnnotCommandArgs e)
  393. {
  394. switch (e.CommandType)
  395. {
  396. case CommandType.Context:
  397. e.Handle = true;
  398. if (e.CommandTarget == TargetType.Annot)
  399. {
  400. e.Handle = true;
  401. e.PopupMenu = new ContextMenu();
  402. if (e.PressOnLink && AnnotationBarControl.CurrentMode == "Link")
  403. {
  404. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  405. MenuItem propertyMenu = new MenuItem();
  406. propertyMenu = new MenuItem();
  407. propertyMenu.Header = "Edit";
  408. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
  409. propertyMenu.CommandParameter = e;
  410. e.PopupMenu.Items.Add(propertyMenu);
  411. }
  412. else if (e.PressOnAnnot)
  413. {
  414. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  415. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  416. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  417. }
  418. else if (e.PressOnMedia || e.PressOnSound)
  419. {
  420. e.Handle = true;
  421. e.PopupMenu.Items.Add(new MenuItem() { Header = "Play", Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = e });
  422. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  423. }
  424. else if (e.PressOnSelectedText)
  425. {
  426. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  427. }
  428. else
  429. {
  430. e.Handle = true;
  431. e.PopupMenu = new ContextMenu();
  432. if (currentMode == "Annotations")
  433. {
  434. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  435. e.PopupMenu.Items.Add(new Separator());
  436. }
  437. MenuItem fitWidthMenu = new MenuItem();
  438. fitWidthMenu.Header = "Automatically Resize";
  439. fitWidthMenu.Click += (o, p) =>
  440. {
  441. if (pdfViewControl != null)
  442. {
  443. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  444. }
  445. };
  446. e.PopupMenu.Items.Add(fitWidthMenu);
  447. MenuItem fitSizeMenu = new MenuItem();
  448. fitSizeMenu.Header = "Actual Size";
  449. fitSizeMenu.Click += (o, p) =>
  450. {
  451. if (pdfViewControl != null)
  452. {
  453. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  454. }
  455. };
  456. e.PopupMenu.Items.Add(fitSizeMenu);
  457. MenuItem zoomInMenu = new MenuItem();
  458. zoomInMenu.Header = "Zoom In";
  459. zoomInMenu.Click += (o, p) =>
  460. {
  461. if (pdfViewControl != null)
  462. {
  463. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  464. pdfViewControl.PDFView?.Zoom(newZoom);
  465. }
  466. };
  467. e.PopupMenu.Items.Add(zoomInMenu);
  468. MenuItem zoomOutMenu = new MenuItem();
  469. zoomOutMenu.Header = "Zoom Out";
  470. zoomOutMenu.Click += (o, p) =>
  471. {
  472. if (pdfViewControl != null)
  473. {
  474. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  475. pdfViewControl.PDFView?.Zoom(newZoom);
  476. }
  477. };
  478. e.PopupMenu.Items.Add(zoomOutMenu);
  479. e.PopupMenu.Items.Add(new Separator());
  480. MenuItem singleView = new MenuItem();
  481. singleView.Header = "Single Page";
  482. singleView.Click += (o, p) =>
  483. {
  484. if (pdfViewControl != null)
  485. {
  486. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  487. }
  488. };
  489. e.PopupMenu.Items.Add(singleView);
  490. MenuItem singleContinuousView = new MenuItem();
  491. singleContinuousView.Header = "Single Page Continuous";
  492. singleContinuousView.Click += (o, p) =>
  493. {
  494. if (pdfViewControl != null)
  495. {
  496. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  497. }
  498. };
  499. e.PopupMenu.Items.Add(singleContinuousView);
  500. MenuItem doubleView = new MenuItem();
  501. doubleView.Header = "Two Pages";
  502. doubleView.Click += (o, p) =>
  503. {
  504. if (pdfViewControl != null)
  505. {
  506. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  507. }
  508. };
  509. e.PopupMenu.Items.Add(doubleView);
  510. MenuItem doubleContinuousView = new MenuItem();
  511. doubleContinuousView.Header = "Two Pages Continuous";
  512. doubleContinuousView.Click += (o, p) =>
  513. {
  514. if (pdfViewControl != null)
  515. {
  516. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  517. }
  518. };
  519. e.PopupMenu.Items.Add(doubleContinuousView);
  520. }
  521. }
  522. else if (e.CommandTarget == TargetType.ImageSelection)
  523. {
  524. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  525. {
  526. e.Handle = true;
  527. e.PopupMenu = new ContextMenu();
  528. MenuItem imageCopyMenu = new MenuItem();
  529. imageCopyMenu = new MenuItem();
  530. imageCopyMenu.Header = "Copy Images";
  531. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  532. imageCopyMenu.CommandParameter = e;
  533. e.PopupMenu.Items.Add(imageCopyMenu);
  534. MenuItem imageExtraMenu = new MenuItem();
  535. imageExtraMenu = new MenuItem();
  536. imageExtraMenu.Header = "Extract Images";
  537. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  538. imageExtraMenu.CommandParameter = e;
  539. e.PopupMenu.Items.Add(imageExtraMenu);
  540. }
  541. }
  542. break;
  543. case CommandType.Copy:
  544. e.DoCommand();
  545. break;
  546. case CommandType.Cut:
  547. case CommandType.Paste:
  548. case CommandType.Delete:
  549. e.DoCommand();
  550. break;
  551. default:
  552. break;
  553. }
  554. }
  555. /// <summary>
  556. /// TextEdit context menu.
  557. /// </summary>
  558. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  559. {
  560. editCommand.PopupMenu = new ContextMenu();
  561. if (lastPDFEditEvent != null)
  562. {
  563. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  564. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  565. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  566. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  567. }
  568. else
  569. {
  570. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  571. if (editCommand.TextAreaCopied)
  572. {
  573. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  574. }
  575. }
  576. }
  577. /// <summary>
  578. /// ImageEdit right-click menu.
  579. /// </summary>
  580. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  581. {
  582. editCommand.PopupMenu = new ContextMenu();
  583. if (lastPDFEditEvent != null)
  584. {
  585. MenuItem rotateLeftMenu = new MenuItem();
  586. rotateLeftMenu.Header = "Left Rotate";
  587. rotateLeftMenu.Click += (o, p) =>
  588. {
  589. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  590. {
  591. lastPDFEditEvent.Rotate = -90;
  592. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  593. imageEditControl?.SetImageThumb();
  594. }
  595. };
  596. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  597. MenuItem rotateRightMenu = new MenuItem();
  598. rotateRightMenu.Header = "Right Rotate";
  599. rotateRightMenu.Click += (o, p) =>
  600. {
  601. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  602. {
  603. lastPDFEditEvent.Rotate = 90;
  604. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  605. imageEditControl?.SetImageThumb();
  606. }
  607. };
  608. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  609. MenuItem replaceMenu = new MenuItem();
  610. replaceMenu.Header = "Replace";
  611. replaceMenu.Click += (o, p) =>
  612. {
  613. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  614. {
  615. OpenFileDialog openFileDialog = new OpenFileDialog();
  616. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  617. if (openFileDialog.ShowDialog() == true)
  618. {
  619. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  620. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  621. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  622. imageEditControl?.SetImageThumb();
  623. }
  624. }
  625. };
  626. editCommand.PopupMenu.Items.Add(replaceMenu);
  627. MenuItem exportMenu = new MenuItem();
  628. exportMenu.Header = "Export";
  629. exportMenu.Click += (o, p) =>
  630. {
  631. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  632. {
  633. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView.GetSelectedImages();
  634. if (imageDict != null && imageDict.Count > 0)
  635. {
  636. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  637. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  638. {
  639. string choosePath = folderBrowser.SelectedPath;
  640. string openPath = choosePath;
  641. foreach (int pageIndex in imageDict.Keys)
  642. {
  643. List<Bitmap> imageList = imageDict[pageIndex];
  644. foreach (Bitmap image in imageList)
  645. {
  646. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  647. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  648. openPath = savePath;
  649. }
  650. }
  651. Process.Start("explorer", "/select,\"" + openPath + "\"");
  652. }
  653. }
  654. }
  655. };
  656. editCommand.PopupMenu.Items.Add(exportMenu);
  657. MenuItem opacityMenu = new MenuItem();
  658. opacityMenu.Header = "Opacity";
  659. editCommand.PopupMenu.Items.Add(opacityMenu);
  660. AppendOpacityMenu(opacityMenu);
  661. MenuItem horizonMirror = new MenuItem();
  662. horizonMirror.Header = "HMirror";
  663. horizonMirror.Click += (o, p) =>
  664. {
  665. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  666. {
  667. lastPDFEditEvent.HorizontalMirror = true;
  668. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  669. }
  670. };
  671. editCommand.PopupMenu.Items.Add(horizonMirror);
  672. MenuItem verticalMirror = new MenuItem();
  673. verticalMirror.Header = "VMirror";
  674. verticalMirror.Click += (o, p) =>
  675. {
  676. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  677. {
  678. lastPDFEditEvent.VerticalMirror = true;
  679. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  680. }
  681. };
  682. editCommand.PopupMenu.Items.Add(verticalMirror);
  683. MenuItem cropMenu = new MenuItem();
  684. cropMenu.Header = "Crop";
  685. cropMenu.Click += (o, p) =>
  686. {
  687. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  688. {
  689. lastPDFEditEvent.ClipImage = true;
  690. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  691. }
  692. };
  693. editCommand.PopupMenu.Items.Add(cropMenu);
  694. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  695. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  696. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  697. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  698. if (editCommand.TextAreaCopied)
  699. {
  700. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  701. }
  702. }
  703. else
  704. {
  705. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  706. }
  707. }
  708. /// <summary>
  709. /// ImageEdit transparency submenu.
  710. /// </summary>
  711. private void AppendOpacityMenu(MenuItem parentMenu)
  712. {
  713. List<int> opacityList = new List<int>()
  714. {
  715. 25,50,75,100
  716. };
  717. foreach (int opacity in opacityList)
  718. {
  719. MenuItem opacityMenu = new MenuItem();
  720. opacityMenu.Header = string.Format("{0}%", opacity);
  721. opacityMenu.Click += (o, p) =>
  722. {
  723. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  724. {
  725. lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
  726. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  727. }
  728. };
  729. parentMenu.Items.Add(opacityMenu);
  730. }
  731. }
  732. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  733. {
  734. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  735. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  736. {
  737. string choosePath = folderDialog.SelectedPath;
  738. string openPath = choosePath;
  739. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  740. if (imageDict != null && imageDict.Count > 0)
  741. {
  742. foreach (int pageIndex in imageDict.Keys)
  743. {
  744. List<Bitmap> imageList = imageDict[pageIndex];
  745. foreach (Bitmap image in imageList)
  746. {
  747. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  748. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  749. openPath = savePath;
  750. }
  751. }
  752. }
  753. Process.Start("explorer", "/select,\"" + openPath + "\"");
  754. }
  755. }
  756. private void CopyImage_Click(object sender, RoutedEventArgs e)
  757. {
  758. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  759. if (imageDict != null && imageDict.Count > 0)
  760. {
  761. foreach (int pageIndex in imageDict.Keys)
  762. {
  763. List<Bitmap> imageList = imageDict[pageIndex];
  764. foreach (Bitmap image in imageList)
  765. {
  766. MemoryStream ms = new MemoryStream();
  767. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  768. BitmapImage imageData = new BitmapImage();
  769. imageData.BeginInit();
  770. imageData.StreamSource = ms;
  771. imageData.CacheOption = BitmapCacheOption.OnLoad;
  772. imageData.EndInit();
  773. imageData.Freeze();
  774. Clipboard.SetImage(imageData);
  775. break;
  776. }
  777. }
  778. }
  779. }
  780. #endregion
  781. #region Property changed
  782. protected void OnPropertyChanged([CallerMemberName] string name = null)
  783. {
  784. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  785. }
  786. #endregion
  787. #region Open and save file
  788. public void InitWithFilePath(string filePath)
  789. {
  790. pdfViewControl = new PDFViewControl();
  791. pdfViewControl.PDFView.InitDocument(filePath);
  792. }
  793. private void LoadDocument()
  794. {
  795. //Load the Document
  796. pdfViewControl.PDFView?.Load();
  797. //Highlight the link annotation
  798. pdfViewControl.PDFView?.SetShowLink(true);
  799. //Add PDFViewControl to PDFGrid
  800. PDFGrid.Child = pdfViewControl;
  801. // Register the InfoChanged event handler,
  802. // which is used to notify the CPDFScalingControl of real-time changes in the displayed number when the page size changes.
  803. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  804. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  805. //
  806. pdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  807. pdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  808. //
  809. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  810. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  811. //Can undo, can redo
  812. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  813. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  814. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  815. PasswordUI.Closed -= PasswordUI_Closed;
  816. PasswordUI.Canceled -= PasswordUI_Canceled;
  817. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  818. PasswordUI.Confirmed += PasswordUI_Confirmed;
  819. PasswordUI.Canceled += PasswordUI_Canceled;
  820. PasswordUI.Closed += PasswordUI_Closed;
  821. pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
  822. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  823. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  824. InitialPDFViewControl(pdfViewControl);
  825. pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  826. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  827. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  828. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  829. ViewSettingBtn.IsChecked = false;
  830. PropertyContainer.Child = null;
  831. PropertyContainer.Visibility = Visibility.Collapsed;
  832. ModeComboBox.SelectedIndex = 0;
  833. if (KeyDownHandler != null)
  834. {
  835. pdfViewControl.PDFView.RemoveHandler(KeyDownEvent, KeyDownHandler);
  836. }
  837. KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
  838. pdfViewControl.PDFView.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
  839. }
  840. /// <summary>
  841. /// Save the file to another PDF file.
  842. /// </summary>
  843. public void SaveAsFile()
  844. {
  845. {
  846. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  847. {
  848. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  849. SaveFileDialog saveDialog = new SaveFileDialog();
  850. saveDialog.Filter = "(*.pdf)|*.pdf";
  851. saveDialog.DefaultExt = ".pdf";
  852. saveDialog.OverwritePrompt = true;
  853. if (saveDialog.ShowDialog() == true)
  854. {
  855. pdfDoc.WriteToFilePath(saveDialog.FileName);
  856. }
  857. }
  858. }
  859. }
  860. /// <summary>
  861. /// Save the file in the current path.
  862. /// </summary>
  863. public void SaveFile()
  864. {
  865. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  866. {
  867. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  868. if (pdfDoc.WriteToLoadedPath())
  869. {
  870. pdfViewControl.PDFView.UndoManager.CanSave = false;
  871. return;
  872. }
  873. SaveFileDialog saveDialog = new SaveFileDialog();
  874. saveDialog.Filter = "(*.pdf)|*.pdf";
  875. saveDialog.DefaultExt = ".pdf";
  876. saveDialog.OverwritePrompt = true;
  877. if (saveDialog.ShowDialog() == true)
  878. {
  879. pdfDoc.WriteToFilePath(saveDialog.FileName);
  880. }
  881. }
  882. }
  883. public void OpenFile()
  884. {
  885. string filePath = CommonHelper.GetFilePathOrEmpty();
  886. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  887. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  888. {
  889. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  890. {
  891. if (oldFilePath.ToLower() == filePath.ToLower())
  892. {
  893. return;
  894. }
  895. }
  896. if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
  897. {
  898. return;
  899. }
  900. passwordViewer = new PDFViewControl();
  901. passwordViewer.PDFView.InitDocument(filePath);
  902. if (passwordViewer.PDFView.Document == null)
  903. {
  904. MessageBox.Show("Open File Failed");
  905. return;
  906. }
  907. if (passwordViewer.PDFView.Document.IsLocked)
  908. {
  909. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  910. PasswordUI.ClearPassword();
  911. PopupBorder.Visibility = Visibility.Visible;
  912. PasswordUI.Visibility = Visibility.Visible;
  913. }
  914. else
  915. {
  916. pdfViewControl = passwordViewer;
  917. LoadDocument();
  918. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  919. }
  920. }
  921. }
  922. private void OpenFile_Click(object sender, RoutedEventArgs e)
  923. {
  924. OpenFile();
  925. }
  926. #endregion
  927. #region ToolPanel expand and collapse
  928. private void ExpandLeftPanel(bool isExpand)
  929. {
  930. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  931. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  932. if (isExpand)
  933. {
  934. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  935. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  936. }
  937. else
  938. {
  939. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  940. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  941. }
  942. }
  943. private void ControlLeftPanel()
  944. {
  945. if (LeftToolPanelButton != null)
  946. {
  947. bool isExpand = LeftToolPanelButton.IsChecked == true;
  948. ExpandLeftPanel(isExpand);
  949. }
  950. }
  951. private void ControlRightPanel()
  952. {
  953. if (RightPanelButton != null)
  954. {
  955. if (RightPanelButton.IsChecked == true)
  956. {
  957. if (currentMode == "Annotation")
  958. {
  959. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  960. }
  961. else if (currentMode == "Edit")
  962. {
  963. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  964. }
  965. else if (currentMode == "Forms")
  966. {
  967. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  968. }
  969. else
  970. {
  971. bool expandEmpty = true;
  972. if (currentMode == "Content Editor")
  973. {
  974. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  975. {
  976. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  977. {
  978. if (textEditControl == null)
  979. {
  980. textEditControl = new PDFTextEditControl();
  981. }
  982. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  983. ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
  984. expandEmpty = false;
  985. }
  986. }
  987. }
  988. if (expandEmpty)
  989. {
  990. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  991. }
  992. }
  993. if ((bool)ViewSettingBtn.IsChecked)
  994. {
  995. ViewSettingBtn.IsChecked = false;
  996. }
  997. }
  998. else
  999. {
  1000. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1001. }
  1002. }
  1003. }
  1004. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  1005. {
  1006. ControlLeftPanel();
  1007. }
  1008. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  1009. {
  1010. ExpandLeftPanel(true);
  1011. LeftToolPanelButton.IsChecked = true;
  1012. BotaSideTool.SelectBotaTool(BOTATools.Search);
  1013. }
  1014. private void ShowViewSettings()
  1015. {
  1016. if (ViewSettingBtn != null)
  1017. {
  1018. if (ViewSettingBtn.IsChecked == true)
  1019. {
  1020. displayPanel = new CPDFDisplaySettingsControl();
  1021. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  1022. PropertyContainer.Child = displayPanel;
  1023. PropertyContainer.Visibility = Visibility.Visible;
  1024. if ((bool)RightPanelButton.IsChecked)
  1025. {
  1026. RightPanelButton.IsChecked = false;
  1027. }
  1028. }
  1029. else
  1030. {
  1031. PropertyContainer.Child = null;
  1032. PropertyContainer.Visibility = Visibility.Collapsed;
  1033. }
  1034. }
  1035. }
  1036. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  1037. {
  1038. ShowViewSettings();
  1039. }
  1040. public void ExpandRightPropertyPanel(UIElement properytPanel, Visibility visible)
  1041. {
  1042. PropertyContainer.Width = 260;
  1043. PropertyContainer.Child = properytPanel;
  1044. PropertyContainer.Visibility = visible;
  1045. if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
  1046. {
  1047. RightPanelButton.IsChecked = false;
  1048. }
  1049. }
  1050. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  1051. {
  1052. ControlRightPanel();
  1053. }
  1054. #endregion
  1055. #region Event handle
  1056. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  1057. {
  1058. pdfAnnotationControl.LoadAnnotationPanel(e);
  1059. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  1060. {
  1061. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  1062. RightPanelButton.IsChecked = true;
  1063. }
  1064. }
  1065. private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1066. {
  1067. if ((bool)ViewSettingBtn.IsChecked)
  1068. {
  1069. ViewSettingBtn.IsChecked = false;
  1070. RightPanelButton.IsChecked = true;
  1071. }
  1072. PropertyContainer.Child = pdfAnnotationControl;
  1073. pdfAnnotationControl.SetAnnotEventData(e);
  1074. }
  1075. private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
  1076. {
  1077. if (e is WidgetSignArgs)
  1078. {
  1079. RightPanelButton.IsChecked = true;
  1080. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  1081. pdfFormControl.SetPropertyForType(e, null);
  1082. }
  1083. else
  1084. {
  1085. RightPanelButton.IsChecked = false;
  1086. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1087. }
  1088. }
  1089. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  1090. {
  1091. if (e == null)
  1092. {
  1093. return;
  1094. }
  1095. if (e.EditType == CPDFEditType.EditText)
  1096. {
  1097. e.Handle = true;
  1098. PDFEditTextContextMenu(sender, e);
  1099. }
  1100. if (e.EditType == CPDFEditType.EditImage)
  1101. {
  1102. e.Handle = true;
  1103. PDFEditImageContextMenu(sender, e);
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// Text and Image Selected Event
  1108. /// </summary>
  1109. private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
  1110. {
  1111. lastPDFEditEvent = e;
  1112. if ((bool)ViewSettingBtn.IsChecked)
  1113. {
  1114. ViewSettingBtn.IsChecked = false;
  1115. RightPanelButton.IsChecked = true;
  1116. }
  1117. if (e == null)
  1118. {
  1119. pdfEditControl = null;
  1120. PropertyContainer.Child = pdfEditControl;
  1121. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  1122. {
  1123. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  1124. {
  1125. if (textEditControl == null)
  1126. {
  1127. textEditControl = new PDFTextEditControl();
  1128. }
  1129. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  1130. PropertyContainer.Child = textEditControl;
  1131. }
  1132. }
  1133. return;
  1134. }
  1135. if (Mouse.RightButton == MouseButtonState.Pressed)
  1136. {
  1137. return;
  1138. }
  1139. if (e.EditType == CPDFEditType.EditText)
  1140. {
  1141. if (textEditControl == null)
  1142. {
  1143. textEditControl = new PDFTextEditControl();
  1144. }
  1145. textEditControl.SetPDFTextEditData(e);
  1146. pdfEditControl = textEditControl as UIElement;
  1147. PropertyContainer.Child = pdfEditControl;
  1148. return;
  1149. }
  1150. if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
  1151. {
  1152. RightPanelButton.IsChecked = true;
  1153. UIElement pageView = sender as UIElement;
  1154. if (pageView != null)
  1155. {
  1156. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp; ;
  1157. }
  1158. return;
  1159. }
  1160. }
  1161. private void PDFView_FormEditHandler(object sender, List<AnnotEditEvent> e)
  1162. {
  1163. if (e != null && e.Count > 0)
  1164. {
  1165. AnnotEditEvent editEvent = e[e.Count - 1];
  1166. if (editEvent.EditAction == ActionType.Add)
  1167. {
  1168. pdfViewControl.PDFView.SelectAnnotation(editEvent.PageIndex, editEvent.AnnotIndex);
  1169. }
  1170. }
  1171. }
  1172. private void PDFView_FormActiveHandler(object sender, AnnotAttribEvent e)
  1173. {
  1174. if (e == null || e.IsAnnotCreateReset)
  1175. {
  1176. pdfFormControl.SetPropertyForType(null, null);
  1177. }
  1178. else
  1179. {
  1180. switch (e.GetAnnotTypes())
  1181. {
  1182. case AnnotArgsType.WidgetViewForm:
  1183. WidgetArgs formArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.WidgetViewForm).First() as WidgetArgs;
  1184. switch (formArgs.WidgeType)
  1185. {
  1186. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  1187. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_COMBOBOX:
  1188. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_LISTBOX:
  1189. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  1190. if ((bool)ViewSettingBtn.IsChecked)
  1191. {
  1192. ViewSettingBtn.IsChecked = false;
  1193. }
  1194. RightPanelButton.IsChecked = true;
  1195. break;
  1196. default:
  1197. break;
  1198. }
  1199. pdfFormControl.SetPropertyForType(formArgs, e);
  1200. break;
  1201. }
  1202. }
  1203. }
  1204. private void PageEditControl_ExitPageEdit(object sender, EventArgs e)
  1205. {
  1206. ModeComboBox.SelectedIndex = 0;
  1207. }
  1208. private void PageEditControl_PageMoved(object sender, RoutedEventArgs e)
  1209. {
  1210. if (pdfViewControl == null || pdfViewControl.PDFView == null)
  1211. {
  1212. return;
  1213. }
  1214. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  1215. }
  1216. private void CPDFPageEditBarControl_PageEditEvent(object sender, string e)
  1217. {
  1218. pageEditControl.PageEdit(e);
  1219. }
  1220. private void CPDFTitleBarControl_SaveFileEvent(object sender, EventArgs e)
  1221. {
  1222. SaveFile();
  1223. }
  1224. private void CPDFTitleBarControl_SaveAsFileEvent(object sender, EventArgs e)
  1225. {
  1226. SaveAsFile();
  1227. }
  1228. private void CPDFTitleBarControl_OpenFileEvent(object sender, EventArgs e)
  1229. {
  1230. OpenFile();
  1231. }
  1232. public void PDFView_KeyDown(object sender, KeyEventArgs e)
  1233. {
  1234. if (pdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
  1235. {
  1236. return;
  1237. }
  1238. if (Keyboard.Modifiers == ModifierKeys.Control)
  1239. {
  1240. if (e.Key == Key.Left)
  1241. {
  1242. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
  1243. e.Handled = true;
  1244. }
  1245. if (e.Key == Key.Right)
  1246. {
  1247. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
  1248. e.Handled = true;
  1249. }
  1250. if (e.Key == Key.Up)
  1251. {
  1252. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
  1253. e.Handled = true;
  1254. }
  1255. if (e.Key == Key.Down)
  1256. {
  1257. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
  1258. e.Handled = true;
  1259. }
  1260. }
  1261. if (Keyboard.Modifiers == ModifierKeys.Shift)
  1262. {
  1263. if (e.Key == Key.Left)
  1264. {
  1265. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, true);
  1266. e.Handled = true;
  1267. }
  1268. if (e.Key == Key.Right)
  1269. {
  1270. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, true);
  1271. e.Handled = true;
  1272. }
  1273. if (e.Key == Key.Up)
  1274. {
  1275. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, true);
  1276. e.Handled = true;
  1277. }
  1278. if (e.Key == Key.Down)
  1279. {
  1280. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, true);
  1281. e.Handled = true;
  1282. }
  1283. }
  1284. if (Keyboard.Modifiers == ModifierKeys.Alt)
  1285. {
  1286. if (e.SystemKey == Key.Up)
  1287. {
  1288. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, true);
  1289. e.Handled = true;
  1290. }
  1291. if (e.SystemKey == Key.Down)
  1292. {
  1293. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, true);
  1294. e.Handled = true;
  1295. }
  1296. }
  1297. if (Keyboard.Modifiers == ModifierKeys.None)
  1298. {
  1299. if (e.Key == Key.Left)
  1300. {
  1301. pdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
  1302. e.Handled = true;
  1303. }
  1304. if (e.Key == Key.Right)
  1305. {
  1306. pdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
  1307. e.Handled = true;
  1308. }
  1309. if (e.Key == Key.Up)
  1310. {
  1311. pdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
  1312. e.Handled = true;
  1313. }
  1314. if (e.Key == Key.Down)
  1315. {
  1316. pdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
  1317. e.Handled = true;
  1318. }
  1319. }
  1320. }
  1321. #endregion
  1322. #region Change mode
  1323. /// <summary>
  1324. /// Actions performed when switching modes:
  1325. /// Separated into actions performed upon entering and exiting the mode.
  1326. /// </summary>
  1327. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1328. {
  1329. pdfTextCreateParam = null;
  1330. if (isFirstLoad)
  1331. {
  1332. isFirstLoad = false;
  1333. return;
  1334. }
  1335. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  1336. //Behavior when exit mode
  1337. switch (currentMode)
  1338. {
  1339. case "Viewer":
  1340. break;
  1341. /*
  1342. * Behavior when exit Edit mode
  1343. * Clear and collapse the ToolBar
  1344. * Clear And collapse the property panel.
  1345. * Change the mousemode to PanTool
  1346. * Unsubscribe the event handles
  1347. * Clear the undo history
  1348. */
  1349. case "Annotations":
  1350. AnnotationBarControl.Visibility = Visibility.Collapsed;
  1351. AnnotationBarControl.ClearAllToolState();
  1352. pdfAnnotationControl.ClearPanel();
  1353. if (!(bool)ViewSettingBtn.IsChecked)
  1354. {
  1355. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1356. }
  1357. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1358. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  1359. pdfAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  1360. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  1361. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1362. break;
  1363. /*
  1364. * Behavior when exit edit mode:
  1365. * Collapsed the ToolBar
  1366. * Highlight the link annotation
  1367. * Set the mode to not allow edit
  1368. * Set the mouse mode to PanTool
  1369. * Reload Document
  1370. * Unsubscribe click event.
  1371. * Clear And collapse the property panel.
  1372. * Clear and collapse the ToolBar
  1373. * Clear undo history
  1374. * CPDFDisplaySettingsControl
  1375. * Enable the configuration of the split view.
  1376. */
  1377. case "Content Editor":
  1378. PDFEditTool.Visibility = Visibility.Collapsed;
  1379. pdfViewControl.PDFView?.SetShowLink(true);
  1380. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
  1381. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1382. pdfViewControl.PDFView?.ReloadDocument();
  1383. pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  1384. if (!(bool)ViewSettingBtn.IsChecked)
  1385. {
  1386. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1387. }
  1388. ClearPDFEditState();
  1389. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1390. if (displayPanel != null)
  1391. {
  1392. displayPanel.SetVisibilityWhenContentEdit(Visibility.Visible);
  1393. }
  1394. break;
  1395. /*
  1396. * Behavior when exit form mode:
  1397. * Clear and collapsed the ToolBar
  1398. * Clear And Collapse the property panel.
  1399. * Unsubscribe event.
  1400. * Clear undo history
  1401. */
  1402. case "Forms":
  1403. if (!(bool)ViewSettingBtn.IsChecked)
  1404. {
  1405. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1406. }
  1407. FormBarControl.ClearAllToolState();
  1408. FormBarControl.Visibility = Visibility.Collapsed;
  1409. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1410. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_FormActiveHandler;
  1411. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_FormEditHandler;
  1412. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1413. break;
  1414. /*
  1415. * Unsubscribe event.
  1416. * Show Undo Redo Button
  1417. * Collapse PageEditBarControl
  1418. * Replace PDFGrid.Child to pdfViewControl.
  1419. * Reload Document
  1420. * Enable Button
  1421. */
  1422. case "Docs Editor":
  1423. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  1424. pageEditControl.PageMoved -= PageEditControl_PageMoved;
  1425. PageEditBarControl.PageEditEvent -= CPDFPageEditBarControl_PageEditEvent;
  1426. UndoRedoStackPanel.Visibility = Visibility.Visible;
  1427. PageEditBarControl.Visibility = Visibility.Collapsed;
  1428. PDFGrid.Child = pdfViewControl;
  1429. FloatPageTool.Visibility = Visibility.Visible;
  1430. pdfViewControl.PDFView.ReloadDocument();
  1431. LeftToolPanelButton.IsEnabled = true;
  1432. SearchButton.IsEnabled = true;
  1433. RightPanelButton.IsEnabled = true;
  1434. ViewSettingBtn.IsEnabled = true;
  1435. break;
  1436. default:
  1437. break;
  1438. }
  1439. /*
  1440. * Behavior when switching to Viewer mode:
  1441. * Hide the ToolBar
  1442. * Set mousemode to Viewer
  1443. */
  1444. if ((string)item.Content == "Viewer")
  1445. {
  1446. ToolBarContainer.Visibility = Visibility.Collapsed;
  1447. pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  1448. }
  1449. /*
  1450. * Behavior when switching to Annotation mode:
  1451. * Show the ToolBar
  1452. * Show the AnnotationBar
  1453. */
  1454. else if ((string)item.Content == "Annotations")
  1455. {
  1456. ToolBarContainer.Visibility = Visibility.Visible;
  1457. AnnotationBarControl.Visibility = Visibility.Visible;
  1458. pdfViewControl.PDFView.SetMouseMode(MouseModes.PanTool);
  1459. pdfAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  1460. pdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  1461. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  1462. }
  1463. /*
  1464. * Behavior when switching to Edit mode:
  1465. * Show the ToolBar
  1466. * Show the EditBar
  1467. * Set the mode to allow editing of both text and images
  1468. * Set the mouse mode to PDFEdit
  1469. * Reload Document
  1470. * Set the splite mode to None and unable the split setting
  1471. */
  1472. else if ((string)item.Content == "Content Editor")
  1473. {
  1474. ToolBarContainer.Visibility = Visibility.Visible;
  1475. PDFEditTool.Visibility = Visibility.Visible;
  1476. PageEditBarControl.Visibility = Visibility.Collapsed;
  1477. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
  1478. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  1479. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1480. pdfViewControl.PDFView?.ReloadDocument();
  1481. pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  1482. pdfViewControl.PDFView.SetSplitMode(SplitMode.None);
  1483. if (displayPanel != null)
  1484. {
  1485. displayPanel.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  1486. }
  1487. }
  1488. /*
  1489. * Behavior when switching to Form mode:
  1490. *
  1491. */
  1492. else if ((string)item.Content == "Forms")
  1493. {
  1494. ToolBarContainer.Visibility = Visibility.Visible;
  1495. FormBarControl.Visibility = Visibility.Visible;
  1496. pdfViewControl.PDFView?.SetShowLink(true);
  1497. pdfViewControl.PDFView?.SetMouseMode(MouseModes.FormEditTool);
  1498. pdfViewControl.PDFView?.ReloadDocument();
  1499. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_FormActiveHandler;
  1500. pdfViewControl.PDFView.AnnotEditHandler += PDFView_FormEditHandler;
  1501. }
  1502. /*
  1503. *
  1504. */
  1505. else if ((string)item.Content == "Docs Editor")
  1506. {
  1507. ToolBarContainer.Visibility = Visibility.Visible;
  1508. if (pageEditControl == null)
  1509. {
  1510. pageEditControl = new CPDFPageEditControl();
  1511. }
  1512. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit; ;
  1513. pageEditControl.PageMoved += PageEditControl_PageMoved; ;
  1514. PageEditBarControl.PageEditEvent += CPDFPageEditBarControl_PageEditEvent;
  1515. pageEditControl.LoadThumbnails(pdfViewControl.PDFView);
  1516. PDFGrid.Child = pageEditControl;
  1517. UndoRedoStackPanel.Visibility = Visibility.Collapsed;
  1518. PageEditBarControl.Visibility = Visibility.Visible;
  1519. LeftToolPanelButton.IsChecked = false;
  1520. LeftToolPanelButton.IsEnabled = false;
  1521. SearchButton.IsEnabled = false;
  1522. RightPanelButton.IsChecked = false;
  1523. RightPanelButton.IsEnabled = false;
  1524. ViewSettingBtn.IsChecked = false;
  1525. ViewSettingBtn.IsEnabled = false;
  1526. ExpandLeftPanel(false);
  1527. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1528. FloatPageTool.Visibility = Visibility.Collapsed;
  1529. }
  1530. currentMode = (string)item.Content;
  1531. }
  1532. #endregion
  1533. #region Shortcut
  1534. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  1535. {
  1536. OpenFile();
  1537. }
  1538. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  1539. {
  1540. if (CanSave)
  1541. {
  1542. SaveFile();
  1543. }
  1544. }
  1545. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  1546. {
  1547. SaveAsFile();
  1548. }
  1549. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  1550. {
  1551. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanUndo)
  1552. {
  1553. pdfViewControl.PDFView.UndoManager?.Undo();
  1554. }
  1555. }
  1556. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  1557. {
  1558. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanRedo)
  1559. {
  1560. pdfViewControl.PDFView.UndoManager?.Redo();
  1561. }
  1562. }
  1563. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  1564. {
  1565. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  1566. ControlLeftPanel();
  1567. }
  1568. private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
  1569. {
  1570. RightPanelButton.IsChecked = !RightPanelButton.IsChecked;
  1571. ControlRightPanel();
  1572. }
  1573. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  1574. {
  1575. ExpandLeftPanel(true);
  1576. LeftToolPanelButton.IsChecked = true;
  1577. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  1578. }
  1579. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  1580. {
  1581. ExpandLeftPanel(true);
  1582. LeftToolPanelButton.IsChecked = true;
  1583. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  1584. }
  1585. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  1586. {
  1587. ExpandLeftPanel(true);
  1588. LeftToolPanelButton.IsChecked = true;
  1589. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  1590. }
  1591. private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
  1592. {
  1593. ExpandLeftPanel(true);
  1594. LeftToolPanelButton.IsChecked = true;
  1595. BotaSideTool.SelectBotaTool(BOTATools.Annotation);
  1596. }
  1597. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  1598. {
  1599. ExpandLeftPanel(true);
  1600. LeftToolPanelButton.IsChecked = true;
  1601. BotaSideTool.SelectBotaTool(BOTATools.Search);
  1602. }
  1603. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  1604. {
  1605. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  1606. pdfViewControl.PDFView?.Zoom(newZoom);
  1607. }
  1608. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  1609. {
  1610. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  1611. pdfViewControl.PDFView?.Zoom(newZoom);
  1612. }
  1613. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  1614. {
  1615. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  1616. ShowViewSettings();
  1617. }
  1618. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  1619. {
  1620. if (PopupBorder.Visibility != Visibility.Visible)
  1621. {
  1622. PasswordUI.Visibility = Visibility.Collapsed;
  1623. FileInfoUI.Visibility = Visibility.Visible;
  1624. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  1625. PopupBorder.Visibility = Visibility.Visible;
  1626. }
  1627. else
  1628. {
  1629. FileInfoUI.Visibility = Visibility.Collapsed;
  1630. PopupBorder.Visibility = Visibility.Collapsed;
  1631. }
  1632. }
  1633. #endregion
  1634. }
  1635. }