MainPage.xaml.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFAnnotation.Form;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.Tool;
  5. using ComPDFKit.Tool.Help;
  6. using ComPDFKit.Controls.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  7. using ComPDFKit.Controls.Helper;
  8. using ComPDFKit.Controls.Measure;
  9. using ComPDFKit.Controls.PDFControl;
  10. using ComPDFKit.Controls.PDFView;
  11. using ComPDFKitViewer;
  12. using ComPDFKitViewer.Widget;
  13. using Microsoft.Win32;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Runtime.CompilerServices;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Controls.Primitives;
  21. using System.Windows.Input;
  22. using ComPDFKit.Controls.PDFControlUI;
  23. using ComPDFKit.Controls.Snapshot;
  24. using System.Windows.Media;
  25. namespace PDFViewer
  26. {
  27. public partial class MainPage : UserControl, INotifyPropertyChanged
  28. {
  29. #region Properties
  30. private string currentMode = "Viewer";
  31. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  32. private PDFViewControl viewControl;
  33. private PDFViewControl passwordViewer;
  34. private RegularViewerControl regularViewerControl = new RegularViewerControl();
  35. private AnnotationControl annotationControl = new AnnotationControl();
  36. private FormControl formControl = new FormControl();
  37. private ContentEditControl contentEditControl = new ContentEditControl();
  38. private PageEditControl pageEditControl = new PageEditControl();
  39. private MeasureControl measureControl = new MeasureControl();
  40. private DigitalSignatureControl digitalSignatureControl = new DigitalSignatureControl();
  41. private SignatureStatusBarControl signatureStatusBarControl = new SignatureStatusBarControl();
  42. private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl();
  43. private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
  44. private PanelState panelState = PanelState.GetInstance();
  45. public event EventHandler FileChangeEvent;
  46. public event Func<string[], bool> CheckExistBeforeOpenFileEvent;
  47. public event EventHandler<string> AfterSaveAsFileEvent;
  48. public event PropertyChangedEventHandler PropertyChanged;
  49. private bool _canSave = false;
  50. /// <summary>
  51. /// Whether the save operation can be performed.
  52. /// </summary>
  53. public bool CanSave
  54. {
  55. get => _canSave;
  56. set
  57. {
  58. _canSave = value;
  59. OnPropertyChanged();
  60. }
  61. }
  62. public PDFViewControl GetPDFViewControl()
  63. {
  64. return viewControl;
  65. }
  66. /// <summary>
  67. /// Whether the left panel is expanded.
  68. /// </summary>
  69. public bool LeftToolPanelButtonIsChecked
  70. {
  71. get => panelState.IsLeftPanelExpand;
  72. set
  73. {
  74. panelState.IsLeftPanelExpand = value;
  75. OnPropertyChanged();
  76. }
  77. }
  78. /// <summary>
  79. /// Whether the right panel is expanded.
  80. /// </summary>
  81. public bool RightToolPanelButtonIsChecked
  82. {
  83. get => panelState.RightPanel == PanelState.RightPanelState.PropertyPanel;
  84. set
  85. {
  86. panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  87. OnPropertyChanged();
  88. }
  89. }
  90. /// <summary>
  91. /// Whether the view setting panel is expanded.
  92. /// </summary>
  93. public bool ViewSettingBtnIsChecked
  94. {
  95. get
  96. {
  97. return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
  98. }
  99. set
  100. {
  101. panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  102. OnPropertyChanged();
  103. }
  104. }
  105. private Visibility _notDocsEditorVisible = Visibility.Visible;
  106. /// <summary>
  107. /// Whether the Document Editor panel is visible.
  108. /// </summary>
  109. public Visibility NotDocsEditorVisible
  110. {
  111. get => _notDocsEditorVisible;
  112. set
  113. {
  114. _notDocsEditorVisible = value;
  115. OnPropertyChanged();
  116. }
  117. }
  118. public MainPage()
  119. {
  120. InitializeComponent();
  121. this.DataContext = this;
  122. }
  123. #endregion
  124. #region Load document
  125. /// <summary>
  126. /// Initialize the PDFViewer and load the PDF file.
  127. /// </summary>
  128. /// <param name="filePath"></param>
  129. public void InitWithFilePath(string filePath)
  130. {
  131. viewControl = new PDFViewControl();
  132. viewControl.InitDocument(filePath);
  133. }
  134. public void InitWithDocument(CPDFDocument document)
  135. {
  136. viewControl = new PDFViewControl();
  137. viewControl.GetCPDFViewer().InitDoc(document);
  138. }
  139. /// <summary>
  140. /// Init controls and set events.
  141. /// </summary>
  142. private void LoadDocument()
  143. {
  144. if (viewControl != null && viewControl.PDFViewTool != null)
  145. {
  146. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  147. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  148. if (pdfDoc == null)
  149. {
  150. return;
  151. }
  152. SizeChanged -= MainPage_SizeChanged;
  153. SizeChanged += MainPage_SizeChanged;
  154. PasswordUI.Closed -= PasswordUI_Closed;
  155. PasswordUI.Canceled -= PasswordUI_Canceled;
  156. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  157. PasswordUI.Closed += PasswordUI_Closed;
  158. PasswordUI.Canceled += PasswordUI_Canceled;
  159. PasswordUI.Confirmed += PasswordUI_Confirmed;
  160. CPDFSaclingControl.InitWithPDFViewer(viewControl);
  161. ModeComboBox.SelectedIndex = 0;
  162. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfviewer.GetZoom() * 100)));
  163. botaBarControl.AddBOTAContent(new[] { BOTATools.Thumbnail, BOTATools.Outline, BOTATools.Bookmark, BOTATools.Annotation, BOTATools.Search });
  164. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  165. ViewSettingBtn.IsChecked = false;
  166. botaBarControl.InitWithPDFViewer(viewControl);
  167. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  168. displaySettingsControl.InitWithPDFViewer(viewControl);
  169. LoadCustomControl();
  170. panelState.PropertyChanged -= PanelState_PropertyChanged;
  171. panelState.PropertyChanged += PanelState_PropertyChanged;
  172. displaySettingsControl.SplitModeChanged -= DisplaySettingsControl_SplitModeChanged;
  173. displaySettingsControl.SplitModeChanged += DisplaySettingsControl_SplitModeChanged;
  174. viewControl.PDFToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  175. viewControl.PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  176. pdfviewer.SetLinkHighlight(Properties.Settings.Default.IsHighlightLinkArea);
  177. pdfviewer.SetFormFieldHighlight(Properties.Settings.Default.IsHighlightFormArea);
  178. pdfviewer.GetDocument().FontSubset = Properties.Settings.Default.FontSubsetting;
  179. pdfviewer.ScrollStride = Properties.Settings.Default.Divisor;
  180. }
  181. }
  182. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  183. {
  184. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  185. {
  186. BaseWidget baseWidget = viewControl.GetCacheHitTestWidget();
  187. if (baseWidget != null)
  188. {
  189. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  190. viewControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  191. baseWidget.GetAnnotData().PageIndex,
  192. baseWidget.GetAnnotData().Annot);
  193. if ((annotParam as WidgetParm).WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
  194. {
  195. var sigWidget = baseWidget.GetAnnotData().Annot as CPDFSignatureWidget;
  196. if(sigWidget == null)
  197. {
  198. return;
  199. }
  200. var sig = sigWidget.GetSignature(viewControl.GetCPDFViewer().GetDocument());
  201. if (sigWidget.IsSigned() && sig != null && sig.SignerList.Count > 0)
  202. {
  203. return;
  204. }
  205. if (currentMode == "Annotation")
  206. {
  207. CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
  208. signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
  209. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  210. annotationControl.SetPropertyContainer(signatureProperty);
  211. }
  212. else if (currentMode == "Viewer")
  213. {
  214. CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
  215. signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
  216. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  217. regularViewerControl.SetPropertyContainer(signatureProperty);
  218. }
  219. }
  220. }
  221. }
  222. }
  223. private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
  224. {
  225. viewControl.WindowSizeChange();
  226. }
  227. private void DisplaySettingsControl_SplitModeChanged(object sender, ComPDFKit.Controls.PDFControlUI.CPDFViewModeUI.SplitMode e)
  228. {
  229. viewControl.SetSplitViewMode(e);
  230. }
  231. /// <summary>
  232. /// When the RightPanel state is changed, decide whether to display the ViewSettingPanel or RightToolPanel.
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  237. {
  238. if (e.PropertyName == "RightPanel")
  239. {
  240. OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
  241. OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
  242. }
  243. }
  244. public void SetFeatureMode(string featureName)
  245. {
  246. if (!string.IsNullOrEmpty(featureName))
  247. {
  248. switch (featureName)
  249. {
  250. case "Viewer":
  251. ModeComboBox.SelectedIndex = 0;
  252. break;
  253. case "Annotations":
  254. ModeComboBox.SelectedIndex = 1;
  255. break;
  256. case "Forms":
  257. ModeComboBox.SelectedIndex = 2;
  258. break;
  259. case "Signatures":
  260. ModeComboBox.SelectedIndex = 5;
  261. break;
  262. case "Document Editor":
  263. ModeComboBox.SelectedIndex = 4;
  264. break;
  265. case "Content Editor":
  266. ModeComboBox.SelectedIndex = 3;
  267. break;
  268. case "Measurement":
  269. ModeComboBox.SelectedIndex = 6;
  270. break;
  271. default:
  272. break;
  273. }
  274. }
  275. }
  276. internal void SetPDFViewer(PDFViewControl newPdfViewer)
  277. {
  278. if (newPdfViewer != null)
  279. {
  280. viewControl = newPdfViewer;
  281. }
  282. }
  283. #endregion
  284. #region Password
  285. /// <summary>
  286. /// Event handler for confirming the password. Open the PDF file if the password is correct.
  287. /// </summary>
  288. /// <param name="sender"></param>
  289. /// <param name="e"></param>
  290. private void PasswordUI_Confirmed(object sender, string e)
  291. {
  292. if (passwordViewer != null && passwordViewer.PDFViewTool != null)
  293. {
  294. CPDFViewer pdfviewer = passwordViewer.PDFViewTool.GetCPDFViewer();
  295. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  296. if (pdfDoc == null)
  297. {
  298. return;
  299. }
  300. pdfDoc.UnlockWithPassword(e);
  301. if (pdfDoc.IsLocked == false)
  302. {
  303. PasswordUI.SetShowError("", Visibility.Collapsed);
  304. PasswordUI.ClearPassword();
  305. PasswordUI.Visibility = Visibility.Collapsed;
  306. PopupBorder.Visibility = Visibility.Collapsed;
  307. viewControl = passwordViewer;
  308. LoadDocument();
  309. viewControl.PDFViewTool.GetCPDFViewer().UpdateVirtualNodes();
  310. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  311. }
  312. else
  313. {
  314. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  315. }
  316. }
  317. }
  318. /// <summary>
  319. /// Event handler for canceling password input.
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void PasswordUI_Canceled(object sender, EventArgs e)
  324. {
  325. PopupBorder.Visibility = Visibility.Collapsed;
  326. PasswordUI.Visibility = Visibility.Collapsed;
  327. }
  328. /// <summary>
  329. /// Event handler for closing the password input dialog.
  330. /// </summary>
  331. /// <param name="sender"></param>
  332. /// <param name="e"></param>
  333. private void PasswordUI_Closed(object sender, EventArgs e)
  334. {
  335. PopupBorder.Visibility = Visibility.Collapsed;
  336. PasswordUI.Visibility = Visibility.Collapsed;
  337. }
  338. #endregion
  339. #region Load custom control
  340. /// <summary>
  341. /// Load the custom controls for the PDF viewer.
  342. /// </summary>
  343. private void LoadCustomControl()
  344. {
  345. regularViewerControl.PdfViewControl = viewControl;
  346. regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  347. regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  348. regularViewerControl.InitWithPDFViewer(viewControl);
  349. //regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  350. regularViewerControl.SetBOTAContainer(null);
  351. regularViewerControl.SetBOTAContainer(botaBarControl);
  352. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  353. PDFGrid.Child = regularViewerControl;
  354. SignatureHelper.InitEffectiveSignatureList(viewControl.GetCPDFViewer().GetDocument());
  355. SignatureHelper.VerifySignatureList(viewControl.GetCPDFViewer().GetDocument());
  356. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  357. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  358. viewControl.PDFViewTool.DocumentModifiedChanged -= PDFViewTool_DocumentModifiedChanged;
  359. viewControl.PDFViewTool.DocumentModifiedChanged += PDFViewTool_DocumentModifiedChanged;
  360. }
  361. /// <summary>
  362. /// Event handler for the Loaded event of the MainPage.
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void MainPage_Loaded(object sender, RoutedEventArgs e)
  367. {
  368. LoadDocument();
  369. }
  370. #endregion
  371. #region Event handle
  372. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  373. {
  374. if (e.Key == "Zoom")
  375. {
  376. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  377. }
  378. }
  379. /// <summary>
  380. /// Command for opening a PDF file saved with a signature.
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
  385. {
  386. OpenFile(e);
  387. }
  388. /// <summary>
  389. /// Event handler for deleting a signature from the BOTA. Set the CanSave property to true and update the signature status.
  390. /// </summary>
  391. /// <param name="sender"></param>
  392. /// <param name="e"></param>
  393. private void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
  394. {
  395. DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
  396. }
  397. /// <summary>
  398. /// Event handler for updating a signature. Update the signature status.
  399. /// </summary>
  400. /// <param name="sender"></param>
  401. /// <param name="e"></param>
  402. private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
  403. {
  404. SignatureHelper.InitEffectiveSignatureList(viewControl.GetCPDFViewer().GetDocument());
  405. SignatureHelper.VerifySignatureList(viewControl.GetCPDFViewer().GetDocument());
  406. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  407. botaBarControl.LoadSignatureList();
  408. }
  409. /// <summary>
  410. /// Event handler for updating the CanSave property.
  411. /// </summary>
  412. /// <param name="sender"></param>
  413. /// <param name="e"></param>
  414. private void DigitalSignatureControl_OnCanSaveChanged(object sender, bool e)
  415. {
  416. this.CanSave = e;
  417. }
  418. #endregion
  419. #region Private Command Event
  420. /// <summary>
  421. /// Close all the expanded panels.
  422. /// </summary>
  423. private void ClearPanelState()
  424. {
  425. LeftToolPanelButtonIsChecked = false;
  426. ViewSettingBtnIsChecked = false;
  427. RightToolPanelButtonIsChecked = false;
  428. }
  429. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  430. {
  431. panelState.IsLeftPanelExpand = (sender as ToggleButton).IsChecked == true;
  432. }
  433. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  434. {
  435. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  436. if ((string)item.Tag == currentMode)
  437. {
  438. return;
  439. }
  440. if((string)item.Tag == "Viewer" || (string)item.Tag == "Annotation")
  441. {
  442. SnapshotButton.Visibility = Visibility.Visible;
  443. }
  444. else
  445. {
  446. SnapshotButton.Visibility = Visibility.Collapsed;
  447. }
  448. ClearPanelState();
  449. if (ViewSettingBtn != null)
  450. ViewSettingBtn.IsChecked = false;
  451. if (RightPanelButton != null)
  452. RightPanelButton.IsChecked = false;
  453. if (viewControl != null && viewControl.GetCPDFViewer() != null)
  454. {
  455. // pdfViewer.PDFView.ToolManager.EnableClickCreate = false;
  456. }
  457. if (currentMode == "Viewer")
  458. {
  459. regularViewerControl.ClearViewerControl();
  460. }
  461. else if (currentMode == "Annotation")
  462. {
  463. annotationControl.UnloadEvent();
  464. annotationControl.ClearViewerControl();
  465. annotationControl.PDFAnnotationControl.AnnotationCancel();
  466. viewControl.SetIsShowStampMouse(false);
  467. }
  468. else if (currentMode == "Form")
  469. {
  470. formControl.UnloadEvent();
  471. formControl.ClearViewerControl();
  472. viewControl.SetIsShowStampMouse(false);
  473. viewControl.GetCPDFViewer().SetFormFieldHighlight(Properties.Settings.Default.IsHighlightFormArea);
  474. }
  475. else if (currentMode == "Content Editor")
  476. {
  477. botaBarControl.ReplaceFunctionEnabled = false;
  478. displaySettingsControl.SetVisibilityWhenContentEdit(Visibility.Visible);
  479. contentEditControl.ClearViewerControl();
  480. contentEditControl.ClearPDFEditState();
  481. }
  482. else if (currentMode == "Document Editor")
  483. {
  484. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  485. NotDocsEditorVisible = Visibility.Visible;
  486. botaBarControl.LoadThumbnail();
  487. }
  488. else if (currentMode == "Digital Signature")
  489. {
  490. RightPanelButton.Visibility = Visibility.Visible;
  491. digitalSignatureControl.ClearViewerControl();
  492. botaBarControl.RemoveBOTAContent(BOTATools.Signature);
  493. digitalSignatureControl.UnloadEvent();
  494. }
  495. else if (currentMode == "Measurement")
  496. {
  497. RightPanelButton.Visibility = Visibility.Visible;
  498. GetPDFViewControl().PDFViewTool.GetDefaultSettingParam().IsOpenMeasure = false;
  499. measureControl.ClearAllToolState();
  500. measureControl.ClearViewerControl();
  501. measureControl.UnloadEvent();
  502. }
  503. if (item.Tag as string == "Viewer")
  504. {
  505. regularViewerControl.PdfViewControl = viewControl;
  506. regularViewerControl.InitWithPDFViewer(viewControl);
  507. if (regularViewerControl.PdfViewControl != null)
  508. {
  509. PDFGrid.Child = regularViewerControl;
  510. viewControl.SetToolType(ToolType.Viewer);
  511. regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  512. regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  513. regularViewerControl.SetBOTAContainer(botaBarControl);
  514. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  515. }
  516. }
  517. else if (item.Tag as string == "Annotation")
  518. {
  519. annotationControl.SetToolBarContainerVisibility(Visibility.Visible);
  520. PDFGrid.Child = annotationControl;
  521. viewControl.SetToolType(ToolType.Pan);
  522. annotationControl.PDFViewControl = viewControl;
  523. annotationControl.InitWithPDFViewer(viewControl);
  524. if (annotationControl.PDFViewControl != null)
  525. {
  526. annotationControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  527. annotationControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  528. annotationControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  529. annotationControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  530. annotationControl.InitialPDFViewControl(annotationControl.PDFViewControl);
  531. annotationControl.SetBOTAContainer(botaBarControl);
  532. annotationControl.SetDisplaySettingsControl(displaySettingsControl);
  533. }
  534. }
  535. else if (item.Tag as string == "Form")
  536. {
  537. formControl.SetToolBarContainerVisibility(Visibility.Visible);
  538. formControl.PdfViewControl = viewControl;
  539. formControl.InitWithPDFViewer(viewControl);
  540. if (formControl.PdfViewControl != null)
  541. {
  542. PDFGrid.Child = formControl;
  543. viewControl.SetToolType(ToolType.WidgetEdit);
  544. formControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  545. formControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  546. formControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  547. formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  548. formControl.SetBOTAContainer(botaBarControl);
  549. formControl.InitialPDFViewControl(formControl.PdfViewControl);
  550. formControl.SetDisplaySettingsControl(displaySettingsControl);
  551. viewControl.GetCPDFViewer().SetFormFieldHighlight(true);
  552. }
  553. }
  554. else if (item.Tag as string == "Content Editor")
  555. {
  556. contentEditControl.PdfViewControl = viewControl;
  557. contentEditControl.InitWithPDFViewer(viewControl);
  558. displaySettingsControl.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  559. if (contentEditControl.pdfContentEditControl != null && contentEditControl.PdfViewControl != null)
  560. {
  561. PDFGrid.Child = contentEditControl;
  562. viewControl.SetToolType(ToolType.ContentEdit);
  563. contentEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  564. contentEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  565. contentEditControl.SetBOTAContainer(botaBarControl);
  566. contentEditControl.SetDisplaySettingsControl(displaySettingsControl);
  567. contentEditControl.PdfViewControl.SetSplitViewMode(CPDFViewModeUI.SplitMode.None);
  568. }
  569. }
  570. else if (item.Tag as string == "Document Editor")
  571. {
  572. pageEditControl.PDFViewControl = viewControl;
  573. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit;
  574. pageEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  575. pageEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  576. PDFGrid.Child = pageEditControl;
  577. NotDocsEditorVisible = Visibility.Collapsed;
  578. }
  579. else if (item.Tag as string == "Digital Signature")
  580. {
  581. if (digitalSignatureControl.PDFViewControl != null)
  582. {
  583. RightPanelButton.Visibility = Visibility.Collapsed;
  584. PDFGrid.Child = digitalSignatureControl;
  585. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  586. digitalSignatureControl.PDFViewControl = viewControl;
  587. botaBarControl.AddBOTAContent(BOTATools.Signature);
  588. digitalSignatureControl.InitWithPDFViewer(viewControl);
  589. digitalSignatureControl.SetBOTAContainer(botaBarControl);
  590. digitalSignatureControl.SetDisplaySettingsControl(displaySettingsControl);
  591. digitalSignatureControl.SetSignatureStatusBarControl(signatureStatusBarControl);
  592. signatureStatusBarControl.OnViewSignatureButtonClicked -= ViewAllSignatures;
  593. signatureStatusBarControl.OnViewSignatureButtonClicked += ViewAllSignatures;
  594. digitalSignatureControl.OnCanSaveChanged -= DigitalSignatureControl_OnCanSaveChanged;
  595. digitalSignatureControl.OnCanSaveChanged += DigitalSignatureControl_OnCanSaveChanged;
  596. digitalSignatureControl.SignatureStatusChanged -= DigitalSignatureControl_OnSignatureStatusChanged;
  597. digitalSignatureControl.SignatureStatusChanged += DigitalSignatureControl_OnSignatureStatusChanged;
  598. digitalSignatureControl.AfterFillSignature -= DigitalSignatureControl_AfterFillSignature;
  599. digitalSignatureControl.AfterFillSignature += DigitalSignatureControl_AfterFillSignature;
  600. }
  601. }
  602. else if (item.Tag as string == "Measurement")
  603. {
  604. if (contentEditControl.pdfContentEditControl != null && viewControl != null)
  605. {
  606. RightPanelButton.Visibility = Visibility.Visible;
  607. PDFGrid.Child = measureControl;
  608. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  609. viewControl.SetToolType(ToolType.Pan);
  610. measureControl.InitWithPDFViewer(viewControl);
  611. measureControl.SetBOTAContainer(botaBarControl);
  612. measureControl.ClearAllToolState();
  613. measureControl.SetSettingsControl(displaySettingsControl);
  614. GetPDFViewControl().PDFViewTool.GetDefaultSettingParam().IsOpenMeasure = true;
  615. measureControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  616. measureControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  617. }
  618. }
  619. currentMode = item.Tag as string;
  620. RightToolPanelButtonIsChecked = false;
  621. SnapshotButton.IsChecked = false;
  622. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  623. }
  624. /// <summary>
  625. /// Event handler for ViewSignatureBtn click event. Expand the bota control and select the Signature tool.
  626. /// </summary>
  627. /// <param name="sender"></param>
  628. /// <param name="e"></param>
  629. private void ViewAllSignatures(object sender, EventArgs e)
  630. {
  631. LeftToolPanelButton.IsChecked = true;
  632. botaBarControl.SelectBotaTool(BOTATools.Signature);
  633. }
  634. private void PageEditControl_ExitPageEdit(object sender, EventArgs e)
  635. {
  636. ModeComboBox.SelectedIndex = 0;
  637. }
  638. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  639. {
  640. PasswordUI.Visibility = Visibility.Collapsed;
  641. FileInfoUI.Visibility = Visibility.Visible;
  642. FileInfoControl.InitWithPDFViewer(viewControl);
  643. PopupBorder.Visibility = Visibility.Visible;
  644. }
  645. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  646. {
  647. panelState.RightPanel =
  648. ((sender as ToggleButton).IsChecked == true) ?
  649. PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  650. }
  651. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  652. {
  653. panelState.RightPanel =
  654. ((sender as ToggleButton).IsChecked == true) ?
  655. PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  656. }
  657. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  658. {
  659. LeftToolPanelButton.IsChecked = true;
  660. botaBarControl.SelectBotaTool(BOTATools.Search);
  661. }
  662. private void CPDFTitleBarControl_Loaded(object sender, RoutedEventArgs e)
  663. {
  664. CPDFTitleBarControl.OpenFileEvent -= CPDFTitleBarControl_OpenFileEvent;
  665. CPDFTitleBarControl.OpenFileEvent += CPDFTitleBarControl_OpenFileEvent;
  666. CPDFTitleBarControl.SaveAsFileEvent -= CPDFTitleBarControl_SaveAsFileEvent;
  667. CPDFTitleBarControl.SaveAsFileEvent += CPDFTitleBarControl_SaveAsFileEvent;
  668. CPDFTitleBarControl.SaveFileEvent -= CPDFTitleBarControl_SaveFileEvent;
  669. CPDFTitleBarControl.SaveFileEvent += CPDFTitleBarControl_SaveFileEvent;
  670. CPDFTitleBarControl.FlattenEvent -= CPDFTitleBarControl_FlattenEvent;
  671. CPDFTitleBarControl.FlattenEvent += CPDFTitleBarControl_FlattenEvent;
  672. CPDFTitleBarControl.PrintEvent -= CPDFTitleBarControl_PrintEvent;
  673. CPDFTitleBarControl.PrintEvent += CPDFTitleBarControl_PrintEvent;
  674. }
  675. private void CPDFTitleBarControl_PrintEvent(object sender, EventArgs e)
  676. {
  677. PrinterDialog printerDialog = new PrinterDialog();
  678. printerDialog.Document = viewControl.GetCPDFViewer().GetDocument();
  679. printerDialog.ShowDialog();
  680. }
  681. private void CPDFTitleBarControl_FlattenEvent(object sender, EventArgs e)
  682. {
  683. if (viewControl != null && viewControl.GetCPDFViewer() != null && viewControl.GetCPDFViewer().GetDocument() != null)
  684. {
  685. string savePath = ComPDFKit.Controls.Helper.CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", viewControl.GetCPDFViewer().GetDocument().FileName + "_Flattened.pdf");
  686. if (!string.IsNullOrEmpty(savePath))
  687. {
  688. if (CanSave)
  689. {
  690. SaveFile();
  691. viewControl.PDFViewTool.IsDocumentModified = false;
  692. }
  693. CPDFDocument document = CPDFDocument.InitWithFilePath(viewControl.GetCPDFViewer().GetDocument().FilePath);
  694. if (document?.WriteFlattenToFilePath(savePath) == true)
  695. {
  696. System.Diagnostics.Process.Start("Explorer.exe", "/select," + savePath);
  697. }
  698. document?.Release();
  699. }
  700. }
  701. }
  702. private void CPDFTitleBarControl_SaveFileEvent(object sender, EventArgs e)
  703. {
  704. SaveFile();
  705. }
  706. private void CPDFTitleBarControl_SaveAsFileEvent(object sender, EventArgs e)
  707. {
  708. SaveAsFile();
  709. }
  710. private void CPDFTitleBarControl_OpenFileEvent(object sender, EventArgs e)
  711. {
  712. OpenFile();
  713. }
  714. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  715. {
  716. PopupBorder.Visibility = Visibility.Collapsed;
  717. }
  718. /// <summary>
  719. /// Refresh the annotation list when a annotation is edited.
  720. /// </summary>
  721. /// <param name="sender"></param>
  722. /// <param name="e"></param>
  723. private void PdfFormControlRefreshAnnotList(object sender, EventArgs e)
  724. {
  725. botaBarControl.LoadAnnotationList();
  726. }
  727. /// <summary>
  728. /// When a CanSave property of a control is changed, the CanSave property of current page is changed.
  729. /// </summary>
  730. /// <param name="sender"></param>
  731. /// <param name="e"></param>
  732. private void ControlOnCanSaveChanged(object sender, bool e)
  733. {
  734. this.CanSave = e;
  735. }
  736. private void PDFViewTool_DocumentModifiedChanged(object sender, EventArgs e)
  737. {
  738. CanSave = viewControl.PDFViewTool.IsDocumentModified;
  739. }
  740. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  741. {
  742. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  743. }
  744. private void SnapShotButton_Click(object sender, RoutedEventArgs e)
  745. {
  746. if((sender as ToggleButton).IsChecked == true)
  747. {
  748. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  749. SnapshotMenu snapMenu = new SnapshotMenu();
  750. snapshotArgs.ControlPointColor = Colors.White;
  751. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  752. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  753. snapshotArgs.ToolPanel = snapMenu;
  754. snapshotArgs.Viewer = viewControl;
  755. snapMenu.SnapToolArgs = snapshotArgs;
  756. snapMenu.PdfViewer = viewControl;
  757. snapMenu.SnapToolEvent += SnapMenu_SnapToolEvent;
  758. viewControl.PDFToolManager.SetToolType(ToolType.SelectedPage);
  759. viewControl.FocusPDFViewTool.SetPageSelectdUserControl(snapshotArgs.ToolPanel);
  760. }
  761. else
  762. {
  763. if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Viewer")
  764. {
  765. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  766. }
  767. else if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Annotation")
  768. {
  769. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  770. }
  771. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  772. }
  773. }
  774. private void SnapMenu_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  775. {
  776. switch (e.Key)
  777. {
  778. case "CloseSnap":
  779. {
  780. if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Viewer")
  781. {
  782. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  783. }
  784. else if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Annotation")
  785. {
  786. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  787. }
  788. SnapshotButton.IsChecked = false;
  789. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  790. }
  791. break;
  792. case "Save":
  793. CanSave = true;
  794. break;
  795. default:
  796. break;
  797. }
  798. }
  799. #endregion
  800. #region Open and Save file
  801. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  802. {
  803. SaveFile();
  804. CanSave = false;
  805. }
  806. private void OpenFile(string filePath = "")
  807. {
  808. if (viewControl != null && viewControl.PDFViewTool != null)
  809. {
  810. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  811. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  812. if (pdfDoc == null)
  813. {
  814. return;
  815. }
  816. if (string.IsNullOrEmpty(filePath))
  817. {
  818. filePath = ComPDFKit.Controls.Helper.CommonHelper.GetExistedPathOrEmpty();
  819. }
  820. string oldFilePath = pdfDoc.FilePath;
  821. if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)
  822. {
  823. if (oldFilePath.ToLower() == filePath.ToLower())
  824. {
  825. return;
  826. }
  827. if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
  828. {
  829. return;
  830. }
  831. if (CanSave)
  832. {
  833. string fileName = pdfDoc.FileName;
  834. var message = fileName + " " + LanguageHelper.CommonManager.GetString("Warn_NotSave");
  835. var result = MessageBox.Show(message, LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
  836. if (result == MessageBoxResult.Yes)
  837. {
  838. SaveFile();
  839. }
  840. else if (result == MessageBoxResult.Cancel)
  841. {
  842. return;
  843. }
  844. }
  845. passwordViewer = new PDFViewControl();
  846. passwordViewer.InitDocument(filePath);
  847. CPDFViewer tempViewer = passwordViewer.PDFViewTool?.GetCPDFViewer();
  848. CPDFDocument tempDoc = tempViewer?.GetDocument();
  849. if (tempDoc == null)
  850. {
  851. MessageBox.Show("Open File Failed");
  852. return;
  853. }
  854. if (passwordViewer.GetCPDFViewer().GetDocument().IsLocked)
  855. {
  856. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " " + LanguageHelper.CommonManager.GetString("Tip_Encrypted"));
  857. PasswordUI.ClearPassword();
  858. PopupBorder.Visibility = Visibility.Visible;
  859. PasswordUI.Visibility = Visibility.Visible;
  860. }
  861. else
  862. {
  863. pdfDoc.Release();
  864. viewControl = passwordViewer;
  865. LoadDocument();
  866. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  867. }
  868. }
  869. }
  870. }
  871. private void OpenFile_Click(object sender, RoutedEventArgs e)
  872. {
  873. OpenFile();
  874. }
  875. /// <summary>
  876. /// Save the file to another PDF file.
  877. /// </summary>
  878. public void SaveAsFile()
  879. {
  880. if (viewControl != null && viewControl.PDFViewTool != null)
  881. {
  882. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  883. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  884. if (pdfDoc == null)
  885. {
  886. return;
  887. }
  888. SaveFileDialog saveDialog = new SaveFileDialog();
  889. saveDialog.Filter = "(*.pdf)|*.pdf";
  890. saveDialog.DefaultExt = ".pdf";
  891. saveDialog.OverwritePrompt = true;
  892. if (saveDialog.ShowDialog() == true)
  893. {
  894. pdfDoc.WriteToFilePath(saveDialog.FileName);
  895. }
  896. }
  897. }
  898. /// <summary>
  899. /// Save the file in the current path.
  900. /// </summary>
  901. public void SaveFile()
  902. {
  903. if (viewControl != null && viewControl.PDFViewTool != null)
  904. {
  905. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  906. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  907. if (pdfDoc == null)
  908. {
  909. return;
  910. }
  911. try
  912. {
  913. if (!string.IsNullOrEmpty(pdfDoc.FilePath))
  914. {
  915. if (pdfDoc.WriteToLoadedPath())
  916. {
  917. return;
  918. }
  919. }
  920. SaveFileDialog saveDialog = new SaveFileDialog
  921. {
  922. Filter = "(*.pdf)|*.pdf",
  923. DefaultExt = ".pdf",
  924. OverwritePrompt = true
  925. };
  926. if (saveDialog.ShowDialog() == true)
  927. {
  928. if (pdfDoc.WriteToFilePath(saveDialog.FileName))
  929. {
  930. AfterSaveAsFileEvent?.Invoke(this, saveDialog.FileName);
  931. }
  932. }
  933. }
  934. catch (Exception ex)
  935. {
  936. return;
  937. }
  938. }
  939. }
  940. public void CloseFile()
  941. {
  942. if (viewControl != null && viewControl.PDFViewTool != null)
  943. {
  944. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  945. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  946. if(pdfDoc !=null)
  947. {
  948. pdfDoc.Release();
  949. }
  950. }
  951. }
  952. #endregion
  953. #region Command Binding
  954. private double CheckZoomLevel(double zoom, bool IsGrowth)
  955. {
  956. double standardZoom = 100;
  957. if (zoom <= 0.01)
  958. {
  959. return 0.01;
  960. }
  961. if (zoom >= 10)
  962. {
  963. return 10;
  964. }
  965. zoom *= 100;
  966. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  967. {
  968. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  969. {
  970. standardZoom = zoomLevelList[i + 1];
  971. break;
  972. }
  973. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  974. {
  975. standardZoom = zoomLevelList[i];
  976. break;
  977. }
  978. }
  979. return standardZoom / 100;
  980. }
  981. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  982. {
  983. OpenFile();
  984. }
  985. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  986. {
  987. if (CanSave)
  988. {
  989. SaveFile();
  990. }
  991. }
  992. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  993. {
  994. SaveAsFile();
  995. }
  996. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  997. {
  998. panelState.IsLeftPanelExpand = !panelState.IsLeftPanelExpand;
  999. }
  1000. private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
  1001. {
  1002. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  1003. {
  1004. panelState.RightPanel = PanelState.RightPanelState.None;
  1005. }
  1006. else
  1007. {
  1008. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  1009. }
  1010. }
  1011. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  1012. {
  1013. LeftToolPanelButton.IsChecked = true;
  1014. botaBarControl.SelectBotaTool(BOTATools.Bookmark);
  1015. }
  1016. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  1017. {
  1018. LeftToolPanelButton.IsChecked = true;
  1019. botaBarControl.SelectBotaTool(BOTATools.Outline);
  1020. }
  1021. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  1022. {
  1023. LeftToolPanelButton.IsChecked = true;
  1024. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  1025. }
  1026. private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
  1027. {
  1028. LeftToolPanelButton.IsChecked = true;
  1029. botaBarControl.SelectBotaTool(BOTATools.Annotation);
  1030. }
  1031. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  1032. {
  1033. LeftToolPanelButton.IsChecked = true;
  1034. botaBarControl.SelectBotaTool(BOTATools.Search);
  1035. }
  1036. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  1037. {
  1038. if (viewControl != null && viewControl.PDFViewTool != null)
  1039. {
  1040. CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
  1041. if (pdfViewer != null)
  1042. {
  1043. double newZoom = CheckZoomLevel(pdfViewer.GetZoom() + 0.01, true);
  1044. pdfViewer.SetZoom(newZoom);
  1045. }
  1046. }
  1047. }
  1048. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  1049. {
  1050. if (viewControl != null && viewControl.PDFViewTool != null)
  1051. {
  1052. CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
  1053. if (pdfViewer != null)
  1054. {
  1055. double newZoom = CheckZoomLevel(pdfViewer.GetZoom() - 0.01, false);
  1056. pdfViewer.SetZoom(newZoom);
  1057. }
  1058. }
  1059. }
  1060. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  1061. {
  1062. panelState.RightPanel = PanelState.RightPanelState.ViewSettings;
  1063. }
  1064. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  1065. {
  1066. if (PopupBorder.Visibility != Visibility.Visible)
  1067. {
  1068. PasswordUI.Visibility = Visibility.Collapsed;
  1069. FileInfoControl.Visibility = Visibility.Visible;
  1070. FileInfoControl.InitWithPDFViewer(viewControl);
  1071. FileInfoControl.CloseInfoEvent -= CPDFInfoControl_CloseInfoEvent;
  1072. FileInfoControl.CloseInfoEvent += CPDFInfoControl_CloseInfoEvent;
  1073. PopupBorder.Visibility = Visibility.Visible;
  1074. }
  1075. else
  1076. {
  1077. FileInfoControl.Visibility = Visibility.Collapsed;
  1078. PopupBorder.Visibility = Visibility.Collapsed;
  1079. this.Focus();
  1080. }
  1081. }
  1082. private void CPDFInfoControl_CloseInfoEvent(object sender, EventArgs e)
  1083. {
  1084. PopupBorder.Visibility = Visibility.Collapsed;
  1085. }
  1086. #endregion
  1087. }
  1088. }