MainWindow.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using compdfkit_tools.Form;
  2. using compdfkit_tools.Helper;
  3. using compdfkit_tools.PDFControl;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. using System.Diagnostics;
  21. using System.IO;
  22. using System.Drawing;
  23. using System.ComponentModel;
  24. using System.Runtime.CompilerServices;
  25. using ComPDFKit.PDFDocument;
  26. using Microsoft.Win32;
  27. using System.Windows.Controls.Primitives;
  28. using ComPDFKit.PDFPage;
  29. using ComPDFKitViewer.PdfViewer;
  30. namespace pageedit_ctrl_demo
  31. {
  32. /// <summary>
  33. /// MainWindow.xaml 的交互逻辑
  34. /// </summary>
  35. public partial class MainWindow : Window, INotifyPropertyChanged
  36. {
  37. private bool isFirstLoad = true;
  38. private string currentMode = "Page Edit";
  39. private PDFViewControl passwordViewer;
  40. private PDFViewControl pdfViewControl;
  41. private CPDFAnnotationControl pdfAnnotationControl = null;
  42. private CPDFSearchControl searchControl = null;
  43. private CPDFPageEditControl pageEditControl = null;
  44. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  45. public bool CanSave
  46. {
  47. get
  48. {
  49. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  50. {
  51. return pdfViewControl.PDFView.UndoManager.CanSave;
  52. }
  53. return false;
  54. }
  55. }
  56. public event PropertyChangedEventHandler PropertyChanged;
  57. protected void OnPropertyChanged([CallerMemberName] string name = null)
  58. {
  59. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  60. }
  61. public MainWindow()
  62. {
  63. InitializeComponent();
  64. Loaded += MainWindow_Loaded;
  65. DataContext = this;
  66. }
  67. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  68. {
  69. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search);
  70. pdfAnnotationControl = new CPDFAnnotationControl();
  71. LoadDefaultDocument();
  72. }
  73. private void LoadDefaultDocument()
  74. {
  75. string defaultFilePath = "developer_guide_windows.pdf";
  76. LeftToolPanelButton.IsEnabled = false;
  77. SearchButton.IsEnabled = false;
  78. RightToolPanelButton.IsEnabled = false;
  79. ViewSettingBtn.IsEnabled = false;
  80. pdfViewControl = new PDFViewControl();
  81. pdfViewControl.PDFView.InitDocument(defaultFilePath);
  82. LoadDocument();
  83. }
  84. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  85. {
  86. if (e.Key == "Zoom")
  87. {
  88. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  89. }
  90. }
  91. private double CheckZoomLevel(double zoom, bool IsGrowth)
  92. {
  93. double standardZoom = 100;
  94. if (zoom <= 0.01)
  95. {
  96. return 0.01;
  97. }
  98. if (zoom >= 10)
  99. {
  100. return 10;
  101. }
  102. zoom *= 100;
  103. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  104. {
  105. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  106. {
  107. standardZoom = zoomLevelList[i + 1];
  108. break;
  109. }
  110. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  111. {
  112. standardZoom = zoomLevelList[i];
  113. break;
  114. }
  115. }
  116. return standardZoom / 100;
  117. }
  118. private void CopyImage_Click(object sender, RoutedEventArgs e)
  119. {
  120. try
  121. {
  122. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  123. if (imageDict != null && imageDict.Count > 0)
  124. {
  125. foreach (int pageIndex in imageDict.Keys)
  126. {
  127. List<Bitmap> imageList = imageDict[pageIndex];
  128. foreach (Bitmap image in imageList)
  129. {
  130. MemoryStream ms = new MemoryStream();
  131. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  132. BitmapImage imageData = new BitmapImage();
  133. imageData.BeginInit();
  134. imageData.StreamSource = ms;
  135. imageData.CacheOption = BitmapCacheOption.OnLoad;
  136. imageData.EndInit();
  137. imageData.Freeze();
  138. Clipboard.SetImage(imageData);
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. catch (Exception ex)
  145. {
  146. }
  147. }
  148. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  149. {
  150. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  151. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  152. {
  153. string choosePath = folderDialog.SelectedPath;
  154. string openPath = choosePath;
  155. try
  156. {
  157. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  158. if (imageDict != null && imageDict.Count > 0)
  159. {
  160. foreach (int pageIndex in imageDict.Keys)
  161. {
  162. List<Bitmap> imageList = imageDict[pageIndex];
  163. foreach (Bitmap image in imageList)
  164. {
  165. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  166. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  167. openPath = savePath;
  168. }
  169. }
  170. }
  171. Process.Start("explorer", "/select,\"" + openPath + "\"");
  172. }
  173. catch (Exception ex)
  174. {
  175. }
  176. }
  177. }
  178. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  179. {
  180. if (e != null && e.CommandType == CommandType.Context)
  181. {
  182. if (e.PressOnSelectedText)
  183. {
  184. e.Handle = true;
  185. e.PopupMenu = new ContextMenu();
  186. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  187. }
  188. else if (e.CommandTarget == TargetType.ImageSelection)
  189. {
  190. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  191. {
  192. e.Handle = true;
  193. e.PopupMenu = new ContextMenu();
  194. MenuItem imageCopyMenu = new MenuItem();
  195. imageCopyMenu = new MenuItem();
  196. imageCopyMenu.Header = "Copy Images";
  197. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  198. imageCopyMenu.CommandParameter = e;
  199. e.PopupMenu.Items.Add(imageCopyMenu);
  200. MenuItem imageExtraMenu = new MenuItem();
  201. imageExtraMenu = new MenuItem();
  202. imageExtraMenu.Header = "Extract Images";
  203. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  204. imageExtraMenu.CommandParameter = e;
  205. e.PopupMenu.Items.Add(imageExtraMenu);
  206. }
  207. }
  208. else if (e.CommandTarget == TargetType.WidgetView)
  209. {
  210. e.Handle = true;
  211. e.PopupMenu = new ContextMenu();
  212. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  213. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  214. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  215. }
  216. else
  217. {
  218. e.Handle = true;
  219. e.PopupMenu = new ContextMenu();
  220. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  221. e.PopupMenu.Items.Add(new Separator());
  222. MenuItem fitWidthMenu = new MenuItem();
  223. fitWidthMenu.Header = "Automatically Resize";
  224. fitWidthMenu.Click += (o, p) =>
  225. {
  226. if (pdfViewControl != null)
  227. {
  228. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  229. }
  230. };
  231. e.PopupMenu.Items.Add(fitWidthMenu);
  232. MenuItem fitSizeMenu = new MenuItem();
  233. fitSizeMenu.Header = "Actual Size";
  234. fitSizeMenu.Click += (o, p) =>
  235. {
  236. if (pdfViewControl != null)
  237. {
  238. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  239. }
  240. };
  241. e.PopupMenu.Items.Add(fitSizeMenu);
  242. MenuItem zoomInMenu = new MenuItem();
  243. zoomInMenu.Header = "Zoom In";
  244. zoomInMenu.Click += (o, p) =>
  245. {
  246. if (pdfViewControl != null)
  247. {
  248. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  249. pdfViewControl.PDFView?.Zoom(newZoom);
  250. }
  251. };
  252. e.PopupMenu.Items.Add(zoomInMenu);
  253. MenuItem zoomOutMenu = new MenuItem();
  254. zoomOutMenu.Header = "Zoom Out";
  255. zoomOutMenu.Click += (o, p) =>
  256. {
  257. if (pdfViewControl != null)
  258. {
  259. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  260. pdfViewControl.PDFView?.Zoom(newZoom);
  261. }
  262. };
  263. e.PopupMenu.Items.Add(zoomOutMenu);
  264. e.PopupMenu.Items.Add(new Separator());
  265. MenuItem singleView = new MenuItem();
  266. singleView.Header = "Single Page";
  267. singleView.Click += (o, p) =>
  268. {
  269. if (pdfViewControl != null)
  270. {
  271. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  272. }
  273. };
  274. e.PopupMenu.Items.Add(singleView);
  275. MenuItem singleContinuousView = new MenuItem();
  276. singleContinuousView.Header = "Single Page Continuous";
  277. singleContinuousView.Click += (o, p) =>
  278. {
  279. if (pdfViewControl != null)
  280. {
  281. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  282. }
  283. };
  284. e.PopupMenu.Items.Add(singleContinuousView);
  285. MenuItem doubleView = new MenuItem();
  286. doubleView.Header = "Two Pages";
  287. doubleView.Click += (o, p) =>
  288. {
  289. if (pdfViewControl != null)
  290. {
  291. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  292. }
  293. };
  294. e.PopupMenu.Items.Add(doubleView);
  295. MenuItem doubleContinuousView = new MenuItem();
  296. doubleContinuousView.Header = "Two Pages Continuous";
  297. doubleContinuousView.Click += (o, p) =>
  298. {
  299. if (pdfViewControl != null)
  300. {
  301. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  302. }
  303. };
  304. e.PopupMenu.Items.Add(doubleContinuousView);
  305. }
  306. }
  307. else
  308. {
  309. e.DoCommand();
  310. }
  311. }
  312. private void PasswordUI_Canceled(object sender, EventArgs e)
  313. {
  314. PopupBorder.Visibility = Visibility.Collapsed;
  315. PasswordUI.Visibility = Visibility.Collapsed;
  316. }
  317. private void PasswordUI_Closed(object sender, EventArgs e)
  318. {
  319. PopupBorder.Visibility = Visibility.Collapsed;
  320. PasswordUI.Visibility = Visibility.Collapsed;
  321. }
  322. private void PasswordUI_Confirmed(object sender, string e)
  323. {
  324. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  325. {
  326. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  327. if (passwordViewer.PDFView.Document.IsLocked == false)
  328. {
  329. PasswordUI.SetShowError("", Visibility.Collapsed);
  330. PasswordUI.ClearPassword();
  331. PasswordUI.Visibility = Visibility.Collapsed;
  332. PopupBorder.Visibility = Visibility.Collapsed;
  333. pdfViewControl = passwordViewer;
  334. LoadDocument();
  335. }
  336. else
  337. {
  338. PasswordUI.SetShowError("error", Visibility.Visible);
  339. }
  340. }
  341. }
  342. private void LoadDocument()
  343. {
  344. pdfViewControl.PDFView?.Load();
  345. pdfViewControl.PDFView?.SetShowLink(true);
  346. if (ViewComboBox.SelectedIndex == 0)
  347. {
  348. PDFGrid.Child = pdfViewControl;
  349. }
  350. else
  351. {
  352. ToolBarContainer.Visibility = Visibility.Visible;
  353. if (pageEditControl == null)
  354. {
  355. pageEditControl = new CPDFPageEditControl();
  356. }
  357. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit;
  358. CPDFPageEditBarControl.PageEditEvent -= CPDFPageEditBarControl_PageEditEvent;
  359. CPDFPageEditBarControl.PageEditEvent += CPDFPageEditBarControl_PageEditEvent;
  360. pageEditControl.LoadThumbnails(pdfViewControl.PDFView);
  361. PDFGrid.Child = pageEditControl;
  362. FloatPageTool.Visibility = Visibility.Collapsed;
  363. }
  364. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  365. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  366. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  367. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  368. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  369. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  370. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  371. PasswordUI.Closed -= PasswordUI_Closed;
  372. PasswordUI.Canceled -= PasswordUI_Canceled;
  373. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  374. PasswordUI.Closed += PasswordUI_Closed;
  375. PasswordUI.Canceled += PasswordUI_Canceled;
  376. PasswordUI.Confirmed += PasswordUI_Confirmed;
  377. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  378. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  379. ViewSettingBtn.IsChecked = false;
  380. PropertyContainer.Child = null;
  381. PropertyContainer.Visibility = Visibility.Collapsed;
  382. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  383. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  384. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  385. }
  386. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  387. {
  388. OnPropertyChanged(e.PropertyName);
  389. }
  390. private void OpenFile_Click(object sender, RoutedEventArgs e)
  391. {
  392. try
  393. {
  394. string filePath = CommonHelper.GetFilePathOrEmpty();
  395. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  396. {
  397. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  398. {
  399. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  400. if (oldFilePath.ToLower() == filePath.ToLower())
  401. {
  402. return;
  403. }
  404. }
  405. passwordViewer = new PDFViewControl();
  406. passwordViewer.PDFView.InitDocument(filePath);
  407. if (passwordViewer.PDFView.Document == null)
  408. {
  409. MessageBox.Show("Open File Failed");
  410. return;
  411. }
  412. if (passwordViewer.PDFView.Document.IsLocked)
  413. {
  414. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  415. PasswordUI.ClearPassword();
  416. PopupBorder.Visibility = Visibility.Visible;
  417. PasswordUI.Visibility = Visibility.Visible;
  418. }
  419. else
  420. {
  421. pdfViewControl = passwordViewer;
  422. LoadDocument();
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. }
  429. }
  430. private void ExpandLeftPanel(bool isExpand)
  431. {
  432. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  433. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  434. if (isExpand)
  435. {
  436. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  437. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  438. }
  439. else
  440. {
  441. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  442. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  443. }
  444. }
  445. /// <summary>
  446. /// 展开Bota工具
  447. /// </summary>
  448. /// <param name="isExpand"></param>
  449. private void ExpandBotaTool(bool isExpand)
  450. {
  451. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  452. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  453. }
  454. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  455. {
  456. ToggleButton expandBtn = sender as ToggleButton;
  457. if (expandBtn != null)
  458. {
  459. bool isExpand = expandBtn.IsChecked == true;
  460. ExpandLeftPanel(isExpand);
  461. }
  462. }
  463. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  464. {
  465. SaveFile();
  466. pdfViewControl.PDFView.UndoManager.CanSave = false;
  467. }
  468. private void SaveFile()
  469. {
  470. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  471. {
  472. try
  473. {
  474. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  475. if (pdfDoc.WriteToLoadedPath())
  476. {
  477. return;
  478. }
  479. SaveFileDialog saveDialog = new SaveFileDialog();
  480. saveDialog.Filter = "(*.pdf)|*.pdf";
  481. saveDialog.DefaultExt = ".pdf";
  482. saveDialog.OverwritePrompt = true;
  483. if (saveDialog.ShowDialog() == true)
  484. {
  485. pdfDoc.WriteToFilePath(saveDialog.FileName);
  486. }
  487. }
  488. catch (Exception ex)
  489. {
  490. }
  491. }
  492. }
  493. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  494. {
  495. PopupBorder.Visibility = Visibility.Collapsed;
  496. }
  497. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  498. {
  499. ExpandLeftPanel(true);
  500. LeftToolPanelButton.IsChecked = true;
  501. BotaSideTool.SelectBotaTool(BOTATools.Search);
  502. }
  503. public void ExpandRightPropertyPanel(UIElement properytPanel, Visibility visible)
  504. {
  505. PropertyContainer.Width = 260;
  506. PropertyContainer.Child = properytPanel;
  507. PropertyContainer.Visibility = visible;
  508. if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
  509. {
  510. RightToolPanelButton.IsChecked = false;
  511. }
  512. }
  513. private void RightToolPanelButton_Click(object sender, RoutedEventArgs e)
  514. {
  515. ToggleButton toggleButton = sender as ToggleButton;
  516. if (toggleButton != null)
  517. {
  518. if (toggleButton.IsChecked == true)
  519. {
  520. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  521. if ((bool)ViewSettingBtn.IsChecked)
  522. {
  523. ViewSettingBtn.IsChecked = false;
  524. }
  525. }
  526. else
  527. {
  528. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  529. }
  530. }
  531. }
  532. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  533. {
  534. ToggleButton toggleButton = sender as ToggleButton;
  535. if (toggleButton != null)
  536. {
  537. if (toggleButton.IsChecked == true)
  538. {
  539. CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
  540. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  541. PropertyContainer.Child = displayPanel;
  542. PropertyContainer.Visibility = Visibility.Visible;
  543. if ((bool)RightToolPanelButton.IsChecked)
  544. {
  545. RightToolPanelButton.IsChecked = false;
  546. }
  547. }
  548. else
  549. {
  550. PropertyContainer.Child = null;
  551. PropertyContainer.Visibility = Visibility.Collapsed;
  552. }
  553. }
  554. }
  555. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  556. {
  557. PasswordUI.Visibility = Visibility.Collapsed;
  558. FileInfoUI.Visibility = Visibility.Visible;
  559. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  560. PopupBorder.Visibility = Visibility.Visible;
  561. }
  562. private void InitPageEditControl()
  563. {
  564. }
  565. private void ViewComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  566. {
  567. if (isFirstLoad)
  568. {
  569. isFirstLoad = false;
  570. return;
  571. }
  572. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  573. switch (currentMode)
  574. {
  575. case "Viewer":
  576. break;
  577. case "Page Edit":
  578. ToolBarContainer.Visibility = Visibility.Collapsed;
  579. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  580. CPDFPageEditBarControl.PageEditEvent -= CPDFPageEditBarControl_PageEditEvent;
  581. FloatPageTool.Visibility = Visibility.Visible;
  582. pdfViewControl.PDFView.ReloadDocument();
  583. LeftToolPanelButton.IsEnabled = true;
  584. SearchButton.IsEnabled = true;
  585. RightToolPanelButton.IsEnabled = true;
  586. ViewSettingBtn.IsEnabled = true;
  587. break;
  588. default:
  589. break;
  590. }
  591. if ((string)item.Content == "Viewer")
  592. {
  593. ToolBarContainer.Visibility = Visibility.Collapsed;
  594. PDFGrid.Child = pdfViewControl;
  595. }
  596. else if ((string)item.Content == "Page Edit")
  597. {
  598. ToolBarContainer.Visibility = Visibility.Visible;
  599. if(pageEditControl == null)
  600. {
  601. pageEditControl = new CPDFPageEditControl();
  602. }
  603. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit;
  604. CPDFPageEditBarControl.PageEditEvent += CPDFPageEditBarControl_PageEditEvent;
  605. pageEditControl.LoadThumbnails(pdfViewControl.PDFView);
  606. PDFGrid.Child = pageEditControl;
  607. LeftToolPanelButton.IsChecked = false;
  608. LeftToolPanelButton.IsEnabled = false;
  609. SearchButton.IsEnabled = false;
  610. RightToolPanelButton.IsChecked = false;
  611. RightToolPanelButton.IsEnabled = false;
  612. ViewSettingBtn.IsChecked = false;
  613. ViewSettingBtn.IsEnabled = false;
  614. ExpandLeftPanel(false);
  615. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  616. FloatPageTool.Visibility = Visibility.Collapsed;
  617. }
  618. currentMode = (string)item.Content;
  619. }
  620. private void CPDFPageEditBarControl_PageEditEvent(object sender, string e)
  621. {
  622. pageEditControl.PageEdit(e);
  623. }
  624. private void PageEditControl_ExitPageEdit(object sender, EventArgs e)
  625. {
  626. ViewComboBox.SelectedIndex = 0;
  627. }
  628. }
  629. }