MainPage.xaml.cs 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  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 ((bool)ViewSettingBtn.IsChecked)
  954. {
  955. ViewSettingBtn.IsChecked = false;
  956. }
  957. if (RightPanelButton != null)
  958. {
  959. if (RightPanelButton.IsChecked == true)
  960. {
  961. if (currentMode == "Annotation")
  962. {
  963. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  964. }
  965. else if (currentMode == "Edit")
  966. {
  967. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  968. }
  969. else if (currentMode == "Forms")
  970. {
  971. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  972. }
  973. else
  974. {
  975. bool expandEmpty = true;
  976. if (currentMode == "Content Editor")
  977. {
  978. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  979. {
  980. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  981. {
  982. if (textEditControl == null)
  983. {
  984. textEditControl = new PDFTextEditControl();
  985. }
  986. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  987. ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
  988. expandEmpty = false;
  989. }
  990. }
  991. }
  992. if (expandEmpty)
  993. {
  994. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  995. }
  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. if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
  1321. {
  1322. if (e.Key == Key.Left)
  1323. {
  1324. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, true);
  1325. e.Handled = true;
  1326. }
  1327. if (e.Key == Key.Right)
  1328. {
  1329. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, true);
  1330. e.Handled = true;
  1331. }
  1332. if (e.Key == Key.Up)
  1333. {
  1334. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, true);
  1335. e.Handled = true;
  1336. }
  1337. if (e.Key == Key.Down)
  1338. {
  1339. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, true);
  1340. e.Handled = true;
  1341. }
  1342. }
  1343. }
  1344. #endregion
  1345. #region Change mode
  1346. /// <summary>
  1347. /// Actions performed when switching modes:
  1348. /// Separated into actions performed upon entering and exiting the mode.
  1349. /// </summary>
  1350. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1351. {
  1352. pdfTextCreateParam = null;
  1353. if (isFirstLoad)
  1354. {
  1355. isFirstLoad = false;
  1356. return;
  1357. }
  1358. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  1359. //Behavior when exit mode
  1360. switch (currentMode)
  1361. {
  1362. case "Viewer":
  1363. break;
  1364. /*
  1365. * Behavior when exit Edit mode
  1366. * Clear and collapse the ToolBar
  1367. * Clear And collapse the property panel.
  1368. * Change the mousemode to PanTool
  1369. * Unsubscribe the event handles
  1370. * Clear the undo history
  1371. */
  1372. case "Annotations":
  1373. AnnotationBarControl.Visibility = Visibility.Collapsed;
  1374. AnnotationBarControl.ClearAllToolState();
  1375. pdfAnnotationControl.ClearPanel();
  1376. if (!(bool)ViewSettingBtn.IsChecked)
  1377. {
  1378. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1379. }
  1380. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1381. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  1382. pdfAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  1383. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  1384. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1385. break;
  1386. /*
  1387. * Behavior when exit edit mode:
  1388. * Collapsed the ToolBar
  1389. * Highlight the link annotation
  1390. * Set the mode to not allow edit
  1391. * Set the mouse mode to PanTool
  1392. * Reload Document
  1393. * Unsubscribe click event.
  1394. * Clear And collapse the property panel.
  1395. * Clear and collapse the ToolBar
  1396. * Clear undo history
  1397. * CPDFDisplaySettingsControl
  1398. * Enable the configuration of the split view.
  1399. */
  1400. case "Content Editor":
  1401. PDFEditTool.Visibility = Visibility.Collapsed;
  1402. pdfViewControl.PDFView?.SetShowLink(true);
  1403. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
  1404. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1405. pdfViewControl.PDFView?.ReloadDocument();
  1406. pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  1407. if (!(bool)ViewSettingBtn.IsChecked)
  1408. {
  1409. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1410. }
  1411. ClearPDFEditState();
  1412. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1413. if (displayPanel != null)
  1414. {
  1415. displayPanel.SetVisibilityWhenContentEdit(Visibility.Visible);
  1416. }
  1417. break;
  1418. /*
  1419. * Behavior when exit form mode:
  1420. * Clear and collapsed the ToolBar
  1421. * Clear And Collapse the property panel.
  1422. * Unsubscribe event.
  1423. * Clear undo history
  1424. */
  1425. case "Forms":
  1426. if (!(bool)ViewSettingBtn.IsChecked)
  1427. {
  1428. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1429. }
  1430. FormBarControl.ClearAllToolState();
  1431. FormBarControl.Visibility = Visibility.Collapsed;
  1432. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1433. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_FormActiveHandler;
  1434. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_FormEditHandler;
  1435. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1436. break;
  1437. /*
  1438. * Unsubscribe event.
  1439. * Show Undo Redo Button
  1440. * Collapse PageEditBarControl
  1441. * Replace PDFGrid.Child to pdfViewControl.
  1442. * Reload Document
  1443. * Enable Button
  1444. */
  1445. case "Docs Editor":
  1446. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  1447. pageEditControl.PageMoved -= PageEditControl_PageMoved;
  1448. PageEditBarControl.PageEditEvent -= CPDFPageEditBarControl_PageEditEvent;
  1449. UndoRedoStackPanel.Visibility = Visibility.Visible;
  1450. PageEditBarControl.Visibility = Visibility.Collapsed;
  1451. PDFGrid.Child = pdfViewControl;
  1452. FloatPageTool.Visibility = Visibility.Visible;
  1453. pdfViewControl.PDFView.ReloadDocument();
  1454. LeftToolPanelButton.IsEnabled = true;
  1455. SearchButton.IsEnabled = true;
  1456. RightPanelButton.IsEnabled = true;
  1457. ViewSettingBtn.IsEnabled = true;
  1458. break;
  1459. default:
  1460. break;
  1461. }
  1462. /*
  1463. * Behavior when switching to Viewer mode:
  1464. * Hide the ToolBar
  1465. * Set mousemode to Viewer
  1466. */
  1467. if ((string)item.Content == "Viewer")
  1468. {
  1469. ToolBarContainer.Visibility = Visibility.Collapsed;
  1470. pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  1471. }
  1472. /*
  1473. * Behavior when switching to Annotation mode:
  1474. * Show the ToolBar
  1475. * Show the AnnotationBar
  1476. */
  1477. else if ((string)item.Content == "Annotations")
  1478. {
  1479. ToolBarContainer.Visibility = Visibility.Visible;
  1480. AnnotationBarControl.Visibility = Visibility.Visible;
  1481. pdfViewControl.PDFView.SetMouseMode(MouseModes.PanTool);
  1482. pdfAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  1483. pdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  1484. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  1485. }
  1486. /*
  1487. * Behavior when switching to Edit mode:
  1488. * Show the ToolBar
  1489. * Show the EditBar
  1490. * Set the mode to allow editing of both text and images
  1491. * Set the mouse mode to PDFEdit
  1492. * Reload Document
  1493. * Set the splite mode to None and unable the split setting
  1494. */
  1495. else if ((string)item.Content == "Content Editor")
  1496. {
  1497. ToolBarContainer.Visibility = Visibility.Visible;
  1498. PDFEditTool.Visibility = Visibility.Visible;
  1499. PageEditBarControl.Visibility = Visibility.Collapsed;
  1500. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
  1501. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  1502. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1503. pdfViewControl.PDFView?.ReloadDocument();
  1504. pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  1505. pdfViewControl.PDFView.SetSplitMode(SplitMode.None);
  1506. if (displayPanel != null)
  1507. {
  1508. displayPanel.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  1509. }
  1510. }
  1511. /*
  1512. * Behavior when switching to Form mode:
  1513. *
  1514. */
  1515. else if ((string)item.Content == "Forms")
  1516. {
  1517. ToolBarContainer.Visibility = Visibility.Visible;
  1518. FormBarControl.Visibility = Visibility.Visible;
  1519. pdfViewControl.PDFView?.SetShowLink(true);
  1520. pdfViewControl.PDFView?.SetMouseMode(MouseModes.FormEditTool);
  1521. pdfViewControl.PDFView?.ReloadDocument();
  1522. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_FormActiveHandler;
  1523. pdfViewControl.PDFView.AnnotEditHandler += PDFView_FormEditHandler;
  1524. }
  1525. /*
  1526. *
  1527. */
  1528. else if ((string)item.Content == "Docs Editor")
  1529. {
  1530. ToolBarContainer.Visibility = Visibility.Visible;
  1531. if (pageEditControl == null)
  1532. {
  1533. pageEditControl = new CPDFPageEditControl();
  1534. }
  1535. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit; ;
  1536. pageEditControl.PageMoved += PageEditControl_PageMoved; ;
  1537. PageEditBarControl.PageEditEvent += CPDFPageEditBarControl_PageEditEvent;
  1538. pageEditControl.LoadThumbnails(pdfViewControl.PDFView);
  1539. PDFGrid.Child = pageEditControl;
  1540. UndoRedoStackPanel.Visibility = Visibility.Collapsed;
  1541. PageEditBarControl.Visibility = Visibility.Visible;
  1542. LeftToolPanelButton.IsChecked = false;
  1543. LeftToolPanelButton.IsEnabled = false;
  1544. SearchButton.IsEnabled = false;
  1545. RightPanelButton.IsChecked = false;
  1546. RightPanelButton.IsEnabled = false;
  1547. ViewSettingBtn.IsChecked = false;
  1548. ViewSettingBtn.IsEnabled = false;
  1549. ExpandLeftPanel(false);
  1550. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1551. FloatPageTool.Visibility = Visibility.Collapsed;
  1552. }
  1553. currentMode = (string)item.Content;
  1554. }
  1555. #endregion
  1556. #region Shortcut
  1557. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  1558. {
  1559. OpenFile();
  1560. }
  1561. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  1562. {
  1563. if (CanSave)
  1564. {
  1565. SaveFile();
  1566. }
  1567. }
  1568. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  1569. {
  1570. SaveAsFile();
  1571. }
  1572. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  1573. {
  1574. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanUndo)
  1575. {
  1576. pdfViewControl.PDFView.UndoManager?.Undo();
  1577. }
  1578. }
  1579. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  1580. {
  1581. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanRedo)
  1582. {
  1583. pdfViewControl.PDFView.UndoManager?.Redo();
  1584. }
  1585. }
  1586. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  1587. {
  1588. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  1589. ControlLeftPanel();
  1590. }
  1591. private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
  1592. {
  1593. RightPanelButton.IsChecked = !RightPanelButton.IsChecked;
  1594. ControlRightPanel();
  1595. }
  1596. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  1597. {
  1598. ExpandLeftPanel(true);
  1599. LeftToolPanelButton.IsChecked = true;
  1600. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  1601. }
  1602. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  1603. {
  1604. ExpandLeftPanel(true);
  1605. LeftToolPanelButton.IsChecked = true;
  1606. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  1607. }
  1608. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  1609. {
  1610. ExpandLeftPanel(true);
  1611. LeftToolPanelButton.IsChecked = true;
  1612. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  1613. }
  1614. private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
  1615. {
  1616. ExpandLeftPanel(true);
  1617. LeftToolPanelButton.IsChecked = true;
  1618. BotaSideTool.SelectBotaTool(BOTATools.Annotation);
  1619. }
  1620. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  1621. {
  1622. ExpandLeftPanel(true);
  1623. LeftToolPanelButton.IsChecked = true;
  1624. BotaSideTool.SelectBotaTool(BOTATools.Search);
  1625. }
  1626. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  1627. {
  1628. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  1629. pdfViewControl.PDFView?.Zoom(newZoom);
  1630. }
  1631. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  1632. {
  1633. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  1634. pdfViewControl.PDFView?.Zoom(newZoom);
  1635. }
  1636. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  1637. {
  1638. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  1639. ShowViewSettings();
  1640. }
  1641. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  1642. {
  1643. if (PopupBorder.Visibility != Visibility.Visible)
  1644. {
  1645. PasswordUI.Visibility = Visibility.Collapsed;
  1646. FileInfoUI.Visibility = Visibility.Visible;
  1647. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  1648. PopupBorder.Visibility = Visibility.Visible;
  1649. }
  1650. else
  1651. {
  1652. FileInfoUI.Visibility = Visibility.Collapsed;
  1653. PopupBorder.Visibility = Visibility.Collapsed;
  1654. }
  1655. }
  1656. #endregion
  1657. }
  1658. }