ViewContentViewModel.cs 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253
  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. using PDF_Office.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Office.Model.Dialog.ConverterDialogs;
  27. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Office.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  34. using ImTools;
  35. using PDF_Office.Properties;
  36. namespace PDF_Office.ViewModels
  37. {
  38. public class ViewContentViewModel : BindableBase, INavigationAware
  39. {
  40. #region 文案
  41. private string T_file;
  42. public string T_File
  43. {
  44. get { return T_file; }
  45. set
  46. {
  47. SetProperty(ref T_file, value);
  48. }
  49. }
  50. private string T_save;
  51. public string T_Save
  52. {
  53. get { return T_save; }
  54. set
  55. {
  56. SetProperty(ref T_save, value);
  57. }
  58. }
  59. private string T_undo;
  60. public string T_Undo
  61. {
  62. get { return T_undo; }
  63. set
  64. {
  65. SetProperty(ref T_undo, value);
  66. }
  67. }
  68. private string T_redo;
  69. public string T_Redo
  70. {
  71. get { return T_redo; }
  72. set
  73. {
  74. SetProperty(ref T_redo, value);
  75. }
  76. }
  77. private string T_annotation;
  78. public string T_Annotation
  79. {
  80. get { return T_annotation; }
  81. set
  82. {
  83. SetProperty(ref T_annotation, value);
  84. }
  85. }
  86. private string T_pageEdit;
  87. public string T_PageEdit
  88. {
  89. get { return T_pageEdit; }
  90. set
  91. {
  92. SetProperty(ref T_pageEdit, value);
  93. }
  94. }
  95. private string T_converter;
  96. public string T_Converter
  97. {
  98. get { return T_converter; }
  99. set
  100. {
  101. SetProperty(ref T_converter, value);
  102. }
  103. }
  104. private string T_fillSign;
  105. public string T_FillSign
  106. {
  107. get { return T_fillSign; }
  108. set
  109. {
  110. SetProperty(ref T_fillSign, value);
  111. }
  112. }
  113. private string T_tools;
  114. public string T_Tools
  115. {
  116. get { return T_tools; }
  117. set
  118. {
  119. SetProperty(ref T_tools, value);
  120. }
  121. }
  122. private string T_print;
  123. public string T_Print
  124. {
  125. get { return T_print; }
  126. set
  127. {
  128. SetProperty(ref T_print, value);
  129. }
  130. }
  131. private string T_share;
  132. public string T_Share
  133. {
  134. get { return T_share; }
  135. set
  136. {
  137. SetProperty(ref T_share, value);
  138. }
  139. }
  140. private string T_properties;
  141. public string T_Properties
  142. {
  143. get { return T_properties; }
  144. set
  145. {
  146. SetProperty(ref T_properties, value);
  147. }
  148. }
  149. private void InitStirng()
  150. {
  151. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  152. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  153. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  154. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  155. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  156. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  157. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  158. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  159. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  160. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  161. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  162. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  163. }
  164. #endregion 文案
  165. #region 属性、变量
  166. public OpenFileInfo OpenFileInfo = null;
  167. public CPDFViewer PDFViewer { get; set; }
  168. public MainContentViewModel mainViewModel { get; set; }
  169. public IRegionManager region;
  170. public IDialogService dialogs;
  171. public IEventAggregator events;
  172. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  173. public string ViwerRegionName { get; set; }
  174. /// <summary>
  175. /// 分屏视图的region名称
  176. /// </summary>
  177. public string SplitViewerRegionName { get; set; }
  178. /// <summary>
  179. /// OCR视图名称
  180. /// </summary>
  181. public string OCRViewerRegionName { get; set; }
  182. public string BOTARegionName { get; set; }
  183. public string PropertyRegionName { get; set; }
  184. public string ToolContentRegionName { get; set; }
  185. public string ToolsBarContentRegionName { get; set; }
  186. /// <summary>
  187. /// 顶部提示的Content
  188. /// </summary>
  189. public string TipContentRegionName { get; set; }
  190. public string LeftTipContentRegionName { get; set; }
  191. //便签弹窗
  192. public string NotePopupRegionName { get; set; }
  193. public string ReadModeRegionName { get; set; }
  194. public string ConverterBarContentRegionName { get; set; }
  195. public string TextEditContentRegionName { get; set; }
  196. public string BackgroundContentRegionName { get; set; }
  197. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  198. public List<Tuple<int,int>> FillAndSign = new List<Tuple<int, int>>();
  199. /// <summary>
  200. /// 文档的密码
  201. /// </summary>
  202. public string PassWord { get; set; }
  203. private Visibility tipVisible = Visibility.Collapsed;
  204. /// <summary>
  205. /// 顶部提示栏的显示状态
  206. /// </summary>
  207. public Visibility TipVisible
  208. {
  209. get { return tipVisible; }
  210. set
  211. {
  212. SetProperty(ref tipVisible, value);
  213. }
  214. }
  215. private Visibility leftTipVisible = Visibility.Collapsed;
  216. public Visibility LeftTipVisible
  217. {
  218. get { return leftTipVisible; }
  219. set
  220. {
  221. SetProperty(ref leftTipVisible, value);
  222. }
  223. }
  224. private Visibility notePopupVisible = Visibility.Collapsed;
  225. public Visibility NotePopupVisible
  226. {
  227. get { return notePopupVisible; }
  228. set
  229. {
  230. SetProperty(ref notePopupVisible, value);
  231. }
  232. }
  233. public bool IsNoteAdd = false;
  234. private double canvasNoteLeft;
  235. public double CanvasNoteLeft
  236. {
  237. get { return canvasNoteLeft; }
  238. set
  239. {
  240. SetProperty(ref canvasNoteLeft, value);
  241. }
  242. }
  243. private double canvasNoteBottom;
  244. public double CanvasNoteBottom
  245. {
  246. get { return canvasNoteBottom; }
  247. set
  248. {
  249. SetProperty(ref canvasNoteBottom, value);
  250. }
  251. }
  252. /// <summary>
  253. /// 底部工具栏 RegionName
  254. /// </summary>
  255. public string BottomToolRegionName { get; set; }
  256. private bool _isInPageEdit = false;
  257. /// <summary>
  258. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  259. /// </summary>
  260. public bool isInPageEdit
  261. {
  262. get { return _isInPageEdit; }
  263. set
  264. {
  265. SetProperty(ref _isInPageEdit, value);
  266. if (!value)
  267. {
  268. CanRedo = PDFViewer.UndoManager.CanRedo;
  269. CanUndo = PDFViewer.UndoManager.CanUndo;
  270. }
  271. }
  272. }
  273. public Action PageEditUndo { get; set; }
  274. public Action PageEditRedo { get; set; }
  275. /// <summary>
  276. ///工具条
  277. ///0:收起
  278. ///40:显示
  279. /// </summary>
  280. private int toolRowHeight = 40;
  281. public int ToolRowHeight
  282. {
  283. get { return toolRowHeight; }
  284. set
  285. {
  286. SetProperty(ref toolRowHeight, value);
  287. }
  288. }
  289. /// <summary>
  290. /// 水印,背景侧边栏宽度
  291. /// 0:收起
  292. /// 260:显示
  293. /// </summary>
  294. private int propertyColumnWidth = 0;
  295. public int PropertyColumnWidth
  296. {
  297. get { return propertyColumnWidth; }
  298. set
  299. {
  300. SetProperty(ref propertyColumnWidth, value);
  301. }
  302. }
  303. private int gridToolRow = 1;
  304. /// <summary>
  305. /// 控制ToolContent的Row
  306. /// </summary>
  307. public int GridToolRow
  308. {
  309. get { return gridToolRow; }
  310. set
  311. {
  312. SetProperty(ref gridToolRow, value);
  313. }
  314. }
  315. private int gridToolRowSpan = 3;
  316. /// <summary>
  317. /// 控制ToolContent的RowSpan
  318. /// </summary>
  319. public int GridToolRowSpan
  320. {
  321. get { return gridToolRowSpan; }
  322. set
  323. {
  324. SetProperty(ref gridToolRowSpan, value);
  325. }
  326. }
  327. private Visibility toolContentVisible = Visibility.Collapsed;
  328. /// <summary>
  329. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  330. /// 留意:显示前需要先注入内容、设置好行和跨行数
  331. /// </summary>
  332. public Visibility ToolContentVisible
  333. {
  334. get { return toolContentVisible; }
  335. set
  336. {
  337. SetProperty(ref toolContentVisible, value);
  338. }
  339. }
  340. private Visibility gridVisibility = Visibility.Visible;
  341. /// <summary>
  342. /// 是否正在加载中
  343. /// </summary>
  344. public Visibility GridVisibility
  345. {
  346. get { return gridVisibility; }
  347. set
  348. {
  349. SetProperty(ref gridVisibility, value);
  350. }
  351. }
  352. private Visibility isLoading = Visibility.Collapsed;
  353. private Visibility ocrContentVisible = Visibility.Collapsed;
  354. public Visibility OCRContentVisible
  355. {
  356. get { return ocrContentVisible; }
  357. set
  358. {
  359. SetProperty(ref ocrContentVisible, value);
  360. }
  361. }
  362. /// <summary>
  363. /// 是否正在加载中
  364. /// </summary>
  365. public Visibility IsLoading
  366. {
  367. get { return isLoading; }
  368. set
  369. {
  370. SetProperty(ref isLoading, value);
  371. }
  372. }
  373. private Visibility converterBarContentVisible = Visibility.Collapsed;
  374. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  375. /// <summary>
  376. /// 控制ToolsBarContent的显示
  377. /// 留意:显示前需要先注入内容、设置好行和跨行数
  378. /// </summary>
  379. public Visibility ConverterBarContentVisible
  380. {
  381. get { return converterBarContentVisible; }
  382. set
  383. {
  384. SetProperty(ref converterBarContentVisible, value);
  385. }
  386. }
  387. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  388. /// <summary>
  389. /// 控制ToolsBarContent的显示
  390. /// 留意:显示前需要先注入内容、设置好行和跨行数
  391. /// </summary>
  392. public Visibility ToolsBarContentVisible
  393. {
  394. get { return toolsBarContentVisible; }
  395. set
  396. {
  397. SetProperty(ref toolsBarContentVisible, value);
  398. }
  399. }
  400. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  401. /// <summary>
  402. /// 控制ToolsBarContent的显示
  403. /// 留意:显示前需要先注入内容、设置好行和跨行数
  404. /// </summary>
  405. public Visibility TextEditToolContentVisible
  406. {
  407. get { return textEditToolContentVisible; }
  408. set
  409. {
  410. SetProperty(ref textEditToolContentVisible, value);
  411. }
  412. }
  413. private bool isPorpertyOpen = false;
  414. /// <summary>
  415. /// 属性栏是否展开
  416. /// </summary>
  417. public bool IsPropertyOpen
  418. {
  419. get { return isPorpertyOpen; }
  420. set
  421. {
  422. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  423. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
  424. {
  425. SetProperty(ref isPorpertyOpen, value);
  426. }
  427. }
  428. }
  429. private Visibility isReadMode = Visibility.Visible;
  430. /// <summary>
  431. ///是否为阅读模式
  432. /// </summary>
  433. public Visibility IsReadMode
  434. {
  435. get { return isReadMode; }
  436. set
  437. {
  438. SetProperty(ref isReadMode, value);
  439. }
  440. }
  441. private bool canSave;
  442. /// <summary>
  443. /// 是否可以保存
  444. /// </summary>
  445. public bool CanSave
  446. {
  447. get { return canSave; }
  448. set
  449. {
  450. if (events != null && canSave == false)
  451. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Unicode = "Clear", AppUnicode = unicode });
  452. SetProperty(ref canSave, value);
  453. }
  454. }
  455. private bool canUndo;
  456. /// <summary>
  457. /// 是否可以进行Undo
  458. /// </summary>
  459. public bool CanUndo
  460. {
  461. get { return canUndo; }
  462. set
  463. {
  464. SetProperty(ref canUndo, value);
  465. }
  466. }
  467. private bool canRedo;
  468. /// <summary>
  469. /// 是否可以进行Redo
  470. /// </summary>
  471. public bool CanRedo
  472. {
  473. get { return canRedo; }
  474. set
  475. {
  476. SetProperty(ref canRedo, value);
  477. }
  478. }
  479. private GridLength botaWidth = new GridLength(48);
  480. /// <summary>
  481. /// BOTA栏的宽度
  482. /// </summary>
  483. public GridLength BOTAWidth
  484. {
  485. get { return botaWidth; }
  486. set
  487. {
  488. SetProperty(ref botaWidth, value);
  489. if (botaWidth.Value <= 48)
  490. {
  491. OpenBOTA = false;
  492. }
  493. }
  494. }
  495. private int selectedIndex;
  496. /// <summary>
  497. /// 工具栏选中项的索引
  498. /// </summary>
  499. public int TabSelectedIndex
  500. {
  501. get { return selectedIndex; }
  502. set
  503. {
  504. SetProperty(ref selectedIndex, value);
  505. }
  506. }
  507. private bool openBOTA = false;
  508. /// <summary>
  509. /// 是否展开BOTA
  510. /// </summary>
  511. public bool OpenBOTA
  512. {
  513. get { return openBOTA; }
  514. set
  515. {
  516. SetProperty(ref openBOTA, value);
  517. if (openBOTA && BOTAWidth.Value <= 48)
  518. {
  519. BOTAWidth = new GridLength(260);
  520. }
  521. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  522. }
  523. }
  524. public SecurityInfo SecurityInfo = new SecurityInfo();
  525. private Dictionary<string, string> regionNameByTabItem;
  526. private Dictionary<string, string> barContentByTabItem;
  527. private string previousBar = "";
  528. public string CurrentBar = "";
  529. public string unicode = null;
  530. /// <summary>
  531. /// 用来避免重复触发导航事件的标志符
  532. /// </summary>
  533. private bool isOpenFile = false;
  534. /// <summary>
  535. /// 鼠标滚轮缩放的缩放值
  536. /// </summary>
  537. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  538. /// <summary>
  539. /// 注释-链接,提示语
  540. /// </summary>
  541. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  542. public Visibility LinkAnnotTipVisibility
  543. {
  544. get { return linkAnnotTipVisibility; }
  545. set
  546. {
  547. SetProperty(ref linkAnnotTipVisibility, value);
  548. }
  549. }
  550. 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";
  551. private bool isCreateLink = false;
  552. public string LinkAnnotTipText
  553. {
  554. get { return linkAnnotTipText; }
  555. set
  556. {
  557. SetProperty(ref linkAnnotTipText, value);
  558. }
  559. }
  560. #endregion 属性、变量
  561. #region 命令
  562. public DelegateCommand LoadFile { get; set; }
  563. public DelegateCommand Load { get; set; }
  564. public DelegateCommand MouseDown { get; set; }
  565. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  566. public DelegateCommand SaveFile { get; set; }
  567. public DelegateCommand SaveAsFile { get; set; }
  568. public DelegateCommand SaveAsFlattenCommand { get; set; }
  569. public DelegateCommand UndoCommand { get; set; }
  570. public DelegateCommand RedoCommand { get; set; }
  571. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  572. public DelegateCommand PrintCommand { get; set; }
  573. public DelegateCommand SettingsCommand { get; set; }
  574. public DelegateCommand ShareCommand { get; set; }
  575. public DelegateCommand<object> CreateLinkCommand { get; set; }
  576. public DelegateCommand PropertyCommand { get; set; }
  577. public DelegateCommand ShowInFolderCommand { get; set; }
  578. public DelegateCommand CompressCommand { get; set; }
  579. public DelegateCommand MergeFileCommand { get; set; }
  580. public DelegateCommand EncryptCommand { get; set; }
  581. public DelegateCommand DecryptCommand { get; set; }
  582. public DelegateCommand<string> ConvertCommand { get; set; }
  583. public DelegateCommand CloseWindowCommand { get; set; }
  584. public DelegateCommand OpenFileCommand { get; set; }
  585. public DelegateCommand<string> HelpCommand { get; set; }
  586. public DelegateCommand CreateBlankFileCommand { get; set; }
  587. public DelegateCommand ClosePropertyCommand { get; set; }
  588. #endregion 命令
  589. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  590. {
  591. InitStirng();
  592. region = regionManager;
  593. dialogs = dialogService;
  594. events = eventAggregator;
  595. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  596. LoadFile = new DelegateCommand(loadFile);
  597. Load = new DelegateCommand(LoadControl);
  598. MouseDown = new DelegateCommand(MouseDownEvent);
  599. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  600. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  601. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  602. UndoCommand = new DelegateCommand(Undo);
  603. RedoCommand = new DelegateCommand(Redo);
  604. ShareCommand = new DelegateCommand(share);
  605. PropertyCommand = new DelegateCommand(property);
  606. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  607. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  608. CompressCommand = new DelegateCommand(compress);
  609. MergeFileCommand = new DelegateCommand(mergeFile);
  610. EncryptCommand = new DelegateCommand(encrypt);
  611. DecryptCommand = new DelegateCommand(decrypt);
  612. ConvertCommand = new DelegateCommand<string>(convert);
  613. CloseWindowCommand = new DelegateCommand(closeWindow);
  614. OpenFileCommand = new DelegateCommand(openfile);
  615. HelpCommand = new DelegateCommand<string>(help);
  616. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  617. ViwerRegionName = RegionNames.ViwerRegionName;
  618. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  619. BOTARegionName = RegionNames.BOTARegionName;
  620. PropertyRegionName = RegionNames.PropertyRegionName;
  621. BottomToolRegionName = RegionNames.BottomToolRegionName;
  622. ReadModeRegionName = RegionNames.ReadModeRegionName;
  623. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  624. PrintCommand = new DelegateCommand(ShowPrintDialog);
  625. SettingsCommand = new DelegateCommand(SettingsEvent);
  626. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  627. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  628. //未显示时无法注册上Region名称
  629. ToolContentVisible = Visibility.Visible;
  630. ToolsBarContentVisible = Visibility.Visible;
  631. OCRContentVisible = Visibility.Visible;
  632. TipVisible = Visibility.Visible;
  633. TipContentRegionName = RegionNames.TipContentRegionName;
  634. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  635. NotePopupRegionName = RegionNames.NotePopupRegionName;
  636. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  637. ToolContentRegionName = Guid.NewGuid().ToString();
  638. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  639. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  640. TextEditContentRegionName = Guid.NewGuid().ToString();
  641. ToolContentVisible = Visibility.Collapsed;
  642. ToolsBarContentVisible = Visibility.Collapsed;
  643. OCRContentVisible = Visibility.Collapsed;
  644. TipVisible = Visibility.Collapsed;
  645. regionNameByTabItem = new Dictionary<string, string>();
  646. barContentByTabItem = new Dictionary<string, string>();
  647. InitialregionNameByTabItem(ref regionNameByTabItem);
  648. InitialbarContentByTabItem(ref barContentByTabItem);
  649. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  650. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  651. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
  652. //TODO:根据缓存 选择用户上次选择的菜单
  653. EnterSelectedBar("TabItemAnnotation");
  654. }
  655. private void MouseDownEvent()
  656. {
  657. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  658. {
  659. NotePopupVisible = Visibility.Collapsed;
  660. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  661. {
  662. var views = region.Regions[NotePopupRegionName].Views;
  663. foreach (var item in views)
  664. {
  665. if (item is StickyNotePopup sticky)
  666. {
  667. var contentRegion = region.Regions[NotePopupRegionName];
  668. contentRegion.Remove(sticky);
  669. break;
  670. }
  671. }
  672. }
  673. }
  674. }
  675. /// <summary>
  676. ///创建空白文档
  677. /// </summary>
  678. private async void createBlankFile()
  679. {
  680. App.mainWindowViewModel.AddTab.Execute();
  681. await Task.Delay(30);
  682. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  683. }
  684. private void help(string args)
  685. {
  686. string url = "";
  687. switch (args)
  688. {
  689. case "Guid":
  690. //打开内嵌文档
  691. if (File.Exists(App.GuidPDFPath))
  692. {
  693. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  694. }
  695. break;
  696. case "Online":
  697. url = @"https://www.pdfreaderpro.com/windows/help";
  698. break;
  699. case "More":
  700. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  701. break;
  702. case "Template":
  703. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  704. break;
  705. case "Blog":
  706. //TODO:显示订阅电子报弹窗
  707. break;
  708. case "ComPDF":
  709. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  710. break;
  711. case "FeedBack":
  712. //调用邮箱 发送邮件
  713. StringBuilder sr = new StringBuilder();
  714. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  715. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  716. break;
  717. default:
  718. break;
  719. }
  720. if (!string.IsNullOrEmpty(url))
  721. {
  722. //需要跳转网页的情况
  723. System.Diagnostics.Process.Start(url);
  724. }
  725. }
  726. /// <summary>
  727. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  728. /// </summary>
  729. private void openfile()
  730. {
  731. OpenFileDialog openFileDialog = new OpenFileDialog();
  732. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  733. openFileDialog.Multiselect = true;
  734. if ((bool)openFileDialog.ShowDialog())
  735. {
  736. if (openFileDialog.FileNames.Count() == 1)
  737. {
  738. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  739. {
  740. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  741. }
  742. else
  743. {
  744. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  745. }
  746. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  747. }
  748. else
  749. {
  750. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  751. if (fileList.Count <= 0)
  752. {
  753. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  754. return;
  755. }
  756. mainViewModel.OpenFile(fileList[0]);
  757. for (int i = 1; i < fileList.Count(); i++)
  758. {
  759. if (!App.OpenedFileList.Contains(fileList[i]))
  760. {
  761. App.mainWindowViewModel.AddTabItem(fileList[i]);
  762. }
  763. ToolMethod.SetFileThumbImg(fileList[i]);
  764. }
  765. }
  766. }
  767. }
  768. /// <summary>
  769. /// 关闭当前窗体
  770. /// </summary>
  771. private void closeWindow()
  772. {
  773. App.Current.MainWindow.Close();
  774. }
  775. /// <summary>
  776. /// 转档
  777. /// </summary>
  778. /// <param name="obj"></param>
  779. private void convert(string obj)
  780. {
  781. if (!string.IsNullOrEmpty(obj))
  782. {
  783. DialogParameters value = new DialogParameters();
  784. value.Add(ParameterNames.PDFViewer, PDFViewer);
  785. switch (obj)
  786. {
  787. case "Word":
  788. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  789. {
  790. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  791. converterDialogsModel.OnOpened((DialogResult)e);
  792. });
  793. break;
  794. case "Excel":
  795. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  796. {
  797. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  798. converterDialogsModel.OnOpened((DialogResult)e);
  799. });
  800. break;
  801. case "PPT":
  802. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  803. {
  804. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  805. converterDialogsModel.OnOpened((DialogResult)e);
  806. });
  807. break;
  808. case "RTF":
  809. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  810. {
  811. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  812. converterDialogsModel.OnOpened((DialogResult)e);
  813. });
  814. break;
  815. case "CSV":
  816. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  817. {
  818. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  819. converterDialogsModel.OnOpened((DialogResult)e);
  820. });
  821. break;
  822. case "HTML":
  823. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  824. {
  825. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  826. converterDialogsModel.OnOpened((DialogResult)e);
  827. });
  828. break;
  829. case "Text":
  830. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  831. {
  832. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  833. converterDialogsModel.OnOpened((DialogResult)e);
  834. });
  835. break;
  836. case "Image":
  837. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  838. {
  839. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  840. converterDialogsModel.OnOpened((DialogResult)e);
  841. });
  842. break;
  843. default:
  844. break;
  845. }
  846. }
  847. }
  848. /// <summary>
  849. /// 解密
  850. /// </summary>
  851. private void decrypt()
  852. {
  853. if (!PDFViewer.Document.IsEncrypted)
  854. {
  855. MessageBoxEx.Show("No security settings available ");
  856. }
  857. else
  858. {
  859. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  860. if (result.IsDiscryptied)
  861. {
  862. if (result.Password != null)
  863. {
  864. string filePath = PDFViewer.Document.FilePath;
  865. PDFViewer.Document.Release();
  866. PDFViewer.InitDocument(filePath);
  867. PDFViewer.Document.UnlockWithPassword(result.Password);
  868. }
  869. DialogParameters value = new DialogParameters();
  870. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  871. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  872. }
  873. }
  874. }
  875. /// <summary>
  876. /// 加密
  877. /// </summary>
  878. private void encrypt()
  879. {
  880. if (!this.SecurityInfo.IsPasswordChanged)
  881. {
  882. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  883. if (result.IsDiscryptied)
  884. {
  885. if (result.Password != null)
  886. {
  887. string filePath = PDFViewer.Document.FilePath;
  888. PDFViewer.Document.Release();
  889. PDFViewer.InitDocument(filePath);
  890. PDFViewer.Document.UnlockWithPassword(result.Password);
  891. }
  892. }
  893. }
  894. DialogParameters value = new DialogParameters();
  895. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  896. value.Add(ParameterNames.ViewContentViewModel, this);
  897. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  898. {
  899. if (e.Result == ButtonResult.OK)
  900. {
  901. SecurityHelper.IsPasswordChanged = true;
  902. if (this.SecurityInfo.IsPasswordChanged)
  903. {
  904. this.PDFViewer.UndoManager.CanSave = true;
  905. }
  906. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  907. }
  908. });
  909. }
  910. /// <summary>
  911. /// 合并
  912. /// </summary>
  913. private void mergeFile()
  914. {
  915. DialogParameters value = new DialogParameters();
  916. value.Add(ParameterNames.PDFViewer, PDFViewer);
  917. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  918. }
  919. /// <summary>
  920. /// 压缩
  921. /// </summary>
  922. private void compress()
  923. {
  924. DialogParameters value = new DialogParameters();
  925. value.Add(ParameterNames.PDFViewer, PDFViewer);
  926. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  927. {
  928. CompressDialogModel compressDialogModel = new CompressDialogModel();
  929. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  930. });
  931. }
  932. /// <summary>
  933. /// 设置Tip状态栏的显示状态
  934. /// </summary>
  935. /// <param name="show">是否显示</param>
  936. public void ShowTip(bool show)
  937. {
  938. if (show)
  939. {
  940. TipVisible = Visibility.Visible;
  941. }
  942. else
  943. {
  944. TipVisible = Visibility.Collapsed;
  945. }
  946. }
  947. /// <summary>
  948. /// 设置LeftTip状态栏的显示状态
  949. /// </summary>
  950. /// <param name="show">是否显示</param>
  951. public void ShowLeftTip(bool show)
  952. {
  953. if (show)
  954. {
  955. LeftTipVisible = Visibility.Visible;
  956. }
  957. else
  958. {
  959. LeftTipVisible = Visibility.Collapsed;
  960. }
  961. }
  962. public void CheckHaveAllPermission()
  963. {
  964. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  965. {
  966. ShowLeftTip(true);
  967. NavigationParameters param = new NavigationParameters();
  968. param.Add(ParameterNames.PDFViewer, PDFViewer);
  969. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  970. }
  971. }
  972. public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)
  973. {
  974. switch (showTipEventArgs.enumTipKind)
  975. {
  976. case EnumTipKind.StatusNone:
  977. ShowLeftTip(false);
  978. break;
  979. case EnumTipKind.StatusSetPasswordSuccessfully:
  980. ShowLeftTip(true);
  981. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  982. break;
  983. default: break;
  984. }
  985. }
  986. /// <summary>
  987. /// 右键菜单创建链接
  988. /// </summary>
  989. /// <param name="obj"></param>
  990. private void CreateLinkEvent(object obj)
  991. {
  992. if (obj is object[] objArry)
  993. {
  994. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  995. {
  996. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  997. linkArgs.URI = string.Empty;
  998. linkArgs.LinkType = LINK_TYPE.GOTO;
  999. linkArgs.PageIndex = annotCommand.PageIndex;
  1000. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1001. this.IsRightMenuCreateLink = true;
  1002. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1003. lists.Add(linkArgs);
  1004. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1005. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1006. PDFViewer.SetToolParam(annotArgs);
  1007. this.IsPropertyOpen = true;
  1008. }
  1009. }
  1010. }
  1011. private void CloseProperty()
  1012. {
  1013. IsPropertyOpen = false;
  1014. }
  1015. /// <summary>
  1016. /// 在文件资源管理器中显示
  1017. /// </summary>
  1018. private void ShowInFolder()
  1019. {
  1020. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1021. }
  1022. private void property()
  1023. {
  1024. DialogParameters valuePairs = new DialogParameters();
  1025. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1026. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1027. }
  1028. private void share()
  1029. {
  1030. try
  1031. {
  1032. var path = PDFViewer.Document.FilePath;
  1033. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  1034. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1035. }
  1036. catch
  1037. {
  1038. AlertsMessage alertsMessage = new AlertsMessage();
  1039. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  1040. }
  1041. }
  1042. private void SettingsEvent()
  1043. {
  1044. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  1045. if(PDFViewer!=null)
  1046. {
  1047. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1048. }
  1049. }
  1050. private bool CanSaveExcute()
  1051. {
  1052. return CanSave;
  1053. }
  1054. private void MenuEnterReadModeEvent(object obj)
  1055. {
  1056. }
  1057. public void ShowPrintDialog()
  1058. {
  1059. DialogParameters printValue = new DialogParameters();
  1060. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1061. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1062. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1063. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1064. }
  1065. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1066. {
  1067. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1068. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1069. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1070. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1071. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  1072. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1073. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1074. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1075. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1076. }
  1077. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1078. {
  1079. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1080. dictionary.Add("TabItemTool", "ToolsBarContent");
  1081. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1082. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1083. dictionary.Add("TabItemScan", "ScanContent");
  1084. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1085. dictionary.Add("TabItemForm", "FormsToolContent");
  1086. dictionary.Add("TabItemFill", "FillAndSignContent");
  1087. }
  1088. private void UpdateShowContent(string currentBar)
  1089. {
  1090. ToolContentVisible = Visibility.Collapsed;
  1091. ToolsBarContentVisible = Visibility.Collapsed;
  1092. ConverterBarContentVisible = Visibility.Collapsed;
  1093. TextEditToolContentVisible = Visibility.Collapsed;
  1094. OCRContentVisible = Visibility.Collapsed;
  1095. switch (currentBar)
  1096. {
  1097. case "TabItemAnnotation":
  1098. case "TabItemTool":
  1099. case "TabItemForm":
  1100. case "TabItemFill":
  1101. ToolsBarContentVisible = Visibility.Visible;
  1102. break;
  1103. case "TabItemScan":
  1104. ToolsBarContentVisible = Visibility.Visible;
  1105. OCRContentVisible = Visibility.Visible;
  1106. break;
  1107. case "TabItemEdit":
  1108. TextEditToolContentVisible = Visibility.Visible;
  1109. break;
  1110. case "TabItemConvert":
  1111. ConverterBarContentVisible = Visibility.Visible;
  1112. break;
  1113. case "TabItemPageEdit":
  1114. case "HeaderFooterContent":
  1115. case "BatesContent":
  1116. case "WatermarkContent":
  1117. case "BackgroundContent":
  1118. case "RedactionContent":
  1119. ToolContentVisible = Visibility.Visible;
  1120. break;
  1121. default:
  1122. break;
  1123. }
  1124. PDFEditMode(currentBar);
  1125. FormMode(currentBar);
  1126. }
  1127. private void PDFEditMode(string currentBar)
  1128. {
  1129. if (currentBar == "TabItemEdit")
  1130. {
  1131. if (PDFViewer != null)
  1132. {
  1133. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1134. //SelectedPrpoertyPanel("TextEditProperty", null);
  1135. //IsPropertyOpen = true;
  1136. }
  1137. }
  1138. else
  1139. {
  1140. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1141. {
  1142. IsPropertyOpen = false;
  1143. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1144. }
  1145. }
  1146. }
  1147. private void FormMode(string currentBar)
  1148. {
  1149. if (currentBar == "TabItemForm")
  1150. {
  1151. if (PDFViewer != null)
  1152. {
  1153. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1154. }
  1155. }
  1156. else
  1157. {
  1158. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1159. {
  1160. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1161. }
  1162. }
  1163. }
  1164. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1165. {
  1166. if (!isInPageEdit)
  1167. {
  1168. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1169. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  1170. if (e.PropertyName == "CanUndo")
  1171. {
  1172. CanUndo = PDFViewer.UndoManager.CanUndo;
  1173. }
  1174. if (e.PropertyName == "CanRedo")
  1175. {
  1176. CanRedo = PDFViewer.UndoManager.CanRedo;
  1177. }
  1178. }
  1179. if (e.PropertyName == "CanSave")
  1180. {
  1181. CanSave = PDFViewer.UndoManager.CanSave;
  1182. }
  1183. }
  1184. /// <summary>
  1185. /// 选项卡切换事件
  1186. /// </summary>
  1187. /// <param name="e"></param>
  1188. private void TabControlSelectonChangedEvent(object e)
  1189. {
  1190. var args = e as SelectionChangedEventArgs;
  1191. if (args != null)
  1192. {
  1193. var item = args.AddedItems[0] as TabItem;
  1194. CurrentBar = item.Name;
  1195. if (previousBar != CurrentBar)
  1196. {
  1197. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1198. {
  1199. EnterToolMode(barContentByTabItem[CurrentBar]);
  1200. isInPageEdit = true;
  1201. }
  1202. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1203. {
  1204. EnterSelectedBar(CurrentBar);
  1205. isInPageEdit = false;
  1206. }
  1207. previousBar = CurrentBar;
  1208. }
  1209. }
  1210. }
  1211. /// <summary>
  1212. /// 阅读模式
  1213. /// </summary>
  1214. /// <param name="viewContent"></param>
  1215. public async void RbtnReadMode()
  1216. {
  1217. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1218. mainViewModel.IsBookMode = true;
  1219. IsLoading = Visibility.Visible;
  1220. await Task.Delay(1);
  1221. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1222. NavigationParameters param = new NavigationParameters();
  1223. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1224. param.Add(ParameterNames.ViewContentViewModel, this);
  1225. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1226. //ShowContent(CurrentBar, true);
  1227. if (GridToolRow != 0)
  1228. {
  1229. GridToolRow = 0;
  1230. }
  1231. if (GridToolRowSpan != 4)
  1232. {
  1233. GridToolRowSpan = 4;
  1234. }
  1235. //isInPageEdit = true;
  1236. UpdateShowContent("TabItemPageEdit");
  1237. IsLoading = Visibility.Collapsed;
  1238. }
  1239. /// <summary>
  1240. /// 退出阅读模式
  1241. /// </summary>
  1242. public async void UnReadModel()
  1243. {
  1244. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1245. mainViewModel.IsBookMode = false;
  1246. IsLoading = Visibility.Visible;
  1247. await Task.Delay(1);
  1248. //PDFViewer.MouseMode = MouseModes.None;
  1249. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1250. {
  1251. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1252. {
  1253. var contentRegion = region.Regions[ViwerRegionName];
  1254. contentRegion.Remove(PDFViewer);
  1255. }
  1256. //还原背景色
  1257. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1258. region.AddToRegion(ViwerRegionName, PDFViewer);
  1259. }
  1260. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1261. {
  1262. EnterSelectedBar("TabItemAnnotation");
  1263. }
  1264. else
  1265. {
  1266. EnterSelectedBar(CurrentBar);
  1267. }
  1268. bool isExist = false;
  1269. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1270. {
  1271. var views = region.Regions[TipContentRegionName].Views;
  1272. foreach (var item in views)
  1273. {
  1274. if (item is Views.TipContent.ReadModelTip readModelTip)
  1275. {
  1276. isExist = true;
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. if (isExist == false)
  1282. {
  1283. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1284. }
  1285. IsLoading = Visibility.Collapsed;
  1286. ShowTip(true);
  1287. await Task.Delay(3000);
  1288. //ReadModelTip = Visibility.Collapsed;
  1289. TipVisible = Visibility.Collapsed;
  1290. }
  1291. #region PDFViewer鼠标滚轮缩放事件
  1292. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1293. {
  1294. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1295. PDFViewer.Zoom(newZoom);
  1296. }
  1297. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1298. {
  1299. double standardZoom = 100;
  1300. if (zoom <= 0.01)
  1301. {
  1302. return 0.01;
  1303. }
  1304. if (zoom >= 10)
  1305. {
  1306. return 10;
  1307. }
  1308. zoom *= 100;
  1309. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1310. {
  1311. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1312. {
  1313. standardZoom = zoomLevel[i + 1];
  1314. break;
  1315. }
  1316. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1317. {
  1318. standardZoom = zoomLevel[i];
  1319. break;
  1320. }
  1321. }
  1322. return standardZoom / 100;
  1323. }
  1324. #endregion PDFViewer鼠标滚轮缩放事件
  1325. #region Navigate
  1326. public void OnNavigatedTo(NavigationContext navigationContext)
  1327. {
  1328. if (isOpenFile)
  1329. return;
  1330. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  1331. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  1332. if (mainVM != null)
  1333. {
  1334. mainViewModel = mainVM;
  1335. mainViewModel.viewContentViewModel = this;
  1336. }
  1337. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  1338. if (pdfview != null)
  1339. {
  1340. PDFViewer = pdfview;
  1341. if (pdfview.Tag != null)
  1342. {
  1343. //保存密码
  1344. PassWord = pdfview.Tag.ToString();
  1345. }
  1346. loadFile();
  1347. CheckHaveAllPermission();
  1348. }
  1349. isOpenFile = true;
  1350. //快捷键
  1351. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1352. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1353. }
  1354. public bool IsNavigationTarget(NavigationContext navigationContext)
  1355. {
  1356. if (navigationContext != null)
  1357. {
  1358. //另存为打开导航进来时 不能新建一个实例
  1359. return true;
  1360. }
  1361. else
  1362. {
  1363. //一次性打开多个文件时,需要新建实例
  1364. return false;
  1365. }
  1366. }
  1367. public void OnNavigatedFrom(NavigationContext navigationContext)
  1368. {
  1369. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1370. }
  1371. #endregion Navigate
  1372. #region 方法
  1373. /// <summary>
  1374. /// 快捷键
  1375. /// </summary>
  1376. /// <param name="sender"></param>
  1377. /// <param name="e"></param>
  1378. /// <exception cref="NotImplementedException"></exception>
  1379. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1380. {
  1381. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1382. {
  1383. if (mainViewModel.IsBookMode == true)
  1384. {
  1385. UnReadModel();
  1386. }
  1387. //内容选择 退出
  1388. if (PDFViewer.MouseMode != MouseModes.PanTool)
  1389. {
  1390. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1391. if (annotToolContent != null && toolContentViewModel != null)
  1392. {
  1393. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1394. {
  1395. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  1396. {
  1397. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  1398. annotToolContent.BtnSelecttool.IsChecked = false;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  1405. {
  1406. //内容选择 复制 快捷键
  1407. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1408. if (annotToolContent != null && toolContentViewModel != null)
  1409. {
  1410. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1411. {
  1412. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  1413. }
  1414. }
  1415. }
  1416. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  1417. {
  1418. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1419. if (annotToolContent != null && toolContentViewModel != null)
  1420. {
  1421. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1422. {
  1423. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  1424. }
  1425. }
  1426. }
  1427. }
  1428. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  1429. {
  1430. AnnotToolContent toolContent = null;
  1431. toolContentViewModel = null;
  1432. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1433. {
  1434. var views = region.Regions[ToolsBarContentRegionName].Views;
  1435. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1436. if (model is AnnotToolContent annotToolContent)
  1437. {
  1438. toolContent = annotToolContent;
  1439. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1440. }
  1441. }
  1442. return toolContent;
  1443. }
  1444. /// <summary>
  1445. /// 视图面板 切换分屏模式
  1446. /// </summary>
  1447. /// <param name="mode"></param>
  1448. public void EnterSplitMode(SplitMode mode)
  1449. {
  1450. ///通知UI层更改布局
  1451. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1452. }
  1453. private void Undo()
  1454. {
  1455. if (isInPageEdit)
  1456. {
  1457. //执行页面编辑的Undo
  1458. PageEditUndo?.Invoke();
  1459. }
  1460. else
  1461. {
  1462. PDFViewer.UndoManager.Undo();
  1463. }
  1464. }
  1465. private void Redo()
  1466. {
  1467. if (isInPageEdit)
  1468. {
  1469. //执行页面编辑的Redo
  1470. PageEditRedo?.Invoke();
  1471. }
  1472. else
  1473. {
  1474. PDFViewer.UndoManager.Redo();
  1475. }
  1476. }
  1477. private void LoadControl()
  1478. {
  1479. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  1480. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  1481. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1482. // {
  1483. NavigationParameters parameters = new NavigationParameters();
  1484. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1485. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1486. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1487. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1488. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  1489. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1490. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1491. EnterSelectedBar("TabItemAnnotation");
  1492. //}
  1493. //));
  1494. //if (App.IsBookMode)
  1495. //{
  1496. // RbtnReadMode();
  1497. //}
  1498. //else
  1499. //{
  1500. // UnReadModel();
  1501. //}
  1502. }
  1503. /// <summary>
  1504. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1505. /// </summary>
  1506. /// <param name="Content"></param>
  1507. /// <param name="annotPropertyPanel"></param>
  1508. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  1509. {
  1510. NavigationParameters parameters = new NavigationParameters();
  1511. //传其他参数:文档类,空注释面板;
  1512. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1513. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1514. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1515. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1516. }
  1517. /// <summary>
  1518. /// 将PDFViwer添加到Region
  1519. /// </summary>
  1520. private void loadFile()
  1521. {
  1522. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1523. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1524. CanSave = PDFViewer.UndoManager.CanSave;
  1525. CanUndo = PDFViewer.UndoManager.CanUndo;
  1526. CanRedo = PDFViewer.UndoManager.CanRedo;
  1527. //OpenFileInfo 内容赋值给PDFViewer
  1528. GetOpenFileInfo();
  1529. region.AddToRegion(ViwerRegionName, PDFViewer);
  1530. }
  1531. /// <summary>
  1532. /// 还原上一次浏览的视图相关设置
  1533. /// </summary>
  1534. private void GetOpenFileInfo()
  1535. {
  1536. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1537. //偏好设置里设置了记录上次视图设置时
  1538. if (OpenFileInfo != null&&Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  1539. {
  1540. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1541. {
  1542. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1543. }
  1544. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1545. {
  1546. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1547. }
  1548. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1549. {
  1550. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1551. }
  1552. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1553. {
  1554. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1555. }
  1556. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1557. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1558. if (OpenFileInfo.LastPageSpace)
  1559. {
  1560. PDFViewer.SetPageSpacing(8);
  1561. }
  1562. else
  1563. {
  1564. PDFViewer.SetPageSpacing(0);
  1565. }
  1566. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  1567. {
  1568. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  1569. }
  1570. else
  1571. {
  1572. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  1573. }
  1574. }
  1575. else
  1576. {
  1577. //新文档应用默认设置
  1578. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  1579. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  1580. }
  1581. }
  1582. /// <summary>
  1583. /// 已有路径文档的保存逻辑
  1584. /// </summary>
  1585. public bool saveFile()
  1586. {
  1587. try
  1588. {
  1589. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  1590. return saveAsFile();
  1591. //文档已被修复时 提示另存为
  1592. if (PDFViewer.Document.HasRepaired)
  1593. {
  1594. AlertsMessage alertsMessage = new AlertsMessage();
  1595. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  1596. if (alertsMessage.result == ContentResult.Ok)
  1597. return saveAsFile();
  1598. else
  1599. return false;
  1600. }
  1601. //文件路径无法存在时
  1602. if (!File.Exists(PDFViewer.Document.FilePath))
  1603. {
  1604. AlertsMessage alertsMessage = new AlertsMessage();
  1605. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  1606. if (alertsMessage.result == ContentResult.Ok)
  1607. return saveAsFile();
  1608. else
  1609. return false;
  1610. }
  1611. //只读文件无法写入时,提示另存为
  1612. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  1613. if (fileInfo.IsReadOnly)
  1614. {
  1615. AlertsMessage alertsMessage = new AlertsMessage();
  1616. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  1617. if (alertsMessage.result == ContentResult.Ok)
  1618. return saveAsFile();
  1619. else
  1620. return false;
  1621. }
  1622. //Security Fixed:
  1623. //修改密码后原文档保存的步骤:
  1624. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  1625. //延迟保存方式:
  1626. //
  1627. //
  1628. if (SecurityInfo.IsPasswordChanged)
  1629. {
  1630. string currentFilePath = PDFViewer.Document.FilePath;
  1631. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  1632. string openPassword = null;
  1633. string permissionsPassword = null;
  1634. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  1635. if (SecurityInfo.NeedOpenPassword)
  1636. {
  1637. openPassword = SecurityInfo.OpenPassword;
  1638. }
  1639. if (SecurityInfo.NeedPermissionsPassword)
  1640. {
  1641. permissionsPassword = SecurityInfo.PermissionsPassword;
  1642. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  1643. }
  1644. try
  1645. {
  1646. string currentPath = PDFViewer.Document.FilePath;
  1647. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  1648. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1649. PDFViewer.Document.WriteToFilePath(tempPath);
  1650. PDFViewer.CloseDocument();
  1651. PDFViewer.InitDocument(tempPath);
  1652. if (!string.IsNullOrEmpty(permissionsPassword))
  1653. {
  1654. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1655. }
  1656. else if (!string.IsNullOrEmpty(openPassword))
  1657. {
  1658. PDFViewer.Document.UnlockWithPassword(openPassword);
  1659. }
  1660. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  1661. PDFViewer.Document.WriteToFilePath(currentPath);
  1662. PDFViewer.CloseDocument();
  1663. PDFViewer.InitDocument(currentPath);
  1664. //System.IO.File.Delete(tempPath);
  1665. if (!string.IsNullOrEmpty(permissionsPassword))
  1666. {
  1667. PDFViewer.Document.UnlockWithPassword(permissionsPassword);
  1668. }
  1669. else if (!string.IsNullOrEmpty(openPassword))
  1670. {
  1671. PDFViewer.Document.UnlockWithPassword(openPassword);
  1672. }
  1673. try
  1674. {
  1675. PDFViewer.Load();
  1676. }
  1677. catch
  1678. {
  1679. }
  1680. PDFViewer.UndoManager.CanSave = false;
  1681. SecurityInfo.IsPasswordChanged = false;
  1682. return true;
  1683. }
  1684. catch
  1685. {
  1686. return false;
  1687. }
  1688. }
  1689. bool result = PDFViewer.Document.WriteToLoadedPath();
  1690. if (result)
  1691. {
  1692. PDFViewer.UndoManager.CanSave = false;
  1693. App.Current.Dispatcher.Invoke(() =>
  1694. {
  1695. //保存时更新缩略图
  1696. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1697. try
  1698. {
  1699. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  1700. {
  1701. var size = PDFViewer.Document.GetPageSize(0);
  1702. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  1703. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  1704. if (File.Exists(folderPath))
  1705. File.Delete(folderPath);
  1706. DirectoryInfo folder = new DirectoryInfo(folderPath);
  1707. if (!folder.Exists)
  1708. folder.Create();
  1709. string imagePath = info.ThumbImgPath;
  1710. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  1711. {
  1712. string imageName = Guid.NewGuid().ToString();
  1713. imagePath = System.IO.Path.Combine(folderPath, imageName);
  1714. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  1715. {
  1716. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1717. }
  1718. }
  1719. else
  1720. {
  1721. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  1722. {
  1723. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  1724. }
  1725. }
  1726. info.ThumbImgPath = imagePath;
  1727. SettingHelper.SetFileInfo(info);
  1728. }
  1729. }
  1730. catch
  1731. {
  1732. info.ThumbImgPath = null;
  1733. SettingHelper.SetFileInfo(info);
  1734. }
  1735. });
  1736. PDFViewer.ReloadDocument();
  1737. }
  1738. else
  1739. {
  1740. //文件被占用 保存失败时
  1741. AlertsMessage alertsMessage = new AlertsMessage();
  1742. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  1743. if (alertsMessage.result == ContentResult.Ok)
  1744. return saveAsFile();
  1745. else
  1746. return false;
  1747. }
  1748. return result;
  1749. }
  1750. catch { return false; }
  1751. }
  1752. /// <summary>
  1753. /// 另存为或新文档保存逻辑
  1754. /// </summary>
  1755. public bool saveAsFile(Action RedactionAction = null)
  1756. {
  1757. var dlg = new Microsoft.Win32.SaveFileDialog();
  1758. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1759. dlg.FileName = PDFViewer.Document.FileName;
  1760. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1761. {
  1762. bool result = false;
  1763. if (RedactionAction != null)
  1764. {
  1765. //保存前进行标记密文处理应用或擦除
  1766. RedactionAction.Invoke();
  1767. }
  1768. if (App.OpenedFileList.Contains(dlg.FileName))
  1769. {
  1770. //提示文件已经被打开
  1771. }
  1772. else
  1773. {
  1774. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1775. if (result)
  1776. {
  1777. DoAfterSaveAs(dlg.FileName);
  1778. }
  1779. else
  1780. {
  1781. //提示文件被其他软件占用 无法保存
  1782. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1783. }
  1784. ;
  1785. }
  1786. return result;
  1787. }
  1788. else
  1789. return false;
  1790. }
  1791. /// <summary>
  1792. /// 另存为Flatten
  1793. /// </summary>
  1794. private void saveAsFlatten()
  1795. {
  1796. var dlg = new SaveFileDialog();
  1797. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1798. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1799. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1800. {
  1801. saveFile();
  1802. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1803. if (kmdoc == null)
  1804. return;
  1805. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1806. if (result)
  1807. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1808. kmdoc.Release();
  1809. }
  1810. }
  1811. /// <summary>
  1812. /// 另存为后进行的操作
  1813. /// 重新打开新文档
  1814. /// </summary>
  1815. /// <param name="targetPath"></param>
  1816. public void DoAfterSaveAs(string targetPath)
  1817. {
  1818. App.OpenedFileList.Remove(targetPath);
  1819. string oldFilePath = targetPath;
  1820. PDFViewer.UndoManager.CanSave = false;
  1821. mainViewModel.OpenFile(targetPath);
  1822. //TODO:通知各模块更新PDFview对象
  1823. //var result = OpenFile(targetPath, true);
  1824. //if (result)
  1825. //{
  1826. // FileChanged.Invoke(this, null);
  1827. // Zoomer.PdfViewer = PdfViewer;
  1828. // PageSelector.PdfViewer = PdfViewer;
  1829. // ViewModeSelector.PdfViewer = PdfViewer;
  1830. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1831. // if (fileInfo != null)
  1832. // {
  1833. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1834. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1835. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1836. // PdfViewer.Zoom(fileInfo.LastZoom);
  1837. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1838. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1839. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1840. // else
  1841. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1842. // }
  1843. //}
  1844. }
  1845. /// <summary>
  1846. /// 显示前添加内容到Region
  1847. /// </summary>
  1848. /// <param name="isPageEdit"></param>
  1849. private void ShowContent(string currentBar, bool isToolMode = false)
  1850. {
  1851. GridVisibility = Visibility.Visible;
  1852. //显示页面编辑或其他工具
  1853. if (currentBar == "TabItemPageEdit" || isToolMode)
  1854. {
  1855. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1856. {
  1857. if (GridToolRow != 1)
  1858. {
  1859. GridToolRow = 1;
  1860. }
  1861. if (GridToolRowSpan != 3)
  1862. {
  1863. GridToolRowSpan = 3;
  1864. }
  1865. }
  1866. else//进入水印等其他工具模式
  1867. {
  1868. GridVisibility = Visibility.Collapsed;
  1869. if (GridToolRow != 0)
  1870. {
  1871. GridToolRow = 0;
  1872. }
  1873. if (GridToolRowSpan != 4)
  1874. {
  1875. GridToolRowSpan = 4;
  1876. }
  1877. }
  1878. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1879. UpdateShowContent(currentBar);
  1880. }
  1881. else
  1882. {
  1883. if (GridToolRow != 1)
  1884. {
  1885. GridToolRow = 1;
  1886. }
  1887. UpdateShowContent(currentBar);
  1888. }
  1889. }
  1890. /// <summary>
  1891. /// 从二级工具栏进入需要修改界面布局的场景
  1892. /// </summary>
  1893. /// <param name="EditToolName"></param>
  1894. private void EnterEditTools(StringWithUnicode EditToolName)
  1895. {
  1896. EnterSelectedEditTool(EditToolName);
  1897. }
  1898. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1899. {
  1900. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1901. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1902. {
  1903. PDFViewer.Document.ReleasePages();
  1904. PDFViewer.ReloadDocument();
  1905. }
  1906. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1907. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1908. {
  1909. region.AddToRegion(ViwerRegionName, PDFViewer);
  1910. }
  1911. CurrentBar = "TabItemTool";
  1912. EnterSelectedBar(CurrentBar);
  1913. }
  1914. /// <summary>
  1915. /// 二级菜单指定目标处理
  1916. /// </summary>
  1917. /// <param name="e"></param>
  1918. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1919. {
  1920. CurrentBar = EditToolName.EditToolsContentName;
  1921. EnterToolMode(CurrentBar);
  1922. }
  1923. /// <summary>
  1924. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1925. /// </summary>
  1926. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1927. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1928. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1929. {
  1930. IsLoading = Visibility.Visible;
  1931. await Task.Delay(3);
  1932. NavigationParameters param = new NavigationParameters();
  1933. if (valuePairs == null)
  1934. {
  1935. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1936. param.Add(ParameterNames.ViewContentViewModel, this);
  1937. }
  1938. else//有传入其他内容的参数时
  1939. {
  1940. param = valuePairs;
  1941. }
  1942. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1943. ShowContent(CurrentBar, true);
  1944. IsLoading = Visibility.Collapsed;
  1945. }
  1946. private void EnterSelectedBar(string currentBar)
  1947. {
  1948. NavigationParameters param = new NavigationParameters();
  1949. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1950. param.Add(ParameterNames.ViewContentViewModel, this);
  1951. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1952. if (currentBar == "TabItemScan")
  1953. {
  1954. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1955. }
  1956. ShowContent(currentBar);
  1957. }
  1958. /// <summary>
  1959. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1960. /// </summary>
  1961. public void ExitToolMode()
  1962. {
  1963. ToolContentVisible = Visibility.Collapsed;
  1964. if (isInPageEdit)
  1965. {
  1966. TabSelectedIndex = 0;
  1967. isInPageEdit = false;
  1968. }
  1969. }
  1970. #endregion 方法
  1971. }
  1972. }