MainPage.xaml.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using compdfkit_tools.Data;
  4. using compdfkit_tools.Edit;
  5. using compdfkit_tools.Helper;
  6. using compdfkit_tools.PDFControl;
  7. using ComPDFKitViewer;
  8. using ComPDFKitViewer.PdfViewer;
  9. using Microsoft.Win32;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Runtime.CompilerServices;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Controls.Primitives;
  23. using System.Windows.Data;
  24. using System.Windows.Documents;
  25. using System.Windows.Input;
  26. using System.Windows.Media;
  27. using System.Windows.Media.Imaging;
  28. using System.Windows.Navigation;
  29. using Path = System.IO.Path;
  30. namespace compdfkit
  31. {
  32. /// <summary>
  33. /// MainPage.xaml 的交互逻辑
  34. /// </summary>
  35. public partial class MainPage : UserControl, INotifyPropertyChanged
  36. {
  37. private bool isFirstLoad = true;
  38. private string currentMode = "Viewer";
  39. private PDFViewControl passwordViewer;
  40. private PDFViewControl pdfViewControl = new PDFViewControl();
  41. private CPDFAnnotationControl pdfAnnotationControl = null;
  42. private UIElement pdfEditControl = 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. /// <summary>
  78. /// The last edit object
  79. /// </summary>
  80. private PDFEditEvent lastPDFEditEvent = null;
  81. public event Func<string, bool> CheckExistBeforeOpenFileEvent;
  82. public event PropertyChangedEventHandler PropertyChanged;
  83. public MainPage()
  84. {
  85. InitializeComponent();
  86. DataContext = this;
  87. }
  88. public void InitWithFilePath(string filePath)
  89. {
  90. pdfViewControl = new PDFViewControl();
  91. pdfViewControl.PDFView.InitDocument(filePath);
  92. }
  93. private void LoadDocument()
  94. {
  95. pdfViewControl.PDFView?.Load();
  96. pdfViewControl.PDFView?.SetShowLink(true);
  97. PDFGrid.Child = pdfViewControl;
  98. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  99. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  100. pdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  101. pdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  102. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  103. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  104. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  105. pdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  106. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  107. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  108. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  109. PasswordUI.Closed -= PasswordUI_Closed;
  110. PasswordUI.Canceled -= PasswordUI_Canceled;
  111. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  112. PasswordUI.Confirmed += PasswordUI_Confirmed;
  113. PasswordUI.Canceled += PasswordUI_Canceled;
  114. PasswordUI.Closed += PasswordUI_Closed;
  115. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  116. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  117. InitialPDFViewControl(pdfViewControl);
  118. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  119. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  120. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  121. ViewSettingBtn.IsChecked = false;
  122. PropertyContainer.Child = null;
  123. PropertyContainer.Visibility = Visibility.Collapsed;
  124. }
  125. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  126. {
  127. pdfAnnotationControl.SetPDFViewer(newPDFViewer.PDFView);
  128. pdfAnnotationControl.AnnotationCancel();
  129. AnnotationBarControl.ClearAllToolState();
  130. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  131. pdfAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  132. }
  133. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  134. {
  135. AnnotationBarControl.ClearAllToolState();
  136. }
  137. #region Load Document
  138. /// <summary>
  139. /// InfoChanged
  140. /// When the PDF zoom ratio changes, the value of the zoom control also changes.
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  145. {
  146. if (e.Key == "Zoom")
  147. {
  148. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  149. }
  150. }
  151. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  152. {
  153. if (e == null)
  154. {
  155. return;
  156. }
  157. if (e.EditType == CPDFEditType.EditText)
  158. {
  159. e.Handle = true;
  160. PDFEditTextContextMenu(sender, e);
  161. }
  162. if (e.EditType == CPDFEditType.EditImage)
  163. {
  164. e.Handle = true;
  165. PDFEditImageContextMenu(sender, e);
  166. }
  167. }
  168. private void PDFView_AnnotCommandHandler(object sender, ComPDFKitViewer.AnnotEvent.AnnotCommandArgs e)
  169. {
  170. switch (e.CommandType)
  171. {
  172. case CommandType.Context:
  173. e.Handle = true;
  174. if (e.CommandTarget == TargetType.Annot)
  175. {
  176. e.Handle = true;
  177. e.PopupMenu = new ContextMenu();
  178. if (e.PressOnLink)
  179. {
  180. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  181. MenuItem propertyMenu = new MenuItem();
  182. propertyMenu = new MenuItem();
  183. propertyMenu.Header = "Edit";
  184. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
  185. propertyMenu.CommandParameter = e;
  186. e.PopupMenu.Items.Add(propertyMenu);
  187. }
  188. else if (e.PressOnAnnot)
  189. {
  190. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  191. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  192. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  193. }
  194. else if (e.PressOnMedia || e.PressOnSound)
  195. {
  196. e.Handle = true;
  197. e.PopupMenu.Items.Add(new MenuItem() { Header = "Play", Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = e });
  198. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  199. }
  200. else if (e.PressOnSelectedText)
  201. {
  202. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  203. }
  204. else
  205. {
  206. e.Handle = true;
  207. e.PopupMenu = new ContextMenu();
  208. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  209. e.PopupMenu.Items.Add(new Separator());
  210. MenuItem fitWidthMenu = new MenuItem();
  211. fitWidthMenu.Header = "Automatically Resize";
  212. fitWidthMenu.Click += (o, p) =>
  213. {
  214. if (pdfViewControl != null)
  215. {
  216. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  217. }
  218. };
  219. e.PopupMenu.Items.Add(fitWidthMenu);
  220. MenuItem fitSizeMenu = new MenuItem();
  221. fitSizeMenu.Header = "Actual Size";
  222. fitSizeMenu.Click += (o, p) =>
  223. {
  224. if (pdfViewControl != null)
  225. {
  226. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  227. }
  228. };
  229. e.PopupMenu.Items.Add(fitSizeMenu);
  230. MenuItem zoomInMenu = new MenuItem();
  231. zoomInMenu.Header = "Zoom In";
  232. zoomInMenu.Click += (o, p) =>
  233. {
  234. if (pdfViewControl != null)
  235. {
  236. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  237. pdfViewControl.PDFView?.Zoom(newZoom);
  238. }
  239. };
  240. e.PopupMenu.Items.Add(zoomInMenu);
  241. MenuItem zoomOutMenu = new MenuItem();
  242. zoomOutMenu.Header = "Zoom Out";
  243. zoomOutMenu.Click += (o, p) =>
  244. {
  245. if (pdfViewControl != null)
  246. {
  247. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  248. pdfViewControl.PDFView?.Zoom(newZoom);
  249. }
  250. };
  251. e.PopupMenu.Items.Add(zoomOutMenu);
  252. e.PopupMenu.Items.Add(new Separator());
  253. MenuItem singleView = new MenuItem();
  254. singleView.Header = "Single Page";
  255. singleView.Click += (o, p) =>
  256. {
  257. if (pdfViewControl != null)
  258. {
  259. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  260. }
  261. };
  262. e.PopupMenu.Items.Add(singleView);
  263. MenuItem singleContinuousView = new MenuItem();
  264. singleContinuousView.Header = "Single Page Continuous";
  265. singleContinuousView.Click += (o, p) =>
  266. {
  267. if (pdfViewControl != null)
  268. {
  269. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  270. }
  271. };
  272. e.PopupMenu.Items.Add(singleContinuousView);
  273. MenuItem doubleView = new MenuItem();
  274. doubleView.Header = "Two Pages";
  275. doubleView.Click += (o, p) =>
  276. {
  277. if (pdfViewControl != null)
  278. {
  279. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  280. }
  281. };
  282. e.PopupMenu.Items.Add(doubleView);
  283. MenuItem doubleContinuousView = new MenuItem();
  284. doubleContinuousView.Header = "Two Pages Continuous";
  285. doubleContinuousView.Click += (o, p) =>
  286. {
  287. if (pdfViewControl != null)
  288. {
  289. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  290. }
  291. };
  292. e.PopupMenu.Items.Add(doubleContinuousView);
  293. }
  294. }
  295. else if (e.CommandTarget == TargetType.ImageSelection)
  296. {
  297. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  298. {
  299. e.Handle = true;
  300. e.PopupMenu = new ContextMenu();
  301. MenuItem imageCopyMenu = new MenuItem();
  302. imageCopyMenu = new MenuItem();
  303. imageCopyMenu.Header = "Copy Images";
  304. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  305. imageCopyMenu.CommandParameter = e;
  306. e.PopupMenu.Items.Add(imageCopyMenu);
  307. MenuItem imageExtraMenu = new MenuItem();
  308. imageExtraMenu = new MenuItem();
  309. imageExtraMenu.Header = "Extract Images";
  310. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  311. imageExtraMenu.CommandParameter = e;
  312. e.PopupMenu.Items.Add(imageExtraMenu);
  313. }
  314. }
  315. break;
  316. case CommandType.Copy:
  317. e.DoCommand();
  318. break;
  319. case CommandType.Cut:
  320. case CommandType.Paste:
  321. case CommandType.Delete:
  322. e.DoCommand();
  323. break;
  324. default:
  325. break;
  326. }
  327. }
  328. private void EditLink_Click(object sender, RoutedEventArgs e)
  329. {
  330. PropertyContainer.Visibility = Visibility.Visible;
  331. }
  332. private double CheckZoomLevel(double zoom, bool IsGrowth)
  333. {
  334. double standardZoom = 100;
  335. if (zoom <= 0.01)
  336. {
  337. return 0.01;
  338. }
  339. if (zoom >= 10)
  340. {
  341. return 10;
  342. }
  343. zoom *= 100;
  344. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  345. {
  346. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  347. {
  348. standardZoom = zoomLevelList[i + 1];
  349. break;
  350. }
  351. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  352. {
  353. standardZoom = zoomLevelList[i];
  354. break;
  355. }
  356. }
  357. return standardZoom / 100;
  358. }
  359. private void PDFView_AnnotEditHandler(object sender, List<ComPDFKitViewer.AnnotEvent.AnnotEditEvent> e)
  360. {
  361. BotaSideTool.LoadAnnotationList();
  362. }
  363. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  364. {
  365. OnPropertyChanged(e.PropertyName);
  366. }
  367. private void PasswordUI_Closed(object sender, EventArgs e)
  368. {
  369. PopupBorder.Visibility = Visibility.Collapsed;
  370. PasswordUI.Visibility = Visibility.Collapsed;
  371. }
  372. private void PasswordUI_Canceled(object sender, EventArgs e)
  373. {
  374. PopupBorder.Visibility = Visibility.Collapsed;
  375. PasswordUI.Visibility = Visibility.Collapsed;
  376. }
  377. private void PasswordUI_Confirmed(object sender, string e)
  378. {
  379. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  380. {
  381. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  382. if (passwordViewer.PDFView.Document.IsLocked == false)
  383. {
  384. PasswordUI.SetShowError("", Visibility.Collapsed);
  385. PasswordUI.ClearPassword();
  386. PasswordUI.Visibility = Visibility.Collapsed;
  387. PopupBorder.Visibility = Visibility.Collapsed;
  388. pdfViewControl = passwordViewer;
  389. LoadDocument();
  390. }
  391. else
  392. {
  393. PasswordUI.SetShowError("error", Visibility.Visible);
  394. }
  395. }
  396. }
  397. #endregion
  398. #region ContextMenu
  399. /// <summary>
  400. /// 文字编辑右键菜单
  401. /// </summary>
  402. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  403. {
  404. editCommand.PopupMenu = new ContextMenu();
  405. if (lastPDFEditEvent != null)
  406. {
  407. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  408. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  409. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  410. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  411. MenuItem propertyMenu = new MenuItem();
  412. propertyMenu.Header = "Property";
  413. propertyMenu.Click += (o, p) =>
  414. {
  415. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditText)
  416. {
  417. PDFTextEditControl textEditControl = new PDFTextEditControl();
  418. textEditControl.SetPDFTextEditData(lastPDFEditEvent);
  419. PropertyContainer.Child = textEditControl;
  420. PropertyContainer.Visibility = Visibility.Visible;
  421. }
  422. };
  423. editCommand.PopupMenu.Items.Add(propertyMenu);
  424. }
  425. else
  426. {
  427. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  428. if (editCommand.TextAreaCopied)
  429. {
  430. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  431. }
  432. }
  433. }
  434. /// <summary>
  435. /// 图片编辑右键菜单
  436. /// </summary>
  437. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  438. {
  439. editCommand.PopupMenu = new ContextMenu();
  440. if (lastPDFEditEvent != null)
  441. {
  442. MenuItem rotateLeftMenu = new MenuItem();
  443. rotateLeftMenu.Header = "Left Rotate";
  444. rotateLeftMenu.Click += (o, p) =>
  445. {
  446. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  447. {
  448. lastPDFEditEvent.Rotate = -90;
  449. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  450. }
  451. };
  452. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  453. MenuItem rotateRightMenu = new MenuItem();
  454. rotateRightMenu.Header = "Right Rotate";
  455. rotateRightMenu.Click += (o, p) =>
  456. {
  457. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  458. {
  459. lastPDFEditEvent.Rotate = 90;
  460. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  461. }
  462. };
  463. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  464. MenuItem replaceMenu = new MenuItem();
  465. replaceMenu.Header = "Replace";
  466. replaceMenu.Click += (o, p) =>
  467. {
  468. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  469. {
  470. OpenFileDialog openFileDialog = new OpenFileDialog();
  471. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  472. if (openFileDialog.ShowDialog() == true)
  473. {
  474. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  475. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  476. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  477. }
  478. }
  479. };
  480. editCommand.PopupMenu.Items.Add(replaceMenu);
  481. MenuItem exportMenu = new MenuItem();
  482. exportMenu.Header = "Export";
  483. exportMenu.Click += (o, p) =>
  484. {
  485. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  486. {
  487. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView.GetSelectedImages();
  488. if (imageDict != null && imageDict.Count > 0)
  489. {
  490. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  491. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  492. {
  493. string choosePath = folderBrowser.SelectedPath;
  494. string openPath = choosePath;
  495. try
  496. {
  497. foreach (int pageIndex in imageDict.Keys)
  498. {
  499. List<Bitmap> imageList = imageDict[pageIndex];
  500. foreach (Bitmap image in imageList)
  501. {
  502. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  503. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  504. openPath = savePath;
  505. }
  506. }
  507. Process.Start("explorer", "/select,\"" + openPath + "\"");
  508. }
  509. catch (Exception ex)
  510. {
  511. }
  512. }
  513. }
  514. }
  515. };
  516. editCommand.PopupMenu.Items.Add(exportMenu);
  517. MenuItem opacityMenu = new MenuItem();
  518. opacityMenu.Header = "Opacity";
  519. editCommand.PopupMenu.Items.Add(opacityMenu);
  520. AppendOpacityMenu(opacityMenu);
  521. MenuItem horizonMirror = new MenuItem();
  522. horizonMirror.Header = "HMirror";
  523. horizonMirror.Click += (o, p) =>
  524. {
  525. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  526. {
  527. lastPDFEditEvent.HorizontalMirror = true;
  528. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  529. }
  530. };
  531. editCommand.PopupMenu.Items.Add(horizonMirror);
  532. MenuItem verticalMirror = new MenuItem();
  533. verticalMirror.Header = "VMirror";
  534. verticalMirror.Click += (o, p) =>
  535. {
  536. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  537. {
  538. lastPDFEditEvent.VerticalMirror = true;
  539. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  540. }
  541. };
  542. editCommand.PopupMenu.Items.Add(verticalMirror);
  543. MenuItem cropMenu = new MenuItem();
  544. cropMenu.Header = "Crop";
  545. cropMenu.Click += (o, p) =>
  546. {
  547. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  548. {
  549. lastPDFEditEvent.ClipImage = true;
  550. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  551. }
  552. };
  553. editCommand.PopupMenu.Items.Add(cropMenu);
  554. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  555. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  556. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  557. }
  558. else
  559. {
  560. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  561. }
  562. }
  563. /// <summary>
  564. /// 图片编辑透明度二级菜单
  565. /// </summary>
  566. private void AppendOpacityMenu(MenuItem parentMenu)
  567. {
  568. List<int> opacityList = new List<int>()
  569. {
  570. 25,50,75,100
  571. };
  572. foreach (int opacity in opacityList)
  573. {
  574. MenuItem opacityMenu = new MenuItem();
  575. opacityMenu.Header = string.Format("{0}%", opacity);
  576. opacityMenu.Click += (o, p) =>
  577. {
  578. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  579. {
  580. lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
  581. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  582. }
  583. };
  584. parentMenu.Items.Add(opacityMenu);
  585. }
  586. }
  587. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  588. {
  589. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  590. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  591. {
  592. string choosePath = folderDialog.SelectedPath;
  593. string openPath = choosePath;
  594. try
  595. {
  596. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  597. if (imageDict != null && imageDict.Count > 0)
  598. {
  599. foreach (int pageIndex in imageDict.Keys)
  600. {
  601. List<Bitmap> imageList = imageDict[pageIndex];
  602. foreach (Bitmap image in imageList)
  603. {
  604. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  605. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  606. openPath = savePath;
  607. }
  608. }
  609. }
  610. Process.Start("explorer", "/select,\"" + openPath + "\"");
  611. }
  612. catch (Exception ex)
  613. {
  614. }
  615. }
  616. }
  617. private void CopyImage_Click(object sender, RoutedEventArgs e)
  618. {
  619. try
  620. {
  621. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  622. if (imageDict != null && imageDict.Count > 0)
  623. {
  624. foreach (int pageIndex in imageDict.Keys)
  625. {
  626. List<Bitmap> imageList = imageDict[pageIndex];
  627. foreach (Bitmap image in imageList)
  628. {
  629. MemoryStream ms = new MemoryStream();
  630. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  631. BitmapImage imageData = new BitmapImage();
  632. imageData.BeginInit();
  633. imageData.StreamSource = ms;
  634. imageData.CacheOption = BitmapCacheOption.OnLoad;
  635. imageData.EndInit();
  636. imageData.Freeze();
  637. Clipboard.SetImage(imageData);
  638. break;
  639. }
  640. }
  641. }
  642. }
  643. catch (Exception ex)
  644. {
  645. }
  646. }
  647. #endregion
  648. protected void OnPropertyChanged([CallerMemberName] string name = null)
  649. {
  650. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  651. }
  652. #region UI Action
  653. public void SaveFile()
  654. {
  655. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  656. {
  657. try
  658. {
  659. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  660. if (pdfDoc.WriteToLoadedPath())
  661. {
  662. return;
  663. }
  664. SaveFileDialog saveDialog = new SaveFileDialog();
  665. saveDialog.Filter = "(*.pdf)|*.pdf";
  666. saveDialog.DefaultExt = ".pdf";
  667. saveDialog.OverwritePrompt = true;
  668. if (saveDialog.ShowDialog() == true)
  669. {
  670. pdfDoc.WriteToFilePath(saveDialog.FileName);
  671. }
  672. }
  673. catch (Exception ex)
  674. {
  675. }
  676. }
  677. }
  678. private void OpenFile_Click(object sender, RoutedEventArgs e)
  679. {
  680. try
  681. {
  682. string filePath = CommonHelper.GetFilePathOrEmpty();
  683. if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(filePath))
  684. {
  685. return;
  686. }
  687. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  688. {
  689. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  690. {
  691. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  692. if (oldFilePath.ToLower() == filePath.ToLower())
  693. {
  694. return;
  695. }
  696. }
  697. passwordViewer = new PDFViewControl();
  698. passwordViewer.PDFView.InitDocument(filePath);
  699. if (passwordViewer.PDFView.Document == null)
  700. {
  701. MessageBox.Show("Open File Failed");
  702. return;
  703. }
  704. if (passwordViewer.PDFView.Document.IsLocked)
  705. {
  706. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  707. PasswordUI.ClearPassword();
  708. PopupBorder.Visibility = Visibility.Visible;
  709. PasswordUI.Visibility = Visibility.Visible;
  710. }
  711. else
  712. {
  713. pdfViewControl = passwordViewer;
  714. LoadDocument();
  715. }
  716. }
  717. }
  718. catch (Exception ex)
  719. {
  720. }
  721. }
  722. #endregion
  723. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  724. {
  725. SaveFile();
  726. pdfViewControl.PDFView.UndoManager.CanSave = false;
  727. }
  728. #region ToolPanel
  729. private void ExpandLeftPanel(bool isExpand)
  730. {
  731. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  732. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  733. if (isExpand)
  734. {
  735. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  736. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  737. }
  738. else
  739. {
  740. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  741. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  742. }
  743. }
  744. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  745. {
  746. ToggleButton expandBtn = sender as ToggleButton;
  747. if (expandBtn != null)
  748. {
  749. bool isExpand = expandBtn.IsChecked == true;
  750. ExpandLeftPanel(isExpand);
  751. }
  752. }
  753. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  754. {
  755. ExpandLeftPanel(true);
  756. LeftToolPanelButton.IsChecked = true;
  757. BotaSideTool.SelectBotaTool(BOTATools.Search);
  758. }
  759. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  760. {
  761. ToggleButton toggleButton = sender as ToggleButton;
  762. if (toggleButton != null)
  763. {
  764. if (toggleButton.IsChecked == true)
  765. {
  766. CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
  767. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  768. PropertyContainer.Child = displayPanel;
  769. PropertyContainer.Visibility = Visibility.Visible;
  770. if ((bool)RightPanelButton.IsChecked)
  771. {
  772. RightPanelButton.IsChecked = false;
  773. }
  774. }
  775. else
  776. {
  777. PropertyContainer.Child = null;
  778. PropertyContainer.Visibility = Visibility.Collapsed;
  779. }
  780. }
  781. }
  782. public void ExpandRightPropertyPanel(UIElement properytPanel, Visibility visible)
  783. {
  784. PropertyContainer.Width = 260;
  785. PropertyContainer.Child = properytPanel;
  786. PropertyContainer.Visibility = visible;
  787. if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
  788. {
  789. RightPanelButton.IsChecked = false;
  790. }
  791. }
  792. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  793. {
  794. ToggleButton toggleButton = sender as ToggleButton;
  795. if (toggleButton != null)
  796. {
  797. if (toggleButton.IsChecked == true)
  798. {
  799. if (currentMode == "Annotation")
  800. {
  801. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  802. }
  803. else if (currentMode == "Edit")
  804. {
  805. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  806. }
  807. else
  808. {
  809. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  810. }
  811. if ((bool)ViewSettingBtn.IsChecked)
  812. {
  813. ViewSettingBtn.IsChecked = false;
  814. }
  815. }
  816. else
  817. {
  818. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  819. }
  820. }
  821. }
  822. #endregion
  823. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  824. {
  825. UIElement pageView = sender as UIElement;
  826. if (pageView != null)
  827. {
  828. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  829. }
  830. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  831. {
  832. PDFImageEditControl imageEditControl = new PDFImageEditControl();
  833. imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
  834. imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
  835. pdfEditControl = imageEditControl as UIElement;
  836. PropertyContainer.Child = pdfEditControl;
  837. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  838. }
  839. }
  840. /// <summary>
  841. /// Text and Image Selected Event
  842. /// </summary>
  843. /// <param name="sender"></param>
  844. /// <param name="e"></param>
  845. private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
  846. {
  847. lastPDFEditEvent = e;
  848. ViewSettingBtn.IsChecked = false;
  849. if (e == null)
  850. {
  851. pdfEditControl = null;
  852. PropertyContainer.Child = pdfEditControl;
  853. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  854. return;
  855. }
  856. if (Mouse.RightButton == MouseButtonState.Pressed)
  857. {
  858. return;
  859. }
  860. if (e.EditType == CPDFEditType.EditText)
  861. {
  862. PDFTextEditControl textEditControl = new PDFTextEditControl();
  863. textEditControl.SetPDFTextEditData(e);
  864. pdfEditControl = textEditControl as UIElement;
  865. PropertyContainer.Child = pdfEditControl;
  866. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  867. return;
  868. }
  869. if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
  870. {
  871. UIElement pageView = sender as UIElement;
  872. if (pageView != null)
  873. {
  874. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp; ;
  875. }
  876. return;
  877. }
  878. }
  879. /// <summary>
  880. /// Actions performed when switching modes:
  881. /// Separated into actions performed upon entering and exiting the mode.
  882. /// </summary>
  883. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  884. {
  885. if (isFirstLoad)
  886. {
  887. isFirstLoad = false;
  888. return;
  889. }
  890. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  891. switch (currentMode)
  892. {
  893. case "Viewer":
  894. break;
  895. //Behavior when exit Edit mode
  896. // Clear the ToolBar
  897. // Collapse the ToolBar
  898. // Clear And Collapse the property panel.
  899. // Change the mousemode
  900. case "Annotation":
  901. AnnotationBarControl.Visibility = Visibility.Collapsed;
  902. AnnotationBarControl.ClearAllToolState();
  903. pdfAnnotationControl.ClearPanel();
  904. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  905. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  906. break;
  907. // Behavior when exit Edit mode:
  908. // Collapsed the ToolBar
  909. // Set the mode to allow editing None
  910. // Set the mouse mode to PanTool
  911. // Reload Document
  912. // Unsubscribe click event.
  913. // Clear And Collapse the property panel.
  914. case "Edit":
  915. PDFEditTool.Visibility = Visibility.Collapsed;
  916. pdfViewControl.PDFView?.SetShowLink(true);
  917. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
  918. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  919. pdfViewControl.PDFView?.ReloadDocument();
  920. pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  921. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  922. break;
  923. default:
  924. break;
  925. }
  926. // Behavior when switching to Viewer mode:
  927. // Hide the ToolBar
  928. if ((string)item.Content == "Viewer")
  929. {
  930. ToolBarContainer.Visibility = Visibility.Collapsed;
  931. }
  932. // Behavior when switching to Annotation mode:
  933. // Show the ToolBar
  934. // Show the AnnotationBar
  935. else if ((string)item.Content == "Annotation")
  936. {
  937. ToolBarContainer.Visibility = Visibility.Visible;
  938. AnnotationBarControl.Visibility = Visibility.Visible;
  939. }
  940. // Behavior when switching to Edit mode:
  941. // Show the ToolBar
  942. // Show the EditBar
  943. // Set the mode to allow editing of both text and images
  944. // Set the mouse mode to PDFEdit
  945. // Reload Document
  946. else if ((string)item.Content == "Edit")
  947. {
  948. ToolBarContainer.Visibility = Visibility.Visible;
  949. PDFEditTool.Visibility = Visibility.Visible;
  950. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
  951. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  952. pdfViewControl.PDFView?.ReloadDocument();
  953. pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  954. }
  955. currentMode = (string)item.Content;
  956. }
  957. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  958. {
  959. PasswordUI.Visibility = Visibility.Collapsed;
  960. FileInfoUI.Visibility = Visibility.Visible;
  961. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  962. PopupBorder.Visibility = Visibility.Visible;
  963. }
  964. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  965. {
  966. PopupBorder.Visibility = Visibility.Collapsed;
  967. }
  968. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  969. {
  970. 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 };
  971. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  972. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  973. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  974. }
  975. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  976. {
  977. ToggleButton toggleButton = sender as ToggleButton;
  978. if (toggleButton != null)
  979. {
  980. if (toggleButton.IsChecked == true)
  981. {
  982. if (pdfAnnotationControl != null)
  983. {
  984. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  985. if ((bool)ViewSettingBtn.IsChecked)
  986. {
  987. ViewSettingBtn.IsChecked = false;
  988. }
  989. }
  990. }
  991. else
  992. {
  993. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  994. }
  995. }
  996. }
  997. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  998. {
  999. pdfAnnotationControl.LoadAnnotationPanel(e);
  1000. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  1001. {
  1002. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  1003. RightPanelButton.IsChecked = true;
  1004. }
  1005. }
  1006. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  1007. {
  1008. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  1009. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  1010. }
  1011. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  1012. {
  1013. ToggleButton senderBtn = sender as ToggleButton;
  1014. if (senderBtn != null && pdfViewControl != null)
  1015. {
  1016. ClearPDFEditState(senderBtn);
  1017. if (senderBtn.IsChecked == true)
  1018. {
  1019. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1020. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  1021. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  1022. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1023. pdfViewControl.PDFView?.ReloadDocument();
  1024. }
  1025. else
  1026. {
  1027. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  1028. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  1029. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1030. pdfViewControl.PDFView?.ReloadDocument();
  1031. }
  1032. }
  1033. }
  1034. /// <summary>
  1035. /// Clear the selected state of editing-related buttons.
  1036. /// </summary>
  1037. private void ClearPDFEditState(ToggleButton ignoreBtn = null)
  1038. {
  1039. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  1040. {
  1041. PDFTextEditButton,
  1042. PDFImageEditButton
  1043. };
  1044. foreach (ToggleButton item in clearBtnList)
  1045. {
  1046. if (ignoreBtn == item)
  1047. {
  1048. continue;
  1049. }
  1050. item.IsChecked = false;
  1051. }
  1052. }
  1053. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  1054. {
  1055. ToggleButton senderBtn = sender as ToggleButton;
  1056. if (senderBtn != null && pdfViewControl != null)
  1057. {
  1058. senderBtn.IsChecked = false;
  1059. OpenFileDialog openFileDialog = new OpenFileDialog();
  1060. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1061. if (openFileDialog.ShowDialog() == true)
  1062. {
  1063. ClearPDFEditState(senderBtn);
  1064. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  1065. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  1066. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1067. pdfViewControl.PDFView?.ReloadDocument();
  1068. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1069. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  1070. pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  1071. }
  1072. }
  1073. }
  1074. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  1075. {
  1076. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  1077. {
  1078. pdfViewControl.PDFView.UndoManager?.Undo();
  1079. }
  1080. }
  1081. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  1082. {
  1083. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  1084. {
  1085. pdfViewControl.PDFView.UndoManager?.Redo();
  1086. }
  1087. }
  1088. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  1089. {
  1090. pdfAnnotationControl = new CPDFAnnotationControl();
  1091. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
  1092. LoadDocument();
  1093. }
  1094. public void SetPDFViewer(PDFViewControl newPdfViewer)
  1095. {
  1096. if(newPdfViewer!=null)
  1097. {
  1098. pdfViewControl = newPdfViewer;
  1099. }
  1100. }
  1101. }
  1102. }