MainWindow.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. using ComPDFKit.PDFDocument;
  2. using Compdfkit_Tools.Helper;
  3. using Compdfkit_Tools.PDFControl;
  4. using Compdfkit_Tools.PDFView;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.PdfViewer;
  7. using Microsoft.Win32;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Linq;
  12. using System.Runtime.CompilerServices;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Controls.Primitives;
  18. using System.Windows.Data;
  19. using System.Windows.Documents;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Navigation;
  24. using System.Windows.Shapes;
  25. using ComPDFKit.DigitalSign;
  26. namespace DigitalSignature
  27. {
  28. /// <summary>
  29. /// Interaction logic for MainWindow.xaml
  30. /// </summary>
  31. public partial class MainWindow : Window, INotifyPropertyChanged
  32. {
  33. private string currentMode = "Viewer";
  34. private bool isFirstLoad = true;
  35. private PDFViewControl pdfViewer;
  36. private PDFViewControl passwordViewer;
  37. private RegularViewerControl regularViewerControl = new RegularViewerControl();
  38. private DigitalSignatureControl digitalSignatureControl = new DigitalSignatureControl();
  39. private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation | BOTATools.Signature);
  40. private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
  41. private SignatureStatusBarControl signatureStatusBarControl = new SignatureStatusBarControl();
  42. private PanelState panelState = PanelState.GetInstance();
  43. public event PropertyChangedEventHandler PropertyChanged;
  44. #region Properties
  45. /// <summary>
  46. /// Whether the save operation can be performed.
  47. /// </summary>
  48. private bool _canSave = false;
  49. public bool CanSave
  50. {
  51. get => _canSave;
  52. set
  53. {
  54. _canSave = value;
  55. OnPropertyChanged();
  56. }
  57. }
  58. /// <summary>
  59. /// Whether the left panel is expanded.
  60. /// </summary>
  61. public bool LeftToolPanelButtonIsChecked
  62. {
  63. get => panelState.IsLeftPanelExpand;
  64. set
  65. {
  66. panelState.IsLeftPanelExpand = value;
  67. OnPropertyChanged();
  68. }
  69. }
  70. /// <summary>
  71. /// Whether the right panel is expanded.
  72. /// </summary>
  73. public bool RightToolPanelButtonIsChecked
  74. {
  75. get
  76. {
  77. return (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel);
  78. }
  79. set
  80. {
  81. panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  82. OnPropertyChanged();
  83. }
  84. }
  85. /// <summary>
  86. /// Whether the view setting panel is expanded.
  87. /// </summary>
  88. public bool ViewSettingBtnIsChecked
  89. {
  90. get
  91. {
  92. return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
  93. }
  94. set
  95. {
  96. panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  97. OnPropertyChanged();
  98. }
  99. }
  100. #endregion
  101. public MainWindow()
  102. {
  103. InitializeComponent();
  104. DataContext = this;
  105. digitalSignatureControl.AfterFillSignature -= DigitalSignatureControl_AfterFillSignature;
  106. digitalSignatureControl.AfterFillSignature += DigitalSignatureControl_AfterFillSignature;
  107. Closing += MainWindow_Closing;
  108. }
  109. #region Load Document
  110. /// <summary>
  111. /// Open a PDF file.
  112. /// </summary>
  113. /// <param name="filePath">The path of the PDF file.</param>
  114. private void OpenFile(string filePath = "")
  115. {
  116. if (string.IsNullOrEmpty(filePath))
  117. {
  118. filePath = CommonHelper.GetExistedPathOrEmpty();
  119. }
  120. string oldFilePath = pdfViewer.PDFView.Document.FilePath;
  121. if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)
  122. {
  123. if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
  124. {
  125. if (oldFilePath.ToLower() == filePath.ToLower())
  126. {
  127. return;
  128. }
  129. }
  130. passwordViewer = new PDFViewControl();
  131. passwordViewer.PDFView.InitDocument(filePath);
  132. if (passwordViewer.PDFView.Document == null)
  133. {
  134. MessageBox.Show("Open File Failed");
  135. return;
  136. }
  137. if (passwordViewer.PDFView.Document.IsLocked)
  138. {
  139. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  140. PasswordUI.ClearPassword();
  141. PopupBorder.Visibility = Visibility.Visible;
  142. PasswordUI.Visibility = Visibility.Visible;
  143. }
  144. else
  145. {
  146. pdfViewer.PDFView.Document.Release();
  147. pdfViewer = passwordViewer;
  148. LoadDocument();
  149. }
  150. }
  151. }
  152. /// <summary>
  153. /// Load the default PDF file when the application is started.
  154. /// </summary>
  155. private void LoadDefaultDocument()
  156. {
  157. string defaultFilePath = "PDF32000_2008.pdf";
  158. pdfViewer.PDFView.InitDocument(defaultFilePath);
  159. LoadDocument();
  160. }
  161. /// <summary>
  162. /// Load the custom controls for the PDF viewer.
  163. /// </summary>
  164. private void LoadCustomControl()
  165. {
  166. regularViewerControl.PdfViewControl = pdfViewer;
  167. regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
  168. regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  169. regularViewerControl.SetBOTAContainer(null);
  170. regularViewerControl.SetBOTAContainer(botaBarControl);
  171. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  172. PDFGrid.Child = regularViewerControl;
  173. SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
  174. digitalSignatureControl.OnCanSaveChanged -= DigitalSignatureControl_OnCanSaveChanged;
  175. digitalSignatureControl.OnCanSaveChanged += DigitalSignatureControl_OnCanSaveChanged;
  176. digitalSignatureControl.SignatureStatusChanged -= DigitalSignatureControl_OnSignatureStatusChanged;
  177. digitalSignatureControl.SignatureStatusChanged += DigitalSignatureControl_OnSignatureStatusChanged;
  178. signatureStatusBarControl.OnViewSignatureButtonClicked -= ViewAllSignatures;
  179. signatureStatusBarControl.OnViewSignatureButtonClicked += ViewAllSignatures;
  180. SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
  181. digitalSignatureControl.LoadUndoManagerEvent(pdfViewer.PDFView);
  182. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  183. regularViewerControl.SetSignatureStatusBarControl(signatureStatusBarControl);
  184. }
  185. /// <summary>
  186. /// Load current PDF file and initialize event handlers.
  187. /// </summary>
  188. private void LoadDocument()
  189. {
  190. if (pdfViewer.PDFView.Document == null)
  191. {
  192. return;
  193. }
  194. pdfViewer.PDFView.Load();
  195. pdfViewer.PDFView.SetShowLink(true);
  196. pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  197. pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
  198. pdfViewer.PDFView.SetFormFieldHighlight(true);
  199. pdfViewer.CustomSignHandle = true;
  200. PasswordUI.Closed -= PasswordUI_Closed;
  201. PasswordUI.Canceled -= PasswordUI_Canceled;
  202. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  203. PasswordUI.Closed += PasswordUI_Closed;
  204. PasswordUI.Canceled += PasswordUI_Canceled;
  205. PasswordUI.Confirmed += PasswordUI_Confirmed;
  206. ModeComboBox.SelectedIndex = 0;
  207. botaBarControl.InitWithPDFViewer(pdfViewer.PDFView);
  208. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  209. botaBarControl.DeleteSignatureEvent -= BotaControlOnDeleteSignatureEvent;
  210. botaBarControl.DeleteSignatureEvent += BotaControlOnDeleteSignatureEvent;
  211. botaBarControl.ViewCertificateEvent -= digitalSignatureControl.ViewCertificateEvent;
  212. botaBarControl.ViewCertificateEvent += digitalSignatureControl.ViewCertificateEvent;
  213. botaBarControl.ViewSignatureEvent -= digitalSignatureControl.ViewSignatureEvent;
  214. botaBarControl.ViewSignatureEvent += digitalSignatureControl.ViewSignatureEvent;
  215. displaySettingsControl.InitWithPDFViewer(pdfViewer.PDFView);
  216. LoadCustomControl();
  217. pdfViewer.PDFView.ChangeFitMode(FitMode.FitWidth);
  218. CPDFSaclingControl.InitWithPDFViewer(pdfViewer.PDFView);
  219. panelState.PropertyChanged -= PanelState_PropertyChanged;
  220. panelState.PropertyChanged += PanelState_PropertyChanged;
  221. }
  222. /// <summary>
  223. /// Event handler for confirming the password. Open the PDF file if the password is correct.
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void PasswordUI_Confirmed(object sender, string e)
  228. {
  229. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  230. {
  231. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  232. if (passwordViewer.PDFView.Document.IsLocked == false)
  233. {
  234. PasswordUI.SetShowError("", Visibility.Collapsed);
  235. PasswordUI.ClearPassword();
  236. PasswordUI.Visibility = Visibility.Collapsed;
  237. PopupBorder.Visibility = Visibility.Collapsed;
  238. pdfViewer = passwordViewer;
  239. LoadDocument();
  240. }
  241. else
  242. {
  243. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  244. }
  245. }
  246. }
  247. /// <summary>
  248. /// Event handler for canceling password input.
  249. /// </summary>
  250. /// <param name="sender"></param>
  251. /// <param name="e"></param>
  252. private void PasswordUI_Canceled(object sender, EventArgs e)
  253. {
  254. PopupBorder.Visibility = Visibility.Collapsed;
  255. PasswordUI.Visibility = Visibility.Collapsed;
  256. }
  257. /// <summary>
  258. /// Event handler for closing the password input dialog.
  259. /// </summary>
  260. /// <param name="sender"></param>
  261. /// <param name="e"></param>
  262. private void PasswordUI_Closed(object sender, EventArgs e)
  263. {
  264. PopupBorder.Visibility = Visibility.Collapsed;
  265. PasswordUI.Visibility = Visibility.Collapsed;
  266. }
  267. #endregion
  268. #region Commands
  269. /// <summary>
  270. /// Command for the OpenFileBtn click event. Opens a PDF file.
  271. /// </summary>
  272. /// <param name="sender"></param>
  273. /// <param name="e"></param>
  274. private void OpenFile_Click(object sender, RoutedEventArgs e)
  275. {
  276. OpenFile();
  277. }
  278. /// <summary>
  279. /// Command for opening a PDF file saved with a signature.
  280. /// </summary>
  281. /// <param name="sender"></param>
  282. /// <param name="e"></param>
  283. private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
  284. {
  285. OpenFile(e);
  286. }
  287. /// <summary>
  288. /// When the RightPanel state is changed, decide whether to display the ViewSettingPanel or RightToolPanel.
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  293. {
  294. if (e.PropertyName == "RightPanel")
  295. {
  296. OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
  297. OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
  298. }
  299. }
  300. /// <summary>
  301. /// Event handler for deleting a signature from the BOTA. Set the CanSave property to true and update the signature status.
  302. /// </summary>
  303. /// <param name="sender"></param>
  304. /// <param name="e"></param>
  305. private void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
  306. {
  307. pdfViewer.PDFView.UndoManager.CanSave = true;
  308. DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
  309. //this.CanSave = true;
  310. }
  311. /// <summary>
  312. /// Event handler for updating a signature. Update the signature status.
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
  317. {
  318. SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
  319. SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
  320. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  321. botaBarControl.LoadSignatureList();
  322. }
  323. /// <summary>
  324. /// Event handler for updating the CanSave property.
  325. /// </summary>
  326. /// <param name="sender"></param>
  327. /// <param name="e"></param>
  328. private void DigitalSignatureControl_OnCanSaveChanged(object sender, bool e)
  329. {
  330. this.CanSave = e;
  331. }
  332. /// <summary>
  333. /// Event handler for the ZoomInBtn click event. Zoom in the PDF file.
  334. /// </summary>
  335. /// <param name="sender"></param>
  336. /// <param name="e"></param>
  337. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  338. {
  339. if (e.Key == "Zoom")
  340. {
  341. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  342. }
  343. }
  344. /// <summary>
  345. /// Event handler for the SaveAsFileBtn click event. Save the PDF file and set the CanSave property to false.
  346. /// </summary>
  347. /// <param name="sender"></param>
  348. /// <param name="e"></param>
  349. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  350. {
  351. SaveFile();
  352. pdfViewer.PDFView.UndoManager.CanSave = false;
  353. }
  354. /// <summary>
  355. /// Event handler for the LeftToolPanelButton click event. Expand or collapse the left panel.
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  360. {
  361. panelState.IsLeftPanelExpand = (sender as ToggleButton).IsChecked == true;
  362. }
  363. /// <summary>
  364. /// Event handler for the ComboBox selection changed event. Switch between the Viewer and Digital Signature modes.
  365. /// </summary>
  366. /// <param name="sender"></param>
  367. /// <param name="e"></param>
  368. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  369. {
  370. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  371. if (item.Content as string == currentMode)
  372. {
  373. return;
  374. }
  375. ClearPanelState();
  376. if(ViewSettingBtn != null)
  377. ViewSettingBtn.IsChecked = false;
  378. if(RightPanelButton != null)
  379. RightPanelButton.IsChecked = false;
  380. if (currentMode == "Viewer")
  381. {
  382. regularViewerControl.ClearViewerControl();
  383. }
  384. else if (currentMode == "Digital Signature")
  385. {
  386. digitalSignatureControl.ClearViewerControl();
  387. }
  388. if (item.Content as string == "Viewer")
  389. {
  390. if (regularViewerControl.PdfViewControl != null && regularViewerControl.PdfViewControl.PDFView != null)
  391. {
  392. PDFGrid.Child = regularViewerControl;
  393. regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  394. regularViewerControl.PdfViewControl = pdfViewer;
  395. regularViewerControl.InitWithPDFViewer(pdfViewer.PDFView);
  396. regularViewerControl.SetBOTAContainer(botaBarControl);
  397. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  398. regularViewerControl.SetSignatureStatusBarControl(signatureStatusBarControl);
  399. }
  400. }
  401. else if (item.Content as string == "Digital Signature")
  402. {
  403. if (digitalSignatureControl.PDFViewControl != null && digitalSignatureControl.PDFViewControl.PDFView != null)
  404. {
  405. PDFGrid.Child = digitalSignatureControl;
  406. digitalSignatureControl.PDFViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  407. digitalSignatureControl.PDFViewControl = pdfViewer;
  408. digitalSignatureControl.InitWithPDFViewer(pdfViewer.PDFView);
  409. digitalSignatureControl.SetBOTAContainer(botaBarControl);
  410. digitalSignatureControl.SetDisplaySettingsControl(displaySettingsControl);
  411. digitalSignatureControl.SetSignatureStatusBarControl(signatureStatusBarControl);
  412. }
  413. }
  414. currentMode = item.Content as string;
  415. }
  416. /// <summary>
  417. /// Event handler for ViewSignatureBtn click event. Expand the bota control and select the Signature tool.
  418. /// </summary>
  419. /// <param name="sender"></param>
  420. /// <param name="e"></param>
  421. private void ViewAllSignatures(object sender, EventArgs e)
  422. {
  423. LeftToolPanelButton.IsChecked = true;
  424. botaBarControl.SelectBotaTool(BOTATools.Signature);
  425. }
  426. /// <summary>
  427. /// Event handler for the SearchBtn click event. Expand the bota control and select the Search tool.
  428. /// </summary>
  429. /// <param name="sender"></param>
  430. /// <param name="e"></param>
  431. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  432. {
  433. LeftToolPanelButton.IsChecked = true;
  434. botaBarControl.SelectBotaTool(BOTATools.Search);
  435. }
  436. /// <summary>
  437. /// Event handler for the RightPanelButton click event. Expand or collapse the right panel.
  438. /// </summary>
  439. /// <param name="sender"></param>
  440. /// <param name="e"></param>
  441. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  442. {
  443. panelState.RightPanel =
  444. ((sender as ToggleButton).IsChecked == true) ?
  445. PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  446. }
  447. /// <summary>
  448. /// Event handler for the ViewSettingBtn click event. Expand or collapse the view setting panel.
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  453. {
  454. panelState.RightPanel =
  455. ((sender as ToggleButton).IsChecked == true) ?
  456. PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  457. }
  458. /// <summary>
  459. /// Close all the expanded panels.
  460. /// </summary>
  461. private void ClearPanelState()
  462. {
  463. LeftToolPanelButtonIsChecked = false;
  464. ViewSettingBtnIsChecked = false;
  465. RightToolPanelButtonIsChecked = false;
  466. }
  467. /// <summary>
  468. /// Event handler for the PageInfoBtn click event. Expand the file info window.
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  473. {
  474. PasswordUI.Visibility = Visibility.Collapsed;
  475. FileInfoUI.Visibility = Visibility.Visible;
  476. FileInfoControl.InitWithPDFViewer(pdfViewer.PDFView);
  477. PopupBorder.Visibility = Visibility.Visible;
  478. }
  479. /// <summary>
  480. /// Event handler for the CloseFileInfoBtn click event. Collapse the file info window.
  481. /// </summary>
  482. /// <param name="sender"></param>
  483. /// <param name="e"></param>
  484. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  485. {
  486. PopupBorder.Visibility = Visibility.Collapsed;
  487. }
  488. /// <summary>
  489. /// Event handler for the control loaded event. Load the default PDF file.
  490. /// </summary>
  491. /// <param name="sender"></param>
  492. /// <param name="e"></param>
  493. private void Window_Loaded(object sender, RoutedEventArgs e)
  494. {
  495. pdfViewer = new PDFViewControl();
  496. LoadDefaultDocument();
  497. }
  498. /// <summary>
  499. /// Event handler for the control unloaded event.
  500. /// </summary>
  501. /// <param name="sender"></param>
  502. /// <param name="e"></param>
  503. private void Window_Unloaded(object sender, RoutedEventArgs e)
  504. {
  505. }
  506. /// <summary>
  507. /// Event handler for closing the window. Prompt to save the changes.
  508. /// </summary>
  509. /// <param name="sender"></param>
  510. /// <param name="e"></param>
  511. private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  512. {
  513. if(CanSave)
  514. {
  515. MessageBoxResult result = MessageBox.Show("Do you want to save the changes to the document?",
  516. "Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
  517. if (result == MessageBoxResult.Yes)
  518. {
  519. SaveFile();
  520. }
  521. else if (result == MessageBoxResult.Cancel)
  522. {
  523. e.Cancel = true;
  524. }
  525. }
  526. }
  527. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  528. {
  529. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  530. }
  531. #endregion
  532. #region Save file
  533. /// <summary>
  534. /// Save the file to another PDF file.
  535. /// </summary>
  536. public void SaveAsFile()
  537. {
  538. {
  539. if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
  540. {
  541. CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
  542. SaveFileDialog saveDialog = new SaveFileDialog();
  543. saveDialog.Filter = "(*.pdf)|*.pdf";
  544. saveDialog.DefaultExt = ".pdf";
  545. saveDialog.OverwritePrompt = true;
  546. if (saveDialog.ShowDialog() == true)
  547. {
  548. pdfDoc.WriteToFilePath(saveDialog.FileName);
  549. }
  550. }
  551. }
  552. }
  553. /// <summary>
  554. /// Save the file in the current path.
  555. /// </summary>
  556. public void SaveFile()
  557. {
  558. if (pdfViewer != null && pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
  559. {
  560. try
  561. {
  562. CPDFDocument pdfDoc = pdfViewer.PDFView.Document;
  563. if (pdfDoc.WriteToLoadedPath())
  564. {
  565. return;
  566. }
  567. SaveFileDialog saveDialog = new SaveFileDialog();
  568. saveDialog.Filter = "(*.pdf)|*.pdf";
  569. saveDialog.DefaultExt = ".pdf";
  570. saveDialog.OverwritePrompt = true;
  571. if (saveDialog.ShowDialog() == true)
  572. {
  573. pdfDoc.WriteToFilePath(saveDialog.FileName);
  574. }
  575. }
  576. catch (Exception ex)
  577. {
  578. }
  579. }
  580. }
  581. #endregion
  582. }
  583. }