ViewContentViewModel.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  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. public DelegateCommand CompressCommand { get; set; }
  412. public DelegateCommand MergeFileCommand { get; set; }
  413. public DelegateCommand EncryptCommand { get; set; }
  414. public DelegateCommand DecryptCommand { get; set; }
  415. public DelegateCommand<string> ConvertCommand { get; set; }
  416. #endregion 命令
  417. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  418. {
  419. region = regionManager;
  420. dialogs = dialogService;
  421. events = eventAggregator;
  422. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  423. LoadFile = new DelegateCommand(loadFile);
  424. Load = new DelegateCommand(LoadControl);
  425. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  426. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  427. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  428. UndoCommand = new DelegateCommand(Undo);
  429. RedoCommand = new DelegateCommand(Redo);
  430. ShareCommand = new DelegateCommand(share);
  431. PropertyCommand = new DelegateCommand(property);
  432. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  433. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  434. CompressCommand = new DelegateCommand(compress);
  435. MergeFileCommand = new DelegateCommand(mergeFile);
  436. EncryptCommand = new DelegateCommand(encrypt);
  437. DecryptCommand = new DelegateCommand(decrypt);
  438. ConvertCommand = new DelegateCommand<string>(convert);
  439. ViwerRegionName = RegionNames.ViwerRegionName;
  440. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  441. BOTARegionName = RegionNames.BOTARegionName;
  442. PropertyRegionName = RegionNames.PropertyRegionName;
  443. BottomToolRegionName = RegionNames.BottomToolRegionName;
  444. ReadModeRegionName = RegionNames.ReadModeRegionName;
  445. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  446. PrintCommand = new DelegateCommand(ShowPrintDialog);
  447. SettingsCommand = new DelegateCommand(SettingsEvent);
  448. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  449. //未显示时无法注册上Region名称
  450. ToolContentVisible = Visibility.Visible;
  451. ToolsBarContentVisible = Visibility.Visible;
  452. OCRContentVisible = Visibility.Visible;
  453. TipVisible = Visibility.Visible;
  454. TipContentRegionName = RegionNames.TipContentRegionName;
  455. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  456. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  457. ToolContentRegionName = Guid.NewGuid().ToString();
  458. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  459. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  460. TextEditContentRegionName = Guid.NewGuid().ToString();
  461. ToolContentVisible = Visibility.Collapsed;
  462. ToolsBarContentVisible = Visibility.Collapsed;
  463. OCRContentVisible = Visibility.Collapsed;
  464. TipVisible = Visibility.Collapsed;
  465. regionNameByTabItem = new Dictionary<string, string>();
  466. barContentByTabItem = new Dictionary<string, string>();
  467. InitialregionNameByTabItem(ref regionNameByTabItem);
  468. InitialbarContentByTabItem(ref barContentByTabItem);
  469. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  470. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  471. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  472. //TODO:根据缓存 选择用户上次选择的菜单
  473. EnterSelectedBar("TabItemAnnotation");
  474. }
  475. /// <summary>
  476. /// 转档
  477. /// </summary>
  478. /// <param name="obj"></param>
  479. private void convert(string obj)
  480. {
  481. if(!string.IsNullOrEmpty(obj))
  482. {
  483. switch (obj)
  484. {
  485. default:
  486. break;
  487. }
  488. }
  489. }
  490. /// <summary>
  491. /// 解密
  492. /// </summary>
  493. private void decrypt()
  494. {
  495. }
  496. /// <summary>
  497. /// 加密
  498. /// </summary>
  499. private void encrypt()
  500. {
  501. }
  502. /// <summary>
  503. /// 合并
  504. /// </summary>
  505. private void mergeFile()
  506. {
  507. }
  508. /// <summary>
  509. /// 压缩
  510. /// </summary>
  511. private void compress()
  512. {
  513. }
  514. /// <summary>
  515. /// 设置Tip状态栏的显示状态
  516. /// </summary>
  517. /// <param name="show">是否显示</param>
  518. public void ShowTip(bool show)
  519. {
  520. if (show)
  521. {
  522. TipVisible = Visibility.Visible;
  523. }
  524. else
  525. {
  526. TipVisible = Visibility.Collapsed;
  527. }
  528. }
  529. /// <summary>
  530. /// 设置LeftTip状态栏的显示状态
  531. /// </summary>
  532. /// <param name="show">是否显示</param>
  533. public void ShowLeftTip(bool show)
  534. {
  535. if (show)
  536. {
  537. LeftTipVisible = Visibility.Visible;
  538. }
  539. else
  540. {
  541. LeftTipVisible = Visibility.Collapsed;
  542. }
  543. }
  544. public void CheckHaveAllPermission()
  545. {
  546. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  547. {
  548. ShowLeftTip(true);
  549. NavigationParameters param = new NavigationParameters();
  550. param.Add(ParameterNames.PDFViewer, PDFViewer);
  551. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  552. }
  553. }
  554. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  555. {
  556. switch (showTipEventArgs.enumTipKind)
  557. {
  558. case EnumTipKind.StatusNone:
  559. ShowLeftTip(false);
  560. break;
  561. case EnumTipKind.StatusSetPasswordSuccessfully:
  562. ShowLeftTip(true);
  563. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  564. break;
  565. default: break;
  566. }
  567. }
  568. /// <summary>
  569. /// 右键菜单创建链接
  570. /// </summary>
  571. /// <param name="obj"></param>
  572. private void CreateLinkEvent(object obj)
  573. {
  574. if (obj is object[] objArry)
  575. {
  576. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  577. {
  578. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  579. linkArgs.URI = string.Empty;
  580. linkArgs.LinkType = LINK_TYPE.GOTO;
  581. linkArgs.PageIndex = annotCommand.PageIndex;
  582. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  583. this.IsRightMenuCreateLink = true;
  584. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  585. lists.Add(linkArgs);
  586. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  587. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  588. PDFViewer.SetToolParam(annotArgs);
  589. this.IsPropertyOpen = true;
  590. }
  591. }
  592. }
  593. /// <summary>
  594. /// 在文件资源管理器中显示
  595. /// </summary>
  596. private void ShowInFolder()
  597. {
  598. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  599. }
  600. private void property()
  601. {
  602. DialogParameters valuePairs = new DialogParameters();
  603. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  604. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  605. }
  606. private void share()
  607. {
  608. try
  609. {
  610. var path = PDFViewer.Document.FilePath;
  611. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  612. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  613. }
  614. catch
  615. {
  616. AlertsMessage alertsMessage = new AlertsMessage();
  617. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  618. }
  619. }
  620. private void SettingsEvent()
  621. {
  622. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  623. }
  624. private bool CanSaveExcute()
  625. {
  626. return CanSave;
  627. }
  628. private void MenuEnterReadModeEvent(object obj)
  629. {
  630. }
  631. public void ShowPrintDialog()
  632. {
  633. DialogParameters printValue = new DialogParameters();
  634. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  635. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  636. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  637. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  638. }
  639. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  640. {
  641. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  642. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  643. //其他工具菜单栏共用一个ToolsBarContentRegionName
  644. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  645. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  646. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  647. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  648. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  649. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  650. }
  651. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  652. {
  653. dictionary.Add("TabItemPageEdit", "PageEditContent");
  654. dictionary.Add("TabItemTool", "ToolsBarContent");
  655. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  656. dictionary.Add("TabItemConvert", "ConverterBarContent");
  657. dictionary.Add("TabItemScan", "ScanContent");
  658. dictionary.Add("TabItemEdit", "TextEditToolContent");
  659. dictionary.Add("TabItemForm", "FormsToolContent");
  660. dictionary.Add("TabItemFill", "FillAndSignContent");
  661. }
  662. private void UpdateShowContent(string currentBar)
  663. {
  664. ToolContentVisible = Visibility.Collapsed;
  665. ToolsBarContentVisible = Visibility.Collapsed;
  666. ConverterBarContentVisible = Visibility.Collapsed;
  667. TextEditToolContentVisible = Visibility.Collapsed;
  668. OCRContentVisible = Visibility.Collapsed;
  669. switch (currentBar)
  670. {
  671. case "TabItemAnnotation":
  672. case "TabItemTool":
  673. case "TabItemForm":
  674. case "TabItemFill":
  675. ToolsBarContentVisible = Visibility.Visible;
  676. break;
  677. case "TabItemScan":
  678. ToolsBarContentVisible = Visibility.Visible;
  679. OCRContentVisible = Visibility.Visible;
  680. break;
  681. case "TabItemEdit":
  682. TextEditToolContentVisible = Visibility.Visible;
  683. break;
  684. case "TabItemConvert":
  685. ConverterBarContentVisible = Visibility.Visible;
  686. break;
  687. case "TabItemPageEdit":
  688. case "HeaderFooterContent":
  689. case "BatesContent":
  690. case "WatermarkContent":
  691. case "BackgroundContent":
  692. case "RedactionContent":
  693. ToolContentVisible = Visibility.Visible;
  694. break;
  695. default:
  696. break;
  697. }
  698. PDFEditMode(currentBar);
  699. FormMode(currentBar);
  700. }
  701. private void PDFEditMode(string currentBar)
  702. {
  703. if (currentBar == "TabItemEdit")
  704. {
  705. if (PDFViewer != null)
  706. {
  707. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  708. //SelectedPrpoertyPanel("TextEditProperty", null);
  709. //IsPropertyOpen = true;
  710. }
  711. }
  712. else
  713. {
  714. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  715. {
  716. IsPropertyOpen = false;
  717. PDFViewer.SetMouseMode(MouseModes.PanTool);
  718. }
  719. }
  720. }
  721. private void FormMode(string currentBar)
  722. {
  723. if (currentBar == "TabItemForm")
  724. {
  725. if (PDFViewer != null)
  726. {
  727. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  728. }
  729. }
  730. else
  731. {
  732. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  733. {
  734. PDFViewer.SetMouseMode(MouseModes.PanTool);
  735. }
  736. }
  737. }
  738. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  739. {
  740. if (!isInPageEdit)
  741. {
  742. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  743. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  744. if (e.PropertyName == "CanUndo")
  745. {
  746. CanUndo = PDFViewer.UndoManager.CanUndo;
  747. }
  748. if (e.PropertyName == "CanRedo")
  749. {
  750. CanRedo = PDFViewer.UndoManager.CanRedo;
  751. }
  752. }
  753. if (e.PropertyName == "CanSave")
  754. {
  755. CanSave = PDFViewer.UndoManager.CanSave;
  756. }
  757. }
  758. /// <summary>
  759. /// 选项卡切换事件
  760. /// </summary>
  761. /// <param name="e"></param>
  762. private void TabControlSelectonChangedEvent(object e)
  763. {
  764. var args = e as SelectionChangedEventArgs;
  765. if (args != null)
  766. {
  767. var item = args.AddedItems[0] as TabItem;
  768. CurrentBar = item.Name;
  769. if (previousBar != CurrentBar)
  770. {
  771. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  772. {
  773. EnterToolMode(barContentByTabItem[CurrentBar]);
  774. isInPageEdit = true;
  775. }
  776. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  777. {
  778. EnterSelectedBar(CurrentBar);
  779. isInPageEdit = false;
  780. }
  781. previousBar = CurrentBar;
  782. }
  783. }
  784. }
  785. /// <summary>
  786. /// 阅读模式
  787. /// </summary>
  788. /// <param name="viewContent"></param>
  789. public async void RbtnReadMode()
  790. {
  791. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  792. App.IsBookMode = true;
  793. IsLoading = Visibility.Visible;
  794. await Task.Delay(1);
  795. PDFViewer.SetMouseMode(MouseModes.PanTool);
  796. NavigationParameters param = new NavigationParameters();
  797. param.Add(ParameterNames.PDFViewer, PDFViewer);
  798. param.Add(ParameterNames.ViewContentViewModel, this);
  799. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  800. //ShowContent(CurrentBar, true);
  801. if (GridToolRow != 0)
  802. {
  803. GridToolRow = 0;
  804. }
  805. if (GridToolRowSpan != 4)
  806. {
  807. GridToolRowSpan = 4;
  808. }
  809. //isInPageEdit = true;
  810. UpdateShowContent("TabItemPageEdit");
  811. IsLoading = Visibility.Collapsed;
  812. }
  813. /// <summary>
  814. /// 退出阅读模式
  815. /// </summary>
  816. public async void UnReadModel()
  817. {
  818. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  819. App.IsBookMode = false;
  820. IsLoading = Visibility.Visible;
  821. await Task.Delay(1);
  822. //PDFViewer.MouseMode = MouseModes.None;
  823. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  824. {
  825. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  826. {
  827. var contentRegion = region.Regions[ViwerRegionName];
  828. contentRegion.Remove(PDFViewer);
  829. }
  830. region.AddToRegion(ViwerRegionName, PDFViewer);
  831. }
  832. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  833. {
  834. EnterSelectedBar("TabItemAnnotation");
  835. }
  836. else
  837. {
  838. EnterSelectedBar(CurrentBar);
  839. }
  840. bool isExist = false;
  841. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  842. {
  843. var views = region.Regions[TipContentRegionName].Views;
  844. foreach (var item in views)
  845. {
  846. if (item is Views.TipContent.ReadModelTip readModelTip)
  847. {
  848. isExist = true;
  849. break;
  850. }
  851. }
  852. }
  853. if (isExist == false)
  854. {
  855. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  856. }
  857. IsLoading = Visibility.Collapsed;
  858. //ReadModelTip = Visibility.Visible;
  859. ShowTip(true);
  860. await Task.Delay(3000);
  861. //ReadModelTip = Visibility.Collapsed;
  862. TipVisible = Visibility.Collapsed;
  863. }
  864. #region PDFViewer鼠标滚轮缩放事件
  865. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  866. {
  867. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  868. PDFViewer.Zoom(newZoom);
  869. }
  870. public double CheckZoomLevel(double zoom, bool IsGrowth)
  871. {
  872. double standardZoom = 100;
  873. if (zoom <= 0.01)
  874. {
  875. return 0.01;
  876. }
  877. if (zoom >= 10)
  878. {
  879. return 10;
  880. }
  881. zoom *= 100;
  882. for (int i = 0; i < zoomLevel.Length - 1; i++)
  883. {
  884. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  885. {
  886. standardZoom = zoomLevel[i + 1];
  887. break;
  888. }
  889. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  890. {
  891. standardZoom = zoomLevel[i];
  892. break;
  893. }
  894. }
  895. return standardZoom / 100;
  896. }
  897. #endregion PDFViewer鼠标滚轮缩放事件
  898. #region Navigate
  899. public void OnNavigatedTo(NavigationContext navigationContext)
  900. {
  901. if (isOpenFile)
  902. return;
  903. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  904. if (mainVM != null)
  905. {
  906. mainViewModel = mainVM;
  907. mainViewModel.viewContentViewModel = this;
  908. }
  909. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  910. if (pdfview != null)
  911. {
  912. PDFViewer = pdfview;
  913. if (pdfview.Tag != null)
  914. {
  915. //保存密码
  916. PassWord = pdfview.Tag.ToString();
  917. }
  918. loadFile();
  919. CheckHaveAllPermission();
  920. }
  921. isOpenFile = true;
  922. }
  923. public bool IsNavigationTarget(NavigationContext navigationContext)
  924. {
  925. return false;
  926. }
  927. public void OnNavigatedFrom(NavigationContext navigationContext)
  928. {
  929. }
  930. #endregion Navigate
  931. #region 方法
  932. /// <summary>
  933. /// 视图面板 切换分屏模式
  934. /// </summary>
  935. /// <param name="mode"></param>
  936. public void EnterSplitMode(SplitMode mode)
  937. {
  938. ///通知UI层更改布局
  939. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  940. }
  941. private void Undo()
  942. {
  943. if (isInPageEdit)
  944. {
  945. //执行页面编辑的Undo
  946. PageEditUndo?.Invoke();
  947. }
  948. else
  949. {
  950. PDFViewer.UndoManager.Undo();
  951. }
  952. }
  953. private void Redo()
  954. {
  955. if (isInPageEdit)
  956. {
  957. //执行页面编辑的Redo
  958. PageEditRedo?.Invoke();
  959. }
  960. else
  961. {
  962. PDFViewer.UndoManager.Redo();
  963. }
  964. }
  965. private void LoadControl()
  966. {
  967. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  968. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  969. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  970. // {
  971. NavigationParameters parameters = new NavigationParameters();
  972. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  973. parameters.Add(ParameterNames.ViewContentViewModel, this);
  974. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  975. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  976. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  977. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  978. //TODO 根据上一次关闭记录的菜单,选中TabItem
  979. EnterSelectedBar("TabItemAnnotation");
  980. //}
  981. //));
  982. }
  983. /// <summary>
  984. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  985. /// </summary>
  986. /// <param name="Content"></param>
  987. /// <param name="annotPropertyPanel"></param>
  988. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  989. {
  990. NavigationParameters parameters = new NavigationParameters();
  991. //传其他参数:文档类,空注释面板;
  992. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  993. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  994. parameters.Add(ParameterNames.ViewContentViewModel, this);
  995. region.RequestNavigate(PropertyRegionName, Content, parameters);
  996. }
  997. /// <summary>
  998. /// 将PDFViwer添加到Region
  999. /// </summary>
  1000. private void loadFile()
  1001. {
  1002. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1003. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1004. CanSave = PDFViewer.UndoManager.CanSave;
  1005. CanUndo = PDFViewer.UndoManager.CanUndo;
  1006. CanRedo = PDFViewer.UndoManager.CanRedo;
  1007. region.AddToRegion(ViwerRegionName, PDFViewer);
  1008. }
  1009. /// <summary>
  1010. /// 已有路径文档的保存逻辑
  1011. /// </summary>
  1012. public bool saveFile()
  1013. {
  1014. try
  1015. {
  1016. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  1017. return saveAsFile();
  1018. //文档已被修复时 提示另存为
  1019. if (PDFViewer.Document.HasRepaired)
  1020. {
  1021. AlertsMessage alertsMessage = new AlertsMessage();
  1022. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  1023. if (alertsMessage.result == ContentResult.Ok)
  1024. return saveAsFile();
  1025. else
  1026. return false;
  1027. }
  1028. //文件路径无法存在时
  1029. if (!File.Exists(PDFViewer.Document.FilePath))
  1030. {
  1031. AlertsMessage alertsMessage = new AlertsMessage();
  1032. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  1033. if (alertsMessage.result == ContentResult.Ok)
  1034. return saveAsFile();
  1035. else
  1036. return false;
  1037. }
  1038. //只读文件无法写入时,提示另存为
  1039. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  1040. if (fileInfo.IsReadOnly)
  1041. {
  1042. AlertsMessage alertsMessage = new AlertsMessage();
  1043. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  1044. if (alertsMessage.result == ContentResult.Ok)
  1045. return saveAsFile();
  1046. else
  1047. return false;
  1048. }
  1049. if (SecurityInfo.IsPasswordChanged)
  1050. {
  1051. string currentFilePath = PDFViewer.Document.FilePath;
  1052. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  1053. string openPassword = null;
  1054. string permissionsPassword = null;
  1055. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  1056. if (SecurityInfo.NeedOpenPassword)
  1057. {
  1058. openPassword = SecurityInfo.OpenPassword;
  1059. }
  1060. if (SecurityInfo.NeedPermissionsPassword)
  1061. {
  1062. permissionsPassword = SecurityInfo.PermissionsPassword;
  1063. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  1064. }
  1065. if (false)
  1066. {
  1067. //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1068. AlertsMessage alertsMessage = new AlertsMessage();
  1069. alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
  1070. if (alertsMessage.result == ContentResult.Ok)
  1071. return saveAsFile();
  1072. else
  1073. return false;
  1074. }
  1075. else
  1076. {
  1077. string currentPath = PDFViewer.Document.FilePath;
  1078. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1079. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1080. PDFViewer.Document.WriteToFilePath(tempPath);
  1081. PDFViewer.InitDocument(tempPath);
  1082. //PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1083. //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1084. PDFViewer.Document.WriteToFilePath(currentPath);
  1085. System.IO.File.Delete(tempPath);
  1086. PDFViewer.CloseDocument();
  1087. PDFViewer.InitDocument(currentPath);
  1088. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1089. }
  1090. }
  1091. bool result = PDFViewer.Document.WriteToLoadedPath();
  1092. if (result)
  1093. {
  1094. PDFViewer.UndoManager.CanSave = false;
  1095. App.Current.Dispatcher.Invoke(() =>
  1096. {
  1097. //保存时更新缩略图
  1098. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1099. try
  1100. {
  1101. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1102. {
  1103. var size = PDFViewer.Document.GetPageSize(0);
  1104. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1105. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1106. if (File.Exists(folderPath))
  1107. File.Delete(folderPath);
  1108. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1109. if (!folder.Exists)
  1110. folder.Create();
  1111. string imagePath = info.ThumbImgPath;
  1112. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1113. {
  1114. string imageName = Guid.NewGuid().ToString();
  1115. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1116. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1117. {
  1118. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1119. }
  1120. }
  1121. else
  1122. {
  1123. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1124. {
  1125. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1126. }
  1127. }
  1128. info.ThumbImgPath = imagePath;
  1129. SettingHelper.SetFileInfo(info);
  1130. }
  1131. }
  1132. catch
  1133. {
  1134. info.ThumbImgPath = null;
  1135. SettingHelper.SetFileInfo(info);
  1136. }
  1137. });
  1138. }
  1139. else
  1140. {
  1141. //文件被占用 保存失败时
  1142. AlertsMessage alertsMessage = new AlertsMessage();
  1143. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1144. if (alertsMessage.result == ContentResult.Ok)
  1145. return saveAsFile();
  1146. else
  1147. return false;
  1148. }
  1149. return result;
  1150. }
  1151. catch { return false; }
  1152. }
  1153. /// <summary>
  1154. /// 另存为或新文档保存逻辑
  1155. /// </summary>
  1156. public bool saveAsFile(Action RedactionAction = null)
  1157. {
  1158. var dlg = new Microsoft.Win32.SaveFileDialog();
  1159. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1160. dlg.FileName = PDFViewer.Document.FileName;
  1161. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1162. {
  1163. bool result = false;
  1164. if (RedactionAction != null)
  1165. {
  1166. //保存前进行标记密文处理应用或擦除
  1167. RedactionAction.Invoke();
  1168. }
  1169. if (App.OpenedFileList.Contains(dlg.FileName))
  1170. {
  1171. //提示文件已经被打开
  1172. }
  1173. else
  1174. {
  1175. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1176. if (result)
  1177. {
  1178. DoAfterSaveAs(dlg.FileName);
  1179. }
  1180. else
  1181. {
  1182. //提示文件被其他软件占用 无法保存
  1183. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1184. }
  1185. ;
  1186. }
  1187. return result;
  1188. }
  1189. else
  1190. return false;
  1191. }
  1192. /// <summary>
  1193. /// 另存为Flatten
  1194. /// </summary>
  1195. private void saveAsFlatten()
  1196. {
  1197. var dlg = new SaveFileDialog();
  1198. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1199. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1200. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1201. {
  1202. saveFile();
  1203. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1204. if (kmdoc == null)
  1205. return;
  1206. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1207. if (result)
  1208. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1209. kmdoc.Release();
  1210. }
  1211. }
  1212. /// <summary>
  1213. /// 另存为后进行的操作
  1214. /// 重新打开新文档
  1215. /// </summary>
  1216. /// <param name="targetPath"></param>
  1217. public void DoAfterSaveAs(string targetPath)
  1218. {
  1219. App.OpenedFileList.Remove(targetPath);
  1220. string oldFilePath = targetPath;
  1221. PDFViewer.UndoManager.CanSave = false;
  1222. mainViewModel.OpenFile(targetPath);
  1223. //TODO:通知各模块更新PDFview对象
  1224. //var result = OpenFile(targetPath, true);
  1225. //if (result)
  1226. //{
  1227. // FileChanged.Invoke(this, null);
  1228. // Zoomer.PdfViewer = PdfViewer;
  1229. // PageSelector.PdfViewer = PdfViewer;
  1230. // ViewModeSelector.PdfViewer = PdfViewer;
  1231. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1232. // if (fileInfo != null)
  1233. // {
  1234. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1235. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1236. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1237. // PdfViewer.Zoom(fileInfo.LastZoom);
  1238. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1239. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1240. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1241. // else
  1242. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1243. // }
  1244. //}
  1245. }
  1246. /// <summary>
  1247. /// 显示前添加内容到Region
  1248. /// </summary>
  1249. /// <param name="isPageEdit"></param>
  1250. private void ShowContent(string currentBar, bool isToolMode = false)
  1251. {
  1252. GridVisibility = Visibility.Visible;
  1253. //显示页面编辑或其他工具
  1254. if (currentBar == "TabItemPageEdit" || isToolMode)
  1255. {
  1256. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1257. {
  1258. if (GridToolRow != 1)
  1259. {
  1260. GridToolRow = 1;
  1261. }
  1262. if (GridToolRowSpan != 3)
  1263. {
  1264. GridToolRowSpan = 3;
  1265. }
  1266. }
  1267. else//进入水印等其他工具模式
  1268. {
  1269. GridVisibility = Visibility.Collapsed;
  1270. if (GridToolRow != 0)
  1271. {
  1272. GridToolRow = 0;
  1273. }
  1274. if (GridToolRowSpan != 4)
  1275. {
  1276. GridToolRowSpan = 4;
  1277. }
  1278. }
  1279. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1280. UpdateShowContent(currentBar);
  1281. }
  1282. else
  1283. {
  1284. if (GridToolRow != 1)
  1285. {
  1286. GridToolRow = 1;
  1287. }
  1288. UpdateShowContent(currentBar);
  1289. }
  1290. }
  1291. /// <summary>
  1292. /// 从二级工具栏进入需要修改界面布局的场景
  1293. /// </summary>
  1294. /// <param name="EditToolName"></param>
  1295. private void EnterEditTools(StringWithUnicode EditToolName)
  1296. {
  1297. EnterSelectedEditTool(EditToolName);
  1298. }
  1299. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1300. {
  1301. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1302. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1303. {
  1304. PDFViewer.Document.ReleasePages();
  1305. PDFViewer.ReloadDocument();
  1306. }
  1307. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1308. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1309. {
  1310. region.AddToRegion(ViwerRegionName, PDFViewer);
  1311. }
  1312. CurrentBar = "TabItemTool";
  1313. EnterSelectedBar(CurrentBar);
  1314. }
  1315. /// <summary>
  1316. /// 二级菜单指定目标处理
  1317. /// </summary>
  1318. /// <param name="e"></param>
  1319. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1320. {
  1321. CurrentBar = EditToolName.EditToolsContentName;
  1322. EnterToolMode(CurrentBar);
  1323. }
  1324. /// <summary>
  1325. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1326. /// </summary>
  1327. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1328. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1329. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1330. {
  1331. IsLoading = Visibility.Visible;
  1332. await Task.Delay(3);
  1333. NavigationParameters param = new NavigationParameters();
  1334. if (valuePairs == null)
  1335. {
  1336. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1337. param.Add(ParameterNames.ViewContentViewModel, this);
  1338. }
  1339. else//有传入其他内容的参数时
  1340. {
  1341. param = valuePairs;
  1342. }
  1343. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1344. ShowContent(CurrentBar, true);
  1345. IsLoading = Visibility.Collapsed;
  1346. }
  1347. private void EnterSelectedBar(string currentBar)
  1348. {
  1349. NavigationParameters param = new NavigationParameters();
  1350. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1351. param.Add(ParameterNames.ViewContentViewModel, this);
  1352. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1353. if (currentBar == "TabItemScan")
  1354. {
  1355. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1356. }
  1357. ShowContent(currentBar);
  1358. }
  1359. /// <summary>
  1360. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1361. /// </summary>
  1362. public void ExitToolMode()
  1363. {
  1364. ToolContentVisible = Visibility.Collapsed;
  1365. if (isInPageEdit)
  1366. {
  1367. TabSelectedIndex = 0;
  1368. isInPageEdit = false;
  1369. }
  1370. }
  1371. #endregion 方法
  1372. }
  1373. }