ViewContentViewModel.cs 80 KB

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