MainPage.xaml.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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. private void CommandBinding_Executed_Highlight(object sender, ExecutedRoutedEventArgs e)
  1657. {
  1658. if (currentMode == "Annotations")
  1659. {
  1660. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Highlight);
  1661. }
  1662. }
  1663. private void CommandBinding_Executed_Underline(object sender, ExecutedRoutedEventArgs e)
  1664. {
  1665. if (currentMode == "Annotations")
  1666. {
  1667. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Underline);
  1668. }
  1669. }
  1670. private void CommandBinding_Executed_Strikeout(object sender, ExecutedRoutedEventArgs e)
  1671. {
  1672. if (currentMode == "Annotations")
  1673. {
  1674. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Strikeout);
  1675. }
  1676. }
  1677. private void CommandBinding_Executed_Squiggly(object sender, ExecutedRoutedEventArgs e)
  1678. {
  1679. if (currentMode == "Annotations")
  1680. {
  1681. AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Squiggly);
  1682. }
  1683. }
  1684. #endregion
  1685. }
  1686. }