ViewContentViewModel.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using ComPDFKitViewer.PdfViewer;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using PDF_Office.CustomControl;
  11. using PDF_Office.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Office.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Office.EventAggregators;
  19. using PDF_Office.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings.Settings;
  22. using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. namespace PDF_Office.ViewModels
  25. {
  26. public class ViewContentViewModel : BindableBase, INavigationAware
  27. {
  28. #region 属性、变量
  29. public CPDFViewer PDFViewer { get; set; }
  30. public MainContentViewModel mainViewModel { get; set; }
  31. public IRegionManager region;
  32. public IDialogService dialogs;
  33. public IEventAggregator events;
  34. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  35. public string ViwerRegionName { get; set; }
  36. /// <summary>
  37. /// 分屏视图的region名称
  38. /// </summary>
  39. public string SplitViewerRegionName { get; set; }
  40. /// <summary>
  41. /// OCR视图名称
  42. /// </summary>
  43. public string OCRViewerRegionName { get; set; }
  44. public string BOTARegionName { get; set; }
  45. public string PropertyRegionName { get; set; }
  46. public string ToolContentRegionName { get; set; }
  47. public string ToolsBarContentRegionName { get; set; }
  48. /// <summary>
  49. /// 顶部提示的Content
  50. /// </summary>
  51. public string TipContentRegionName { get; set; }
  52. public string LeftTipContentRegionName { get; set; }
  53. public string ReadModeRegionName { get; set; }
  54. public string ConverterBarContentRegionName { get; set; }
  55. public string TextEditContentRegionName { get; set; }
  56. public string BackgroundContentRegionName { get; set; }
  57. public List<Point> FillAndSign = new List<Point>();
  58. /// <summary>
  59. /// 文档的密码
  60. /// </summary>
  61. public string PassWord { get; set; }
  62. private Visibility tipVisible = Visibility.Collapsed;
  63. /// <summary>
  64. /// 顶部提示栏的显示状态
  65. /// </summary>
  66. public Visibility TipVisible
  67. {
  68. get { return tipVisible; }
  69. set
  70. {
  71. SetProperty(ref tipVisible, value);
  72. }
  73. }
  74. private Visibility leftTipVisible = Visibility.Collapsed;
  75. public Visibility LeftTipVisible
  76. {
  77. get { return leftTipVisible; }
  78. set
  79. {
  80. SetProperty(ref leftTipVisible, value);
  81. }
  82. }
  83. private Visibility readModelTip = Visibility.Collapsed;
  84. public Visibility ReadModelTip
  85. {
  86. get { return readModelTip; }
  87. set
  88. {
  89. SetProperty(ref readModelTip, value);
  90. }
  91. }
  92. /// <summary>
  93. /// 底部工具栏 RegionName
  94. /// </summary>
  95. public string BottomToolRegionName { get; set; }
  96. private bool _isInPageEdit = false;
  97. /// <summary>
  98. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  99. /// </summary>
  100. public bool isInPageEdit
  101. {
  102. get { return _isInPageEdit; }
  103. set
  104. {
  105. _isInPageEdit = value;
  106. if (!value)
  107. {
  108. CanRedo = PDFViewer.UndoManager.CanRedo;
  109. CanUndo = PDFViewer.UndoManager.CanUndo;
  110. }
  111. }
  112. }
  113. public Action PageEditUndo { get; set; }
  114. public Action PageEditRedo { get; set; }
  115. /// <summary>
  116. ///工具条
  117. ///0:收起
  118. ///40:显示
  119. /// </summary>
  120. private int toolRowHeight = 40;
  121. public int ToolRowHeight
  122. {
  123. get { return toolRowHeight; }
  124. set
  125. {
  126. SetProperty(ref toolRowHeight, value);
  127. }
  128. }
  129. /// <summary>
  130. /// 水印,背景侧边栏宽度
  131. /// 0:收起
  132. /// 260:显示
  133. /// </summary>
  134. private int propertyColumnWidth = 0;
  135. public int PropertyColumnWidth
  136. {
  137. get { return propertyColumnWidth; }
  138. set
  139. {
  140. SetProperty(ref propertyColumnWidth, value);
  141. }
  142. }
  143. private int gridToolRow = 1;
  144. /// <summary>
  145. /// 控制ToolContent的Row
  146. /// </summary>
  147. public int GridToolRow
  148. {
  149. get { return gridToolRow; }
  150. set
  151. {
  152. SetProperty(ref gridToolRow, value);
  153. }
  154. }
  155. private int gridToolRowSpan = 3;
  156. /// <summary>
  157. /// 控制ToolContent的RowSpan
  158. /// </summary>
  159. public int GridToolRowSpan
  160. {
  161. get { return gridToolRowSpan; }
  162. set
  163. {
  164. SetProperty(ref gridToolRowSpan, value);
  165. }
  166. }
  167. private Visibility toolContentVisible = Visibility.Collapsed;
  168. /// <summary>
  169. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  170. /// 留意:显示前需要先注入内容、设置好行和跨行数
  171. /// </summary>
  172. public Visibility ToolContentVisible
  173. {
  174. get { return toolContentVisible; }
  175. set
  176. {
  177. SetProperty(ref toolContentVisible, value);
  178. }
  179. }
  180. private Visibility gridVisibility = Visibility.Visible;
  181. /// <summary>
  182. /// 是否正在加载中
  183. /// </summary>
  184. public Visibility GridVisibility
  185. {
  186. get { return gridVisibility; }
  187. set
  188. {
  189. SetProperty(ref gridVisibility, value);
  190. }
  191. }
  192. private Visibility isLoading = Visibility.Collapsed;
  193. private Visibility ocrContentVisible = Visibility.Collapsed;
  194. public Visibility OCRContentVisible
  195. {
  196. get { return ocrContentVisible; }
  197. set
  198. {
  199. SetProperty(ref ocrContentVisible, value);
  200. }
  201. }
  202. /// <summary>
  203. /// 是否正在加载中
  204. /// </summary>
  205. public Visibility IsLoading
  206. {
  207. get { return isLoading; }
  208. set
  209. {
  210. SetProperty(ref isLoading, value);
  211. }
  212. }
  213. private Visibility converterBarContentVisible = Visibility.Collapsed;
  214. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  215. /// <summary>
  216. /// 控制ToolsBarContent的显示
  217. /// 留意:显示前需要先注入内容、设置好行和跨行数
  218. /// </summary>
  219. public Visibility ConverterBarContentVisible
  220. {
  221. get { return converterBarContentVisible; }
  222. set
  223. {
  224. SetProperty(ref converterBarContentVisible, value);
  225. }
  226. }
  227. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  228. /// <summary>
  229. /// 控制ToolsBarContent的显示
  230. /// 留意:显示前需要先注入内容、设置好行和跨行数
  231. /// </summary>
  232. public Visibility ToolsBarContentVisible
  233. {
  234. get { return toolsBarContentVisible; }
  235. set
  236. {
  237. SetProperty(ref toolsBarContentVisible, value);
  238. }
  239. }
  240. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  241. /// <summary>
  242. /// 控制ToolsBarContent的显示
  243. /// 留意:显示前需要先注入内容、设置好行和跨行数
  244. /// </summary>
  245. public Visibility TextEditToolContentVisible
  246. {
  247. get { return textEditToolContentVisible; }
  248. set
  249. {
  250. SetProperty(ref textEditToolContentVisible, value);
  251. }
  252. }
  253. private bool isPorpertyOpen = false;
  254. /// <summary>
  255. /// 属性栏是否展开
  256. /// </summary>
  257. public bool IsPropertyOpen
  258. {
  259. get { return isPorpertyOpen; }
  260. set
  261. {
  262. SetProperty(ref isPorpertyOpen, value);
  263. }
  264. }
  265. private Visibility isReadMode = Visibility.Visible;
  266. /// <summary>
  267. ///是否为阅读模式
  268. /// </summary>
  269. public Visibility IsReadMode
  270. {
  271. get { return isReadMode; }
  272. set
  273. {
  274. SetProperty(ref isReadMode, value);
  275. }
  276. }
  277. private bool canSave;
  278. /// <summary>
  279. /// 是否可以保存
  280. /// </summary>
  281. public bool CanSave
  282. {
  283. get { return canSave; }
  284. set
  285. {
  286. SetProperty(ref canSave, value);
  287. }
  288. }
  289. private bool canUndo;
  290. /// <summary>
  291. /// 是否可以进行Undo
  292. /// </summary>
  293. public bool CanUndo
  294. {
  295. get { return canUndo; }
  296. set
  297. {
  298. SetProperty(ref canUndo, value);
  299. }
  300. }
  301. private bool canRedo;
  302. /// <summary>
  303. /// 是否可以进行Redo
  304. /// </summary>
  305. public bool CanRedo
  306. {
  307. get { return canRedo; }
  308. set
  309. {
  310. SetProperty(ref canRedo, value);
  311. }
  312. }
  313. private GridLength botaWidth = new GridLength(48);
  314. /// <summary>
  315. /// BOTA栏的宽度
  316. /// </summary>
  317. public GridLength BOTAWidth
  318. {
  319. get { return botaWidth; }
  320. set
  321. {
  322. SetProperty(ref botaWidth, value);
  323. if (botaWidth.Value <= 48)
  324. {
  325. OpenBOTA = false;
  326. }
  327. }
  328. }
  329. private int selectedIndex;
  330. /// <summary>
  331. /// 工具栏选中项的索引
  332. /// </summary>
  333. public int TabSelectedIndex
  334. {
  335. get { return selectedIndex; }
  336. set
  337. {
  338. SetProperty(ref selectedIndex, value);
  339. }
  340. }
  341. private bool openBOTA = false;
  342. /// <summary>
  343. /// 是否展开BOTA
  344. /// </summary>
  345. public bool OpenBOTA
  346. {
  347. get { return openBOTA; }
  348. set
  349. {
  350. SetProperty(ref openBOTA, value);
  351. if (openBOTA && BOTAWidth.Value <= 48)
  352. {
  353. BOTAWidth = new GridLength(260);
  354. }
  355. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  356. }
  357. }
  358. public SecurityInfo SecurityInfo = new SecurityInfo();
  359. private Dictionary<string, string> regionNameByTabItem;
  360. private Dictionary<string, string> barContentByTabItem;
  361. private string previousBar = "";
  362. public string CurrentBar = "";
  363. public string unicode = null;
  364. /// <summary>
  365. /// 用来避免重复触发导航事件的标志符
  366. /// </summary>
  367. private bool isOpenFile = false;
  368. /// <summary>
  369. /// 鼠标滚轮缩放的缩放值
  370. /// </summary>
  371. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  372. /// <summary>
  373. /// 注释-链接,提示语
  374. /// </summary>
  375. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  376. public Visibility LinkAnnotTipVisibility
  377. {
  378. get { return linkAnnotTipVisibility; }
  379. set
  380. {
  381. SetProperty(ref linkAnnotTipVisibility, value);
  382. }
  383. }
  384. private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
  385. private bool isCreateLink = false;
  386. public string LinkAnnotTipText
  387. {
  388. get { return linkAnnotTipText; }
  389. set
  390. {
  391. SetProperty(ref linkAnnotTipText, value);
  392. }
  393. }
  394. #endregion 属性、变量
  395. #region 命令
  396. public DelegateCommand LoadFile { get; set; }
  397. public DelegateCommand Load { get; set; }
  398. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  399. public DelegateCommand SaveFile { get; set; }
  400. public DelegateCommand SaveAsFile { get; set; }
  401. public DelegateCommand SaveAsFlattenCommand { get; set; }
  402. public DelegateCommand UndoCommand { get; set; }
  403. public DelegateCommand RedoCommand { get; set; }
  404. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  405. public DelegateCommand PrintCommand { get; set; }
  406. public DelegateCommand SettingsCommand { get; set; }
  407. public DelegateCommand ShareCommand { get; set; }
  408. public DelegateCommand<object> CreateLinkCommand { get; set; }
  409. public DelegateCommand PropertyCommand { get; set; }
  410. public DelegateCommand ShowInFolderCommand { get; set; }
  411. #endregion 命令
  412. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  413. {
  414. region = regionManager;
  415. dialogs = dialogService;
  416. events = eventAggregator;
  417. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  418. LoadFile = new DelegateCommand(loadFile);
  419. Load = new DelegateCommand(LoadControl);
  420. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  421. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  422. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  423. UndoCommand = new DelegateCommand(Undo);
  424. RedoCommand = new DelegateCommand(Redo);
  425. ShareCommand = new DelegateCommand(share);
  426. PropertyCommand = new DelegateCommand(property);
  427. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  428. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  429. ViwerRegionName = RegionNames.ViwerRegionName;
  430. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  431. BOTARegionName = RegionNames.BOTARegionName;
  432. PropertyRegionName = RegionNames.PropertyRegionName;
  433. BottomToolRegionName = RegionNames.BottomToolRegionName;
  434. ReadModeRegionName = RegionNames.ReadModeRegionName;
  435. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  436. PrintCommand = new DelegateCommand(ShowPrintDialog);
  437. SettingsCommand = new DelegateCommand(SettingsEvent);
  438. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  439. //未显示时无法注册上Region名称
  440. ToolContentVisible = Visibility.Visible;
  441. ToolsBarContentVisible = Visibility.Visible;
  442. OCRContentVisible = Visibility.Visible;
  443. TipVisible = Visibility.Visible;
  444. TipContentRegionName = RegionNames.TipContentRegionName;
  445. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  446. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  447. ToolContentRegionName = Guid.NewGuid().ToString();
  448. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  449. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  450. TextEditContentRegionName = Guid.NewGuid().ToString();
  451. ToolContentVisible = Visibility.Collapsed;
  452. ToolsBarContentVisible = Visibility.Collapsed;
  453. OCRContentVisible = Visibility.Collapsed;
  454. TipVisible = Visibility.Collapsed;
  455. regionNameByTabItem = new Dictionary<string, string>();
  456. barContentByTabItem = new Dictionary<string, string>();
  457. InitialregionNameByTabItem(ref regionNameByTabItem);
  458. InitialbarContentByTabItem(ref barContentByTabItem);
  459. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  460. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  461. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  462. //TODO:根据缓存 选择用户上次选择的菜单
  463. EnterSelectedBar("TabItemAnnotation");
  464. }
  465. /// <summary>
  466. /// 设置Tip状态栏的显示状态
  467. /// </summary>
  468. /// <param name="show">是否显示</param>
  469. public void ShowTip(bool show)
  470. {
  471. if (show)
  472. {
  473. TipVisible = Visibility.Visible;
  474. }
  475. else
  476. {
  477. TipVisible = Visibility.Collapsed;
  478. }
  479. }
  480. /// <summary>
  481. /// 设置LeftTip状态栏的显示状态
  482. /// </summary>
  483. /// <param name="show">是否显示</param>
  484. public void ShowLeftTip(bool show)
  485. {
  486. if (show)
  487. {
  488. LeftTipVisible = Visibility.Visible;
  489. }
  490. else
  491. {
  492. LeftTipVisible = Visibility.Collapsed;
  493. }
  494. }
  495. public void CheckHaveAllPermission()
  496. {
  497. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  498. {
  499. ShowLeftTip(true);
  500. NavigationParameters param = new NavigationParameters();
  501. param.Add(ParameterNames.PDFViewer, PDFViewer);
  502. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  503. }
  504. }
  505. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  506. {
  507. switch (showTipEventArgs.enumTipKind)
  508. {
  509. case EnumTipKind.StatusNone:
  510. ShowLeftTip(false);
  511. break;
  512. case EnumTipKind.StatusSetPasswordSuccessfully:
  513. ShowLeftTip(true);
  514. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  515. break;
  516. default: break;
  517. }
  518. }
  519. /// <summary>
  520. /// 右键菜单创建链接
  521. /// </summary>
  522. /// <param name="obj"></param>
  523. private void CreateLinkEvent(object obj)
  524. {
  525. if (obj is object[] objArry)
  526. {
  527. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  528. {
  529. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  530. linkArgs.URI = string.Empty;
  531. linkArgs.LinkType = LINK_TYPE.GOTO;
  532. linkArgs.PageIndex = annotCommand.PageIndex;
  533. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  534. this.IsRightMenuCreateLink = true;
  535. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  536. lists.Add(linkArgs);
  537. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  538. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  539. PDFViewer.SetToolParam(annotArgs);
  540. this.IsPropertyOpen = true;
  541. }
  542. }
  543. }
  544. /// <summary>
  545. /// 在文件资源管理器中显示
  546. /// </summary>
  547. private void ShowInFolder()
  548. {
  549. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  550. }
  551. private void property()
  552. {
  553. DialogParameters valuePairs = new DialogParameters();
  554. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  555. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  556. }
  557. private void share()
  558. {
  559. try
  560. {
  561. var path = PDFViewer.Document.FilePath;
  562. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  563. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  564. }
  565. catch
  566. {
  567. AlertsMessage alertsMessage = new AlertsMessage();
  568. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  569. }
  570. }
  571. private void SettingsEvent()
  572. {
  573. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  574. }
  575. private bool CanSaveExcute()
  576. {
  577. return CanSave;
  578. }
  579. private void MenuEnterReadModeEvent(object obj)
  580. {
  581. }
  582. public void ShowPrintDialog()
  583. {
  584. DialogParameters printValue = new DialogParameters();
  585. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  586. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  587. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  588. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  589. }
  590. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  591. {
  592. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  593. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  594. //其他工具菜单栏共用一个ToolsBarContentRegionName
  595. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  596. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  597. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  598. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  599. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  600. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  601. }
  602. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  603. {
  604. dictionary.Add("TabItemPageEdit", "PageEditContent");
  605. dictionary.Add("TabItemTool", "ToolsBarContent");
  606. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  607. dictionary.Add("TabItemConvert", "ConverterBarContent");
  608. dictionary.Add("TabItemScan", "ScanContent");
  609. dictionary.Add("TabItemEdit", "TextEditToolContent");
  610. dictionary.Add("TabItemForm", "FormsToolContent");
  611. dictionary.Add("TabItemFill", "FillAndSignContent");
  612. }
  613. private void UpdateShowContent(string currentBar)
  614. {
  615. ToolContentVisible = Visibility.Collapsed;
  616. ToolsBarContentVisible = Visibility.Collapsed;
  617. ConverterBarContentVisible = Visibility.Collapsed;
  618. TextEditToolContentVisible = Visibility.Collapsed;
  619. OCRContentVisible = Visibility.Collapsed;
  620. switch (currentBar)
  621. {
  622. case "TabItemAnnotation":
  623. case "TabItemTool":
  624. case "TabItemForm":
  625. case "TabItemFill":
  626. ToolsBarContentVisible = Visibility.Visible;
  627. break;
  628. case "TabItemScan":
  629. ToolsBarContentVisible = Visibility.Visible;
  630. OCRContentVisible = Visibility.Visible;
  631. break;
  632. case "TabItemEdit":
  633. TextEditToolContentVisible = Visibility.Visible;
  634. break;
  635. case "TabItemConvert":
  636. ConverterBarContentVisible = Visibility.Visible;
  637. break;
  638. case "TabItemPageEdit":
  639. case "HeaderFooterContent":
  640. case "BatesContent":
  641. case "WatermarkContent":
  642. case "BackgroundContent":
  643. case "RedactionContent":
  644. ToolContentVisible = Visibility.Visible;
  645. break;
  646. default:
  647. break;
  648. }
  649. PDFEditMode(currentBar);
  650. FormMode(currentBar);
  651. }
  652. private void PDFEditMode(string currentBar)
  653. {
  654. if (currentBar == "TabItemEdit")
  655. {
  656. if (PDFViewer != null)
  657. {
  658. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  659. //SelectedPrpoertyPanel("TextEditProperty", null);
  660. //IsPropertyOpen = true;
  661. }
  662. }
  663. else
  664. {
  665. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  666. {
  667. IsPropertyOpen = false;
  668. PDFViewer.SetMouseMode(MouseModes.PanTool);
  669. }
  670. }
  671. }
  672. private void FormMode(string currentBar)
  673. {
  674. if (currentBar == "TabItemForm")
  675. {
  676. if (PDFViewer != null)
  677. {
  678. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  679. }
  680. }
  681. else
  682. {
  683. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  684. {
  685. PDFViewer.SetMouseMode(MouseModes.PanTool);
  686. }
  687. }
  688. }
  689. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  690. {
  691. if (!isInPageEdit)
  692. {
  693. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  694. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  695. if (e.PropertyName == "CanUndo")
  696. {
  697. CanUndo = PDFViewer.UndoManager.CanUndo;
  698. }
  699. if (e.PropertyName == "CanRedo")
  700. {
  701. CanRedo = PDFViewer.UndoManager.CanRedo;
  702. }
  703. }
  704. if (e.PropertyName == "CanSave")
  705. {
  706. CanSave = PDFViewer.UndoManager.CanSave;
  707. }
  708. }
  709. /// <summary>
  710. /// 选项卡切换事件
  711. /// </summary>
  712. /// <param name="e"></param>
  713. private void TabControlSelectonChangedEvent(object e)
  714. {
  715. var args = e as SelectionChangedEventArgs;
  716. if (args != null)
  717. {
  718. var item = args.AddedItems[0] as TabItem;
  719. CurrentBar = item.Name;
  720. if (previousBar != CurrentBar)
  721. {
  722. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  723. {
  724. EnterToolMode(barContentByTabItem[CurrentBar]);
  725. isInPageEdit = true;
  726. }
  727. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  728. {
  729. EnterSelectedBar(CurrentBar);
  730. isInPageEdit = false;
  731. }
  732. previousBar = CurrentBar;
  733. }
  734. }
  735. }
  736. /// <summary>
  737. /// 阅读模式
  738. /// </summary>
  739. /// <param name="viewContent"></param>
  740. public async void RbtnReadMode()
  741. {
  742. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  743. App.IsBookMode = true;
  744. IsLoading = Visibility.Visible;
  745. await Task.Delay(1);
  746. NavigationParameters param = new NavigationParameters();
  747. param.Add(ParameterNames.PDFViewer, PDFViewer);
  748. param.Add(ParameterNames.ViewContentViewModel, this);
  749. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  750. //ShowContent(CurrentBar, true);
  751. if (GridToolRow != 0)
  752. {
  753. GridToolRow = 0;
  754. }
  755. if (GridToolRowSpan != 4)
  756. {
  757. GridToolRowSpan = 4;
  758. }
  759. //isInPageEdit = true;
  760. UpdateShowContent("TabItemPageEdit");
  761. IsLoading = Visibility.Collapsed;
  762. }
  763. /// <summary>
  764. /// 退出阅读模式
  765. /// </summary>
  766. public async void UnReadModel()
  767. {
  768. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  769. App.IsBookMode = false;
  770. IsLoading = Visibility.Visible;
  771. await Task.Delay(1);
  772. //PDFViewer.MouseMode = MouseModes.None;
  773. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  774. {
  775. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  776. {
  777. var contentRegion = region.Regions[ViwerRegionName];
  778. contentRegion.Remove(PDFViewer);
  779. }
  780. region.AddToRegion(ViwerRegionName, PDFViewer);
  781. }
  782. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  783. {
  784. EnterSelectedBar("TabItemAnnotation");
  785. }
  786. else
  787. {
  788. EnterSelectedBar(CurrentBar);
  789. }
  790. //isInPageEdit = false;
  791. //ShowContent(CurrentBar, false);
  792. //isInPageEdit = false;
  793. IsLoading = Visibility.Collapsed;
  794. ReadModelTip = Visibility.Visible;
  795. await Task.Delay(3000);
  796. ReadModelTip = Visibility.Collapsed;
  797. }
  798. #region PDFViewer鼠标滚轮缩放事件
  799. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  800. {
  801. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  802. PDFViewer.Zoom(newZoom);
  803. }
  804. public double CheckZoomLevel(double zoom, bool IsGrowth)
  805. {
  806. double standardZoom = 100;
  807. if (zoom <= 0.01)
  808. {
  809. return 0.01;
  810. }
  811. if (zoom >= 10)
  812. {
  813. return 10;
  814. }
  815. zoom *= 100;
  816. for (int i = 0; i < zoomLevel.Length - 1; i++)
  817. {
  818. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  819. {
  820. standardZoom = zoomLevel[i + 1];
  821. break;
  822. }
  823. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  824. {
  825. standardZoom = zoomLevel[i];
  826. break;
  827. }
  828. }
  829. return standardZoom / 100;
  830. }
  831. #endregion PDFViewer鼠标滚轮缩放事件
  832. #region Navigate
  833. public void OnNavigatedTo(NavigationContext navigationContext)
  834. {
  835. if (isOpenFile)
  836. return;
  837. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  838. if (mainVM != null)
  839. {
  840. mainViewModel = mainVM;
  841. mainViewModel.viewContentViewModel = this;
  842. }
  843. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  844. if (pdfview != null)
  845. {
  846. PDFViewer = pdfview;
  847. if (pdfview.Tag != null)
  848. {
  849. //保存密码
  850. PassWord = pdfview.Tag.ToString();
  851. }
  852. loadFile();
  853. CheckHaveAllPermission();
  854. }
  855. isOpenFile = true;
  856. }
  857. public bool IsNavigationTarget(NavigationContext navigationContext)
  858. {
  859. return false;
  860. }
  861. public void OnNavigatedFrom(NavigationContext navigationContext)
  862. {
  863. }
  864. #endregion Navigate
  865. #region 方法
  866. /// <summary>
  867. /// 视图面板 切换分屏模式
  868. /// </summary>
  869. /// <param name="mode"></param>
  870. public void EnterSplitMode(SplitMode mode)
  871. {
  872. ///通知UI层更改布局
  873. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  874. }
  875. private void Undo()
  876. {
  877. if (isInPageEdit)
  878. {
  879. //执行页面编辑的Undo
  880. PageEditUndo?.Invoke();
  881. }
  882. else
  883. {
  884. PDFViewer.UndoManager.Undo();
  885. }
  886. }
  887. private void Redo()
  888. {
  889. if (isInPageEdit)
  890. {
  891. //执行页面编辑的Redo
  892. PageEditRedo?.Invoke();
  893. }
  894. else
  895. {
  896. PDFViewer.UndoManager.Redo();
  897. }
  898. }
  899. private void LoadControl()
  900. {
  901. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  902. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  903. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  904. // {
  905. NavigationParameters parameters = new NavigationParameters();
  906. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  907. parameters.Add(ParameterNames.ViewContentViewModel, this);
  908. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  909. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  910. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  911. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  912. //TODO 根据上一次关闭记录的菜单,选中TabItem
  913. EnterSelectedBar("TabItemAnnotation");
  914. //}
  915. //));
  916. }
  917. /// <summary>
  918. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  919. /// </summary>
  920. /// <param name="Content"></param>
  921. /// <param name="annotPropertyPanel"></param>
  922. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  923. {
  924. NavigationParameters parameters = new NavigationParameters();
  925. //传其他参数:文档类,空注释面板;
  926. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  927. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  928. parameters.Add(ParameterNames.ViewContentViewModel, this);
  929. region.RequestNavigate(PropertyRegionName, Content, parameters);
  930. }
  931. /// <summary>
  932. /// 将PDFViwer添加到Region
  933. /// </summary>
  934. private void loadFile()
  935. {
  936. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  937. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  938. CanSave = PDFViewer.UndoManager.CanSave;
  939. CanUndo = PDFViewer.UndoManager.CanUndo;
  940. CanRedo = PDFViewer.UndoManager.CanRedo;
  941. region.AddToRegion(ViwerRegionName, PDFViewer);
  942. }
  943. /// <summary>
  944. /// 已有路径文档的保存逻辑
  945. /// </summary>
  946. public bool saveFile()
  947. {
  948. try
  949. {
  950. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  951. return saveAsFile();
  952. //文档已被修复时 提示另存为
  953. if (PDFViewer.Document.HasRepaired)
  954. {
  955. AlertsMessage alertsMessage = new AlertsMessage();
  956. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  957. if (alertsMessage.result == ContentResult.Ok)
  958. return saveAsFile();
  959. else
  960. return false;
  961. }
  962. //文件路径无法存在时
  963. if (!File.Exists(PDFViewer.Document.FilePath))
  964. {
  965. AlertsMessage alertsMessage = new AlertsMessage();
  966. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  967. if (alertsMessage.result == ContentResult.Ok)
  968. return saveAsFile();
  969. else
  970. return false;
  971. }
  972. //只读文件无法写入时,提示另存为
  973. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  974. if (fileInfo.IsReadOnly)
  975. {
  976. AlertsMessage alertsMessage = new AlertsMessage();
  977. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  978. if (alertsMessage.result == ContentResult.Ok)
  979. return saveAsFile();
  980. else
  981. return false;
  982. }
  983. if (SecurityInfo.IsPasswordChanged)
  984. {
  985. string currentFilePath = PDFViewer.Document.FilePath;
  986. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  987. string openPassword = null;
  988. string permissionsPassword = null;
  989. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  990. if (SecurityInfo.NeedOpenPassword)
  991. {
  992. openPassword = SecurityInfo.OpenPassword;
  993. }
  994. if (SecurityInfo.NeedPermissionsPassword)
  995. {
  996. permissionsPassword = SecurityInfo.PermissionsPassword;
  997. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  998. }
  999. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1000. AlertsMessage alertsMessage = new AlertsMessage();
  1001. alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
  1002. if (alertsMessage.result == ContentResult.Ok)
  1003. return saveAsFile();
  1004. else
  1005. return false;
  1006. }
  1007. bool result = PDFViewer.Document.WriteToLoadedPath();
  1008. if (result)
  1009. {
  1010. PDFViewer.UndoManager.CanSave = false;
  1011. App.Current.Dispatcher.Invoke(() =>
  1012. {
  1013. //保存时更新缩略图
  1014. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1015. try
  1016. {
  1017. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1018. {
  1019. var size = PDFViewer.Document.GetPageSize(0);
  1020. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1021. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1022. if (File.Exists(folderPath))
  1023. File.Delete(folderPath);
  1024. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1025. if (!folder.Exists)
  1026. folder.Create();
  1027. string imagePath = info.ThumbImgPath;
  1028. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1029. {
  1030. string imageName = Guid.NewGuid().ToString();
  1031. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1032. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1033. {
  1034. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1040. {
  1041. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1042. }
  1043. }
  1044. info.ThumbImgPath = imagePath;
  1045. SettingHelper.SetFileInfo(info);
  1046. }
  1047. }
  1048. catch
  1049. {
  1050. info.ThumbImgPath = null;
  1051. SettingHelper.SetFileInfo(info);
  1052. }
  1053. });
  1054. }
  1055. else
  1056. {
  1057. //文件被占用 保存失败时
  1058. AlertsMessage alertsMessage = new AlertsMessage();
  1059. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1060. if (alertsMessage.result == ContentResult.Ok)
  1061. return saveAsFile();
  1062. else
  1063. return false;
  1064. }
  1065. return result;
  1066. }
  1067. catch { return false; }
  1068. }
  1069. /// <summary>
  1070. /// 另存为或新文档保存逻辑
  1071. /// </summary>
  1072. public bool saveAsFile(Action RedactionAction = null)
  1073. {
  1074. var dlg = new Microsoft.Win32.SaveFileDialog();
  1075. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1076. dlg.FileName = PDFViewer.Document.FileName;
  1077. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1078. {
  1079. bool result = false;
  1080. if (RedactionAction != null)
  1081. {
  1082. //保存前进行标记密文处理应用或擦除
  1083. RedactionAction.Invoke();
  1084. }
  1085. if (App.OpenedFileList.Contains(dlg.FileName))
  1086. {
  1087. //提示文件已经被打开
  1088. }
  1089. else
  1090. {
  1091. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1092. if (result)
  1093. {
  1094. DoAfterSaveAs(dlg.FileName);
  1095. }
  1096. else
  1097. {
  1098. //提示文件被其他软件占用 无法保存
  1099. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1100. }
  1101. ;
  1102. }
  1103. return result;
  1104. }
  1105. else
  1106. return false;
  1107. }
  1108. /// <summary>
  1109. /// 另存为Flatten
  1110. /// </summary>
  1111. private void saveAsFlatten()
  1112. {
  1113. var dlg = new SaveFileDialog();
  1114. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1115. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1116. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1117. {
  1118. saveFile();
  1119. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1120. if (kmdoc == null)
  1121. return;
  1122. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1123. if (result)
  1124. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1125. kmdoc.Release();
  1126. }
  1127. }
  1128. /// <summary>
  1129. /// 另存为后进行的操作
  1130. /// 重新打开新文档
  1131. /// </summary>
  1132. /// <param name="targetPath"></param>
  1133. public void DoAfterSaveAs(string targetPath)
  1134. {
  1135. App.OpenedFileList.Remove(targetPath);
  1136. string oldFilePath = targetPath;
  1137. PDFViewer.UndoManager.CanSave = false;
  1138. mainViewModel.OpenFile(targetPath);
  1139. //TODO:通知各模块更新PDFview对象
  1140. //var result = OpenFile(targetPath, true);
  1141. //if (result)
  1142. //{
  1143. // FileChanged.Invoke(this, null);
  1144. // Zoomer.PdfViewer = PdfViewer;
  1145. // PageSelector.PdfViewer = PdfViewer;
  1146. // ViewModeSelector.PdfViewer = PdfViewer;
  1147. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1148. // if (fileInfo != null)
  1149. // {
  1150. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1151. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1152. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1153. // PdfViewer.Zoom(fileInfo.LastZoom);
  1154. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1155. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1156. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1157. // else
  1158. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1159. // }
  1160. //}
  1161. }
  1162. /// <summary>
  1163. /// 显示前添加内容到Region
  1164. /// </summary>
  1165. /// <param name="isPageEdit"></param>
  1166. private void ShowContent(string currentBar, bool isToolMode = false)
  1167. {
  1168. GridVisibility = Visibility.Visible;
  1169. //显示页面编辑或其他工具
  1170. if (currentBar == "TabItemPageEdit" || isToolMode)
  1171. {
  1172. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1173. {
  1174. if (GridToolRow != 1)
  1175. {
  1176. GridToolRow = 1;
  1177. }
  1178. if (GridToolRowSpan != 3)
  1179. {
  1180. GridToolRowSpan = 3;
  1181. }
  1182. }
  1183. else//进入水印等其他工具模式
  1184. {
  1185. GridVisibility = Visibility.Collapsed;
  1186. if (GridToolRow != 0)
  1187. {
  1188. GridToolRow = 0;
  1189. }
  1190. if (GridToolRowSpan != 4)
  1191. {
  1192. GridToolRowSpan = 4;
  1193. }
  1194. }
  1195. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1196. UpdateShowContent(currentBar);
  1197. }
  1198. else
  1199. {
  1200. if (GridToolRow != 1)
  1201. {
  1202. GridToolRow = 1;
  1203. }
  1204. UpdateShowContent(currentBar);
  1205. }
  1206. }
  1207. /// <summary>
  1208. /// 从二级工具栏进入需要修改界面布局的场景
  1209. /// </summary>
  1210. /// <param name="EditToolName"></param>
  1211. private void EnterEditTools(StringWithUnicode EditToolName)
  1212. {
  1213. EnterSelectedEditTool(EditToolName);
  1214. }
  1215. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1216. {
  1217. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1218. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1219. {
  1220. PDFViewer.Document.ReleasePages();
  1221. PDFViewer.ReloadDocument();
  1222. }
  1223. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1224. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1225. {
  1226. region.AddToRegion(ViwerRegionName, PDFViewer);
  1227. }
  1228. CurrentBar = "TabItemTool";
  1229. EnterSelectedBar(CurrentBar);
  1230. }
  1231. /// <summary>
  1232. /// 二级菜单指定目标处理
  1233. /// </summary>
  1234. /// <param name="e"></param>
  1235. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1236. {
  1237. CurrentBar = EditToolName.EditToolsContentName;
  1238. EnterToolMode(CurrentBar);
  1239. }
  1240. /// <summary>
  1241. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1242. /// </summary>
  1243. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1244. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1245. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1246. {
  1247. IsLoading = Visibility.Visible;
  1248. await Task.Delay(3);
  1249. NavigationParameters param = new NavigationParameters();
  1250. if (valuePairs == null)
  1251. {
  1252. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1253. param.Add(ParameterNames.ViewContentViewModel, this);
  1254. }
  1255. else//有传入其他内容的参数时
  1256. {
  1257. param = valuePairs;
  1258. }
  1259. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1260. ShowContent(CurrentBar, true);
  1261. IsLoading = Visibility.Collapsed;
  1262. }
  1263. private void EnterSelectedBar(string currentBar)
  1264. {
  1265. NavigationParameters param = new NavigationParameters();
  1266. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1267. param.Add(ParameterNames.ViewContentViewModel, this);
  1268. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1269. if (currentBar == "TabItemScan")
  1270. {
  1271. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1272. }
  1273. ShowContent(currentBar);
  1274. }
  1275. /// <summary>
  1276. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1277. /// </summary>
  1278. public void ExitToolMode()
  1279. {
  1280. ToolContentVisible = Visibility.Collapsed;
  1281. if (isInPageEdit)
  1282. {
  1283. TabSelectedIndex = 0;
  1284. isInPageEdit = false;
  1285. }
  1286. }
  1287. #endregion 方法
  1288. }
  1289. }