ViewContentViewModel.cs 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850
  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_Master.CustomControl;
  11. using PDF_Master.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Master.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Master.EventAggregators;
  19. using PDF_Master.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings.Settings;
  22. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Master.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Master.Model.Dialog.ConverterDialogs;
  27. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Master.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  34. using ImTools;
  35. using PDF_Master.Properties;
  36. using PDF_Master.ViewModels.BOTA;
  37. using PDF_Master.Views.BOTA;
  38. using System.Drawing;
  39. using PDF_Master.ViewModels.Tools.AnnotManager;
  40. using PDF_Master.Model.FillAndSign;
  41. using PDF_Master.Views.PropertyPanel.ViewModular;
  42. using PDF_Master.Views.PropertyPanel;
  43. using System.Windows.Threading;
  44. using Dropbox.Api.Files;
  45. using System.Windows.Media;
  46. using Color = System.Windows.Media.Color;
  47. using PDFSettings;
  48. using PDF_Master.Views;
  49. namespace PDF_Master.ViewModels
  50. {
  51. public class ViewContentViewModel : BindableBase, INavigationAware
  52. {
  53. #region 文案
  54. private string T_file;
  55. public string T_File
  56. {
  57. get { return T_file; }
  58. set
  59. {
  60. SetProperty(ref T_file, value);
  61. }
  62. }
  63. private string T_save;
  64. public string T_Save
  65. {
  66. get { return T_save; }
  67. set
  68. {
  69. SetProperty(ref T_save, value);
  70. }
  71. }
  72. private string T_undo;
  73. public string T_Undo
  74. {
  75. get { return T_undo; }
  76. set
  77. {
  78. SetProperty(ref T_undo, value);
  79. }
  80. }
  81. private string T_redo;
  82. public string T_Redo
  83. {
  84. get { return T_redo; }
  85. set
  86. {
  87. SetProperty(ref T_redo, value);
  88. }
  89. }
  90. private string T_annotation;
  91. public string T_Annotation
  92. {
  93. get { return T_annotation; }
  94. set
  95. {
  96. SetProperty(ref T_annotation, value);
  97. }
  98. }
  99. private string T_pageEdit;
  100. public string T_PageEdit
  101. {
  102. get { return T_pageEdit; }
  103. set
  104. {
  105. SetProperty(ref T_pageEdit, value);
  106. }
  107. }
  108. private string T_converter;
  109. public string T_Converter
  110. {
  111. get { return T_converter; }
  112. set
  113. {
  114. SetProperty(ref T_converter, value);
  115. }
  116. }
  117. private string T_fillSign;
  118. public string T_FillSign
  119. {
  120. get { return T_fillSign; }
  121. set
  122. {
  123. SetProperty(ref T_fillSign, value);
  124. }
  125. }
  126. private string T_tools;
  127. public string T_Tools
  128. {
  129. get { return T_tools; }
  130. set
  131. {
  132. SetProperty(ref T_tools, value);
  133. }
  134. }
  135. private string T_print;
  136. public string T_Print
  137. {
  138. get { return T_print; }
  139. set
  140. {
  141. SetProperty(ref T_print, value);
  142. }
  143. }
  144. private string T_share;
  145. public string T_Share
  146. {
  147. get { return T_share; }
  148. set
  149. {
  150. SetProperty(ref T_share, value);
  151. }
  152. }
  153. private string T_properties;
  154. public string T_Properties
  155. {
  156. get { return T_properties; }
  157. set
  158. {
  159. SetProperty(ref T_properties, value);
  160. }
  161. }
  162. private void InitStirng()
  163. {
  164. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  165. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  166. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  167. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  168. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  169. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  170. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  171. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  172. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  173. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  174. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  175. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  176. }
  177. #endregion 文案
  178. #region 属性、变量
  179. public bool IsMultiSelected { get; set; } = false;
  180. public OpenFileInfo OpenFileInfo = null;
  181. public CPDFViewer PDFViewer { get; set; }
  182. public bool ReadModeIsShowProperty { get; set; } = false;
  183. public MainContentViewModel mainViewModel { get; set; }
  184. public IRegionManager region;
  185. public IDialogService dialogs;
  186. public IEventAggregator events;
  187. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  188. public string ViwerRegionName { get; set; }
  189. /// <summary>
  190. /// 分屏视图的region名称
  191. /// </summary>
  192. public string SplitViewerRegionName { get; set; }
  193. /// <summary>
  194. /// OCR视图名称
  195. /// </summary>
  196. public string OCRViewerRegionName { get; set; }
  197. public string BOTARegionName { get; set; }
  198. public string PropertyRegionName { get; set; }
  199. public string ToolContentRegionName { get; set; }
  200. public string ToolsBarContentRegionName { get; set; }
  201. /// <summary>
  202. /// 顶部提示的Content
  203. /// </summary>
  204. public string TipContentRegionName { get; set; }
  205. public string LeftTipContentRegionName { get; set; }
  206. //便签弹窗
  207. public string NotePopupRegionName { get; set; }
  208. public string ReadModeRegionName { get; set; }
  209. public string TextEditContentRegionName { get; set; }
  210. public string BackgroundContentRegionName { get; set; }
  211. public PasswordInfo PasswordInfo = new PasswordInfo();
  212. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  213. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  214. /// <summary>
  215. /// 签名列表
  216. /// </summary>
  217. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  218. /// <summary>
  219. /// 文档的密码
  220. /// </summary>
  221. public string PassWord { get; set; }
  222. public PasswordInfo passwordInfo = new PasswordInfo();
  223. private Visibility tipVisible = Visibility.Collapsed;
  224. /// <summary>
  225. /// 顶部提示栏的显示状态
  226. /// </summary>
  227. public bool IsFileLocked = false;
  228. public Visibility TipVisible
  229. {
  230. get { return tipVisible; }
  231. set
  232. {
  233. SetProperty(ref tipVisible, value);
  234. }
  235. }
  236. private Visibility leftTipVisible = Visibility.Collapsed;
  237. public Visibility LeftTipVisible
  238. {
  239. get { return leftTipVisible; }
  240. set
  241. {
  242. SetProperty(ref leftTipVisible, value);
  243. }
  244. }
  245. private Visibility notePopupVisible = Visibility.Collapsed;
  246. public Visibility NotePopupVisible
  247. {
  248. get { return notePopupVisible; }
  249. set
  250. {
  251. SetProperty(ref notePopupVisible, value);
  252. }
  253. }
  254. public bool IsNoteAdd = false;
  255. private double canvasNoteLeft;
  256. public double CanvasNoteLeft
  257. {
  258. get { return canvasNoteLeft; }
  259. set
  260. {
  261. SetProperty(ref canvasNoteLeft, value);
  262. }
  263. }
  264. private double canvasNoteBottom;
  265. public double CanvasNoteBottom
  266. {
  267. get { return canvasNoteBottom; }
  268. set
  269. {
  270. SetProperty(ref canvasNoteBottom, value);
  271. }
  272. }
  273. /// <summary>
  274. /// 底部工具栏 RegionName
  275. /// </summary>
  276. public string BottomToolRegionName { get; set; }
  277. private bool _isInPageEdit = false;
  278. /// <summary>
  279. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  280. /// </summary>
  281. public bool isInPageEdit
  282. {
  283. get { return _isInPageEdit; }
  284. set
  285. {
  286. SetProperty(ref _isInPageEdit, value);
  287. //if (!value)
  288. //{
  289. // CanRedo = PDFViewer.UndoManager.CanRedo;
  290. // CanUndo = PDFViewer.UndoManager.CanUndo;
  291. //}
  292. }
  293. }
  294. public Action PageEditUndo { get; set; }
  295. public Action PageEditRedo { get; set; }
  296. /// <summary>
  297. ///工具条
  298. ///0:收起
  299. ///40:显示
  300. /// </summary>
  301. private int toolRowHeight = 40;
  302. public int ToolRowHeight
  303. {
  304. get { return toolRowHeight; }
  305. set
  306. {
  307. SetProperty(ref toolRowHeight, value);
  308. }
  309. }
  310. /// <summary>
  311. /// 水印,背景侧边栏宽度
  312. /// 0:收起
  313. /// 260:显示
  314. /// </summary>
  315. private int propertyColumnWidth = 0;
  316. public int PropertyColumnWidth
  317. {
  318. get { return propertyColumnWidth; }
  319. set
  320. {
  321. SetProperty(ref propertyColumnWidth, value);
  322. }
  323. }
  324. private int gridToolRow = 1;
  325. /// <summary>
  326. /// 控制ToolContent的Row
  327. /// </summary>
  328. public int GridToolRow
  329. {
  330. get { return gridToolRow; }
  331. set
  332. {
  333. SetProperty(ref gridToolRow, value);
  334. }
  335. }
  336. private int gridToolRowSpan = 3;
  337. /// <summary>
  338. /// 控制ToolContent的RowSpan
  339. /// </summary>
  340. public int GridToolRowSpan
  341. {
  342. get { return gridToolRowSpan; }
  343. set
  344. {
  345. SetProperty(ref gridToolRowSpan, value);
  346. }
  347. }
  348. private Visibility toolContentVisible = Visibility.Collapsed;
  349. /// <summary>
  350. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  351. /// 留意:显示前需要先注入内容、设置好行和跨行数
  352. /// </summary>
  353. public Visibility ToolContentVisible
  354. {
  355. get { return toolContentVisible; }
  356. set
  357. {
  358. SetProperty(ref toolContentVisible, value);
  359. }
  360. }
  361. private Visibility gridVisibility = Visibility.Visible;
  362. /// <summary>
  363. /// 是否正在加载中
  364. /// </summary>
  365. public Visibility GridVisibility
  366. {
  367. get { return gridVisibility; }
  368. set
  369. {
  370. SetProperty(ref gridVisibility, value);
  371. }
  372. }
  373. private Visibility isLoading = Visibility.Collapsed;
  374. private Visibility ocrContentVisible = Visibility.Collapsed;
  375. public Visibility OCRContentVisible
  376. {
  377. get { return ocrContentVisible; }
  378. set
  379. {
  380. SetProperty(ref ocrContentVisible, value);
  381. }
  382. }
  383. /// <summary>
  384. /// 是否正在加载中
  385. /// </summary>
  386. public Visibility IsLoading
  387. {
  388. get { return isLoading; }
  389. set
  390. {
  391. SetProperty(ref isLoading, value);
  392. }
  393. }
  394. private Visibility converterBarContentVisible = Visibility.Collapsed;
  395. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  396. ///// <summary>
  397. ///// 控制ToolsBarContent的显示
  398. ///// 留意:显示前需要先注入内容、设置好行和跨行数
  399. ///// </summary>
  400. //public Visibility ConverterBarContentVisible
  401. //{
  402. // get { return converterBarContentVisible; }
  403. // set
  404. // {
  405. // SetProperty(ref converterBarContentVisible, value);
  406. // }
  407. //}
  408. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  409. /// <summary>
  410. /// 控制ToolsBarContent的显示
  411. /// 留意:显示前需要先注入内容、设置好行和跨行数
  412. /// </summary>
  413. public Visibility ToolsBarContentVisible
  414. {
  415. get { return toolsBarContentVisible; }
  416. set
  417. {
  418. SetProperty(ref toolsBarContentVisible, value);
  419. }
  420. }
  421. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  422. /// <summary>
  423. /// 控制ToolsBarContent的显示
  424. /// 留意:显示前需要先注入内容、设置好行和跨行数
  425. /// </summary>
  426. public Visibility TextEditToolContentVisible
  427. {
  428. get { return textEditToolContentVisible; }
  429. set
  430. {
  431. SetProperty(ref textEditToolContentVisible, value);
  432. }
  433. }
  434. private bool isPorpertyOpen = false;
  435. /// <summary>
  436. /// 属性栏是否展开
  437. /// </summary>
  438. public bool IsPropertyOpen
  439. {
  440. get { return isPorpertyOpen; }
  441. set
  442. {
  443. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  444. //或者手动点击按钮时 也展开
  445. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty || FromClick)
  446. {
  447. if (mainViewModel.IsBookMode)
  448. {
  449. this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  450. }
  451. SetProperty(ref isPorpertyOpen, value);
  452. }
  453. }
  454. }
  455. /// <summary>
  456. /// 是否是点击属性面板按钮
  457. /// </summary>
  458. private bool FromClick = false;
  459. private Visibility isReadMode = Visibility.Visible;
  460. /// <summary>
  461. ///是否为阅读模式
  462. /// </summary>
  463. public Visibility IsReadMode
  464. {
  465. get { return isReadMode; }
  466. set
  467. {
  468. SetProperty(ref isReadMode, value);
  469. }
  470. }
  471. private bool canSave;
  472. /// <summary>
  473. /// 是否可以保存
  474. /// </summary>
  475. public bool CanSave
  476. {
  477. get { return canSave; }
  478. set
  479. {
  480. if (events != null && canSave == false)
  481. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  482. SetProperty(ref canSave, value);
  483. }
  484. }
  485. private bool canUndo;
  486. /// <summary>
  487. /// 是否可以进行Undo
  488. /// </summary>
  489. public bool CanUndo
  490. {
  491. get { return canUndo; }
  492. set
  493. {
  494. SetProperty(ref canUndo, value);
  495. }
  496. }
  497. private bool canRedo;
  498. /// <summary>
  499. /// 是否可以进行Redo
  500. /// </summary>
  501. public bool CanRedo
  502. {
  503. get { return canRedo; }
  504. set
  505. {
  506. SetProperty(ref canRedo, value);
  507. }
  508. }
  509. private GridLength botaWidth = new GridLength(48);
  510. /// <summary>
  511. /// BOTA栏的宽度
  512. /// </summary>
  513. public GridLength BOTAWidth
  514. {
  515. get { return botaWidth; }
  516. set
  517. {
  518. SetProperty(ref botaWidth, value);
  519. if (botaWidth.Value <= 48)
  520. {
  521. OpenBOTA = false;
  522. }
  523. }
  524. }
  525. private int selectedIndex;
  526. /// <summary>
  527. /// 工具栏选中项的索引
  528. /// </summary>
  529. public int TabSelectedIndex
  530. {
  531. get { return selectedIndex; }
  532. set
  533. {
  534. SetProperty(ref selectedIndex, value);
  535. }
  536. }
  537. private bool openBOTA = false;
  538. /// <summary>
  539. /// 是否展开BOTA
  540. /// </summary>
  541. public bool OpenBOTA
  542. {
  543. get { return openBOTA; }
  544. set
  545. {
  546. SetProperty(ref openBOTA, value);
  547. if (openBOTA && BOTAWidth.Value <= 48)
  548. {
  549. BOTAWidth = new GridLength(260);
  550. }
  551. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  552. }
  553. }
  554. public SecurityInfo SecurityInfo = new SecurityInfo();
  555. private Dictionary<string, string> regionNameByTabItem;
  556. private Dictionary<string, string> barContentByTabItem;
  557. private string previousBar = "";
  558. public string CurrentBar = "";
  559. public string unicode = null;
  560. /// <summary>
  561. /// 自动保存的定时器
  562. /// </summary>
  563. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  564. /// <summary>
  565. /// 用来避免重复触发导航事件的标志符
  566. /// </summary>
  567. private bool isOpenFile = false;
  568. /// <summary>
  569. /// 鼠标滚轮缩放的缩放值
  570. /// </summary>
  571. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  572. /// <summary>
  573. /// 注释-链接,提示语
  574. /// </summary>
  575. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  576. public Visibility LinkAnnotTipVisibility
  577. {
  578. get { return linkAnnotTipVisibility; }
  579. set
  580. {
  581. SetProperty(ref linkAnnotTipVisibility, value);
  582. }
  583. }
  584. 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";
  585. private bool isCreateLink = false;
  586. internal bool IsRightMenuSelectedTextAddLink = false;
  587. public string LinkAnnotTipText
  588. {
  589. get { return linkAnnotTipText; }
  590. set
  591. {
  592. SetProperty(ref linkAnnotTipText, value);
  593. }
  594. }
  595. #endregion 属性、变量
  596. #region 命令
  597. public DelegateCommand Load { get; set; }
  598. public DelegateCommand MouseDown { get; set; }
  599. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  600. public DelegateCommand SaveFile { get; set; }
  601. public DelegateCommand SaveAsFile { get; set; }
  602. public DelegateCommand SaveAsFlattenCommand { get; set; }
  603. public DelegateCommand UndoCommand { get; set; }
  604. public DelegateCommand RedoCommand { get; set; }
  605. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  606. public DelegateCommand PrintCommand { get; set; }
  607. public DelegateCommand SelectCommand { get; set; }
  608. public DelegateCommand SettingsCommand { get; set; }
  609. public DelegateCommand ShareCommand { get; set; }
  610. public DelegateCommand<object> CreateLinkCommand { get; set; }
  611. public DelegateCommand PropertyCommand { get; set; }
  612. public DelegateCommand ShowInFolderCommand { get; set; }
  613. public DelegateCommand CompressCommand { get; set; }
  614. public DelegateCommand MergeFileCommand { get; set; }
  615. public DelegateCommand EncryptCommand { get; set; }
  616. public DelegateCommand DecryptCommand { get; set; }
  617. public DelegateCommand<string> ConvertCommand { get; set; }
  618. public DelegateCommand CloseWindowCommand { get; set; }
  619. public DelegateCommand OpenFileCommand { get; set; }
  620. public DelegateCommand<string> HelpCommand { get; set; }
  621. public DelegateCommand CreateBlankFileCommand { get; set; }
  622. public DelegateCommand CreateFromFile { get; set; }
  623. public DelegateCommand ClosePropertyCommand { get; set; }
  624. public DelegateCommand<object> OpenPropertyCommand { get; set; }
  625. #endregion 命令
  626. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  627. {
  628. InitStirng();
  629. region = regionManager;
  630. dialogs = dialogService;
  631. events = eventAggregator;
  632. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  633. Load = new DelegateCommand(LoadControl);
  634. MouseDown = new DelegateCommand(MouseDownEvent);
  635. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  636. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  637. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  638. UndoCommand = new DelegateCommand(Undo);
  639. RedoCommand = new DelegateCommand(Redo);
  640. ShareCommand = new DelegateCommand(share);
  641. PropertyCommand = new DelegateCommand(property);
  642. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  643. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  644. CompressCommand = new DelegateCommand(compress);
  645. MergeFileCommand = new DelegateCommand(mergeFile);
  646. EncryptCommand = new DelegateCommand(encrypt);
  647. DecryptCommand = new DelegateCommand(decrypt);
  648. ConvertCommand = new DelegateCommand<string>(convert);
  649. CloseWindowCommand = new DelegateCommand(closeWindow);
  650. OpenFileCommand = new DelegateCommand(openfile);
  651. HelpCommand = new DelegateCommand<string>(help);
  652. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  653. CreateFromFile = new DelegateCommand(createfromFile);
  654. OpenPropertyCommand = new DelegateCommand<object>(openProperty);
  655. ViwerRegionName = RegionNames.ViwerRegionName;
  656. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  657. BOTARegionName = RegionNames.BOTARegionName;
  658. PropertyRegionName = RegionNames.PropertyRegionName;
  659. BottomToolRegionName = RegionNames.BottomToolRegionName;
  660. ReadModeRegionName = RegionNames.ReadModeRegionName;
  661. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  662. PrintCommand = new DelegateCommand(ShowPrintDialog);
  663. SelectCommand = new DelegateCommand(SelectClick);
  664. SettingsCommand = new DelegateCommand(SettingsEvent);
  665. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  666. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  667. //未显示时无法注册上Region名称
  668. ToolContentVisible = Visibility.Visible;
  669. ToolsBarContentVisible = Visibility.Visible;
  670. OCRContentVisible = Visibility.Visible;
  671. TipVisible = Visibility.Visible;
  672. TipContentRegionName = RegionNames.TipContentRegionName;
  673. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  674. NotePopupRegionName = RegionNames.NotePopupRegionName;
  675. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  676. ToolContentRegionName = Guid.NewGuid().ToString();
  677. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  678. TextEditContentRegionName = Guid.NewGuid().ToString();
  679. ToolContentVisible = Visibility.Collapsed;
  680. ToolsBarContentVisible = Visibility.Collapsed;
  681. OCRContentVisible = Visibility.Collapsed;
  682. TipVisible = Visibility.Collapsed;
  683. regionNameByTabItem = new Dictionary<string, string>();
  684. barContentByTabItem = new Dictionary<string, string>();
  685. InitialregionNameByTabItem(ref regionNameByTabItem);
  686. InitialbarContentByTabItem(ref barContentByTabItem);
  687. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  688. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  689. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  690. //TODO:根据缓存 选择用户上次选择的菜单
  691. CurrentBar = "TabItemAnnotation";
  692. EnterSelectedBar("TabItemAnnotation");
  693. StartAutoSave();
  694. }
  695. /// <summary>
  696. /// 进入全屏模式
  697. /// </summary>
  698. private void OpenFullWindow()
  699. {
  700. DialogParameters parameters = new DialogParameters();
  701. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  702. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  703. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  704. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  705. {
  706. if (e.Result == ButtonResult.Cancel)
  707. {
  708. //TODO:弹窗提示打开全屏模式失败
  709. AlertsMessage alertsMessage = new AlertsMessage();
  710. alertsMessage.ShowDialog("", "Error", "OK");
  711. return;
  712. }
  713. });
  714. }
  715. /// <summary>
  716. /// 点击展开折叠属性面板
  717. /// </summary>
  718. /// <param name="obj"></param>
  719. private void openProperty(object obj)
  720. {
  721. FromClick = true;
  722. IsPropertyOpen = (bool)obj;
  723. FromClick = false;
  724. }
  725. /// <summary>
  726. /// 开始自动保存
  727. /// </summary>
  728. public void StartAutoSave()
  729. {
  730. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  731. if (autoSave)
  732. {
  733. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  734. if (autoSaveTimer == null)
  735. {
  736. autoSaveTimer = new DispatcherTimer();
  737. }
  738. autoSaveTimer.Stop();
  739. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  740. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  741. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  742. autoSaveTimer.Start();
  743. }
  744. }
  745. /// <summary>
  746. /// 释放定时器
  747. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  748. /// </summary>
  749. public void CloseAutoSave()
  750. {
  751. autoSaveTimer.Stop();
  752. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  753. autoSaveTimer = null;
  754. }
  755. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  756. {
  757. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  758. if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
  759. {
  760. //自动保存仅针对已经有文件路径的文档
  761. saveFile();
  762. App.Current.MainWindow.Activate();
  763. }
  764. }
  765. private void MouseDownEvent()
  766. {
  767. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  768. {
  769. NotePopupVisible = Visibility.Collapsed;
  770. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  771. {
  772. var views = region.Regions[NotePopupRegionName].Views;
  773. foreach (var item in views)
  774. {
  775. if (item is StickyNotePopup sticky)
  776. {
  777. var contentRegion = region.Regions[NotePopupRegionName];
  778. contentRegion.Remove(sticky);
  779. break;
  780. }
  781. }
  782. }
  783. }
  784. }
  785. private async void createfromFile()
  786. {
  787. string txt = Properties.Resources.txtex;
  788. string word = Properties.Resources.wordex;
  789. string ppt = Properties.Resources.pptex;
  790. string excel = Properties.Resources.excelex;
  791. string html = Properties.Resources.htmlex;
  792. string image = Properties.Resources.imageex;
  793. string allfiles = txt + word + excel + ppt + image + html;
  794. OpenFileDialog dialog = new OpenFileDialog();
  795. dialog.Multiselect = true;
  796. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  797. $"Microsoft Office Word({word})|{word}|" +
  798. $"Microsoft Office Excel({excel})|{excel}|" +
  799. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  800. $"Txt({txt})|{txt}|" +
  801. $"Picture({image})|{image}|" +
  802. $"Html({html})|{html}");
  803. if ((bool)dialog.ShowDialog())
  804. {
  805. for (int i = 0; i < dialog.FileNames.Length; i++)
  806. {
  807. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  808. {
  809. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  810. }
  811. else
  812. {
  813. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  814. {
  815. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  816. }));
  817. await Task.Delay(20);
  818. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  819. }
  820. }
  821. }
  822. }
  823. /// <summary>
  824. ///创建空白文档
  825. /// </summary>
  826. private async void createBlankFile()
  827. {
  828. App.mainWindowViewModel.AddTab.Execute();
  829. await Task.Delay(30);
  830. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  831. }
  832. private void help(string args)
  833. {
  834. string url = "";
  835. switch (args)
  836. {
  837. case "Guid":
  838. //打开内嵌文档
  839. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  840. {
  841. //如果已经打开时,则选中内嵌文档
  842. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  843. return;
  844. }
  845. if (File.Exists(App.GuidPDFPath))
  846. {
  847. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  848. }
  849. break;
  850. case "Online":
  851. url = @"https://www.pdfreaderpro.com/windows/help";
  852. break;
  853. case "More":
  854. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  855. break;
  856. case "Template":
  857. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  858. break;
  859. case "Blog":
  860. //TODO:显示订阅电子报弹窗
  861. break;
  862. case "ComPDF":
  863. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  864. break;
  865. case "FeedBack":
  866. //调用邮箱 发送邮件
  867. StringBuilder sr = new StringBuilder();
  868. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  869. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  870. break;
  871. default:
  872. break;
  873. }
  874. if (!string.IsNullOrEmpty(url))
  875. {
  876. //需要跳转网页的情况
  877. System.Diagnostics.Process.Start(url);
  878. }
  879. }
  880. /// <summary>
  881. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  882. /// </summary>
  883. private void openfile()
  884. {
  885. OpenFileDialog openFileDialog = new OpenFileDialog();
  886. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  887. openFileDialog.Multiselect = true;
  888. if ((bool)openFileDialog.ShowDialog())
  889. {
  890. if (openFileDialog.FileNames.Count() == 1)
  891. {
  892. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  893. {
  894. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  895. }
  896. else
  897. {
  898. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  899. }
  900. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  901. }
  902. else
  903. {
  904. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  905. if (fileList.Count <= 0)
  906. {
  907. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  908. return;
  909. }
  910. mainViewModel.OpenFile(fileList[0]);
  911. for (int i = 1; i < fileList.Count(); i++)
  912. {
  913. if (!App.OpenedFileList.Contains(fileList[i]))
  914. {
  915. App.mainWindowViewModel.AddTabItem(fileList[i]);
  916. }
  917. ToolMethod.SetFileThumbImg(fileList[i]);
  918. }
  919. }
  920. }
  921. }
  922. /// <summary>
  923. /// 关闭当前窗体
  924. /// </summary>
  925. private void closeWindow()
  926. {
  927. App.Current.MainWindow.Close();
  928. }
  929. /// <summary>
  930. /// 转档
  931. /// </summary>
  932. /// <param name="obj"></param>
  933. private void convert(string obj)
  934. {
  935. if (!string.IsNullOrEmpty(obj))
  936. {
  937. DialogParameters value = new DialogParameters();
  938. value.Add(ParameterNames.PDFViewer, PDFViewer);
  939. switch (obj)
  940. {
  941. case "Word":
  942. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  943. {
  944. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  945. converterDialogsModel.OnOpened((DialogResult)e);
  946. });
  947. break;
  948. case "Excel":
  949. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  950. {
  951. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  952. converterDialogsModel.OnOpened((DialogResult)e);
  953. });
  954. break;
  955. case "PPT":
  956. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  957. {
  958. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  959. converterDialogsModel.OnOpened((DialogResult)e);
  960. });
  961. break;
  962. case "RTF":
  963. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  964. {
  965. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  966. converterDialogsModel.OnOpened((DialogResult)e);
  967. });
  968. break;
  969. case "CSV":
  970. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  971. {
  972. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  973. converterDialogsModel.OnOpened((DialogResult)e);
  974. });
  975. break;
  976. case "HTML":
  977. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  978. {
  979. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  980. converterDialogsModel.OnOpened((DialogResult)e);
  981. });
  982. break;
  983. case "Text":
  984. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  985. {
  986. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  987. converterDialogsModel.OnOpened((DialogResult)e);
  988. });
  989. break;
  990. case "Image":
  991. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  992. {
  993. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  994. converterDialogsModel.OnOpened((DialogResult)e);
  995. });
  996. break;
  997. default:
  998. break;
  999. }
  1000. }
  1001. }
  1002. /// <summary>
  1003. /// 解密
  1004. /// </summary>
  1005. private void decrypt()
  1006. {
  1007. ///无可用安全性设置的原因:
  1008. ///文件本身无安全性设置,且没有设置过密码
  1009. ///文件安全性已经被重置
  1010. ///
  1011. if ((!PDFViewer.Document.IsEncrypted && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
  1012. {
  1013. AlertsMessage alertsMessage = new AlertsMessage();
  1014. alertsMessage.ShowDialog("", "No security settings available ", "OK");
  1015. }
  1016. else
  1017. {
  1018. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1019. if (result.IsDiscryptied)
  1020. {
  1021. if (result.Password != null)
  1022. {
  1023. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1024. }
  1025. ShowLeftTip(false);
  1026. DialogParameters value = new DialogParameters();
  1027. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1028. value.Add(ParameterNames.ViewContentViewModel, this);
  1029. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
  1030. {
  1031. if (e.Result == ButtonResult.OK)
  1032. {
  1033. if (SecurityInfo.IsPasswordRemoved)
  1034. {
  1035. PDFViewer.UndoManager.CanSave = true;
  1036. }
  1037. ShowLeftTip(false);
  1038. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1039. }
  1040. });
  1041. }
  1042. }
  1043. }
  1044. /// <summary>
  1045. /// 加密
  1046. /// </summary>
  1047. private void encrypt()
  1048. {
  1049. if (!this.SecurityInfo.IsPasswordChanged)
  1050. {
  1051. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1052. if (result.IsDiscryptied)
  1053. {
  1054. if (result.Password != null)
  1055. {
  1056. if (PDFViewer.Document.UnlockWithPassword(result.Password))
  1057. {
  1058. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1059. }
  1060. }
  1061. }
  1062. }
  1063. DialogParameters value = new DialogParameters();
  1064. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1065. value.Add(ParameterNames.ViewContentViewModel, this);
  1066. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1067. {
  1068. if (e.Result == ButtonResult.OK)
  1069. {
  1070. SecurityHelper.IsPasswordChanged = true;
  1071. if (this.SecurityInfo.IsPasswordChanged)
  1072. {
  1073. this.PDFViewer.UndoManager.CanSave = true;
  1074. }
  1075. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1076. }
  1077. });
  1078. }
  1079. /// <summary>
  1080. /// 合并
  1081. /// </summary>
  1082. private void mergeFile()
  1083. {
  1084. DialogParameters value = new DialogParameters();
  1085. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1086. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1087. }
  1088. /// <summary>
  1089. /// 压缩
  1090. /// </summary>
  1091. private void compress()
  1092. {
  1093. DialogParameters value = new DialogParameters();
  1094. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1095. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1096. {
  1097. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1098. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1099. });
  1100. }
  1101. /// <summary>
  1102. /// 设置Tip状态栏的显示状态
  1103. /// </summary>
  1104. /// <param name="show">是否显示</param>
  1105. public void ShowTip(bool show)
  1106. {
  1107. if (show)
  1108. {
  1109. TipVisible = Visibility.Visible;
  1110. }
  1111. else
  1112. {
  1113. TipVisible = Visibility.Collapsed;
  1114. }
  1115. }
  1116. /// <summary>
  1117. /// 设置LeftTip状态栏的显示状态
  1118. /// </summary>
  1119. /// <param name="show">是否显示</param>
  1120. public void ShowLeftTip(bool show)
  1121. {
  1122. if (show)
  1123. {
  1124. LeftTipVisible = Visibility.Visible;
  1125. }
  1126. else
  1127. {
  1128. LeftTipVisible = Visibility.Collapsed;
  1129. }
  1130. }
  1131. public void CheckHaveAllPermission()
  1132. {
  1133. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1134. {
  1135. ShowLeftTip(true);
  1136. NavigationParameters param = new NavigationParameters();
  1137. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1138. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1139. }
  1140. }
  1141. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1142. {
  1143. switch (showTipEventArgs.enumTipKind)
  1144. {
  1145. case EnumTipKind.StatusNone:
  1146. ShowLeftTip(false);
  1147. break;
  1148. case EnumTipKind.StatusSetPasswordSuccessfully:
  1149. ShowLeftTip(true);
  1150. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1151. break;
  1152. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1153. ShowLeftTip(false);
  1154. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1155. IsLoading = Visibility.Collapsed;
  1156. ShowTip(true);
  1157. await Task.Delay(3000);
  1158. //ReadModelTip = Visibility.Collapsed;
  1159. TipVisible = Visibility.Collapsed;
  1160. break;
  1161. default: break;
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// 右键菜单创建链接
  1166. /// </summary>
  1167. /// <param name="obj"></param>
  1168. private void CreateLinkEvent(object obj)
  1169. {
  1170. if (obj is object[] objArry)
  1171. {
  1172. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1173. {
  1174. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1175. linkArgs.URI = string.Empty;
  1176. linkArgs.LinkType = LINK_TYPE.GOTO;
  1177. linkArgs.PageIndex = annotCommand.PageIndex;
  1178. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1179. this.IsRightMenuCreateLink = true;
  1180. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1181. lists.Add(linkArgs);
  1182. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1183. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1184. PDFViewer.SetToolParam(annotArgs);
  1185. this.IsPropertyOpen = true;
  1186. }
  1187. }
  1188. }
  1189. private void CloseProperty()
  1190. {
  1191. FromClick = true;
  1192. IsPropertyOpen = false;
  1193. FromClick = false;
  1194. }
  1195. /// <summary>
  1196. /// 在文件资源管理器中显示
  1197. /// </summary>
  1198. private void ShowInFolder()
  1199. {
  1200. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1201. }
  1202. private void property()
  1203. {
  1204. DialogParameters valuePairs = new DialogParameters();
  1205. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1206. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1207. }
  1208. private void share()
  1209. {
  1210. try
  1211. {
  1212. var path = PDFViewer.Document.FilePath;
  1213. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  1214. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1215. }
  1216. catch
  1217. {
  1218. AlertsMessage alertsMessage = new AlertsMessage();
  1219. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  1220. }
  1221. }
  1222. private void SettingsEvent()
  1223. {
  1224. DialogParameters value = new DialogParameters();
  1225. value.Add(ParameterNames.ViewContentViewModel, this);
  1226. AnnotToolContentViewModel annotToolContent = null;
  1227. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1228. {
  1229. var views = region.Regions[ToolsBarContentRegionName].Views;
  1230. var isHas = views.FindFirst(q => q is AnnotToolContent);
  1231. if (isHas is AnnotToolContent annotTool)
  1232. {
  1233. annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
  1234. }
  1235. }
  1236. dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
  1237. {
  1238. var annotate = Settings.Default.AppProperties.Annotate;
  1239. if (annotToolContent != null)
  1240. {
  1241. //与注释联动修改颜色
  1242. UpdateFreeHand(annotate, annotToolContent);
  1243. UpdateTextHighlight(annotate, annotToolContent);
  1244. UpdateUnderLine(annotate, annotToolContent);
  1245. UpdateStrikethrough(annotate, annotToolContent);
  1246. UpdateLine(annotate, annotToolContent);
  1247. UpdateArrow(annotate, annotToolContent);
  1248. }
  1249. });
  1250. if (PDFViewer != null)
  1251. {
  1252. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1253. }
  1254. if (Settings.Default.AppProperties.Description.AutoSave)
  1255. {
  1256. StartAutoSave();
  1257. }
  1258. else
  1259. {
  1260. CloseAutoSave();
  1261. }
  1262. }
  1263. private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1264. {
  1265. Color color2 = annotate.ArrowColor;
  1266. Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
  1267. bool flag = ColorComparison(color2, color1);
  1268. if (flag)
  1269. {
  1270. annotToolContent.ArrowColor = new SolidColorBrush(color2);
  1271. if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
  1272. {
  1273. if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
  1274. {
  1275. annotArgs.LineColor = color2;
  1276. }
  1277. }
  1278. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1279. {
  1280. CreateRefreshComment(annotToolContent);
  1281. }
  1282. }
  1283. }
  1284. private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1285. {
  1286. Color color2 = annotate.LineColor;
  1287. Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
  1288. bool flag = ColorComparison(color2, color1);
  1289. if (flag)
  1290. {
  1291. annotToolContent.LineColor = new SolidColorBrush(color2);
  1292. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
  1293. {
  1294. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
  1295. {
  1296. annotArgs.LineColor = color2;
  1297. }
  1298. }
  1299. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1300. {
  1301. CreateRefreshComment(annotToolContent);
  1302. }
  1303. }
  1304. }
  1305. private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1306. {
  1307. Color color2 = annotate.StrikethroughColor;
  1308. Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
  1309. bool flag = ColorComparison(color2, color1);
  1310. if (flag)
  1311. {
  1312. annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
  1313. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1314. {
  1315. CreateRefreshComment(annotToolContent);
  1316. }
  1317. }
  1318. }
  1319. private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1320. {
  1321. Color color2 = annotate.UnderLineColor;
  1322. Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
  1323. bool flag = ColorComparison(color2, color1);
  1324. if (flag)
  1325. {
  1326. annotToolContent.UnderLineColor = new SolidColorBrush(color2);
  1327. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1328. {
  1329. CreateRefreshComment(annotToolContent);
  1330. }
  1331. }
  1332. }
  1333. private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1334. {
  1335. Color color2 = annotate.HighLightColor;
  1336. Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
  1337. bool flag = ColorComparison(color2, color1);
  1338. if (flag)
  1339. {
  1340. annotToolContent.HighLightColor = new SolidColorBrush(color2);
  1341. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1342. {
  1343. CreateRefreshComment(annotToolContent);
  1344. }
  1345. }
  1346. }
  1347. private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1348. {
  1349. Color color2 = annotate.FreeHandColor;
  1350. Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
  1351. bool flag = ColorComparison(color2, color1);
  1352. if (flag)
  1353. {
  1354. annotToolContent.FreeHandColor = new SolidColorBrush(color2);
  1355. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
  1356. {
  1357. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
  1358. {
  1359. freehandAnnotArgs.InkColor = color2;
  1360. }
  1361. }
  1362. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1363. {
  1364. CreateRefreshComment(annotToolContent);
  1365. }
  1366. }
  1367. }
  1368. private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
  1369. {
  1370. AnnotHandlerEventArgs annotArgs = null;
  1371. string tag = annotToolContent.StrAnnotToolChecked;
  1372. annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
  1373. if (annotArgs != null)
  1374. {
  1375. //设置点击页面会创建对应选中注释工具的注释
  1376. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1377. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1378. PDFViewer.SetToolParam(annotArgs);
  1379. }
  1380. }
  1381. private bool ColorComparison(Color color2, Color color1)
  1382. {
  1383. if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
  1384. && color1.A == color2.A)
  1385. {
  1386. return false;
  1387. }
  1388. else
  1389. {
  1390. return true;
  1391. }
  1392. }
  1393. private bool CanSaveExcute()
  1394. {
  1395. return CanSave;
  1396. }
  1397. private void MenuEnterReadModeEvent(object obj)
  1398. {
  1399. }
  1400. public void ShowPrintDialog()
  1401. {
  1402. DialogParameters printValue = new DialogParameters();
  1403. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1404. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1405. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1406. printValue.Add(ParameterNames.Unicode, unicode);
  1407. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1408. }
  1409. public void SelectClick()
  1410. {
  1411. if (OpenBOTA == false)
  1412. {
  1413. OpenBOTA = true;
  1414. }
  1415. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1416. if (isBook == false)
  1417. {
  1418. bOTAContent.TabItemSearch.IsSelected = true;
  1419. }
  1420. }
  1421. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1422. {
  1423. bool isTabItem = false;
  1424. bOTAContentViewModel = null;
  1425. bOTAContent = null;
  1426. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1427. {
  1428. var views = region.Regions[this.BOTARegionName].Views;
  1429. var model = views.FirstOrDefault(q => q is BOTAContent);
  1430. if (model is BOTAContent bOTAContent1)
  1431. {
  1432. bOTAContent = bOTAContent1;
  1433. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1434. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1435. {
  1436. isTabItem = true;
  1437. }
  1438. }
  1439. }
  1440. return isTabItem;
  1441. }
  1442. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1443. {
  1444. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1445. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1446. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1447. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1448. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  1449. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1450. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1451. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1452. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1453. }
  1454. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1455. {
  1456. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1457. dictionary.Add("TabItemTool", "ToolsBarContent");
  1458. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1459. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1460. dictionary.Add("TabItemScan", "ScanContent");
  1461. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1462. dictionary.Add("TabItemForm", "FormsToolContent");
  1463. dictionary.Add("TabItemFill", "FillAndSignContent");
  1464. }
  1465. private void UpdateShowContent(string currentBar)
  1466. {
  1467. ToolContentVisible = Visibility.Collapsed;
  1468. ToolsBarContentVisible = Visibility.Collapsed;
  1469. ToolsBarContentVisible = Visibility.Collapsed;
  1470. TextEditToolContentVisible = Visibility.Collapsed;
  1471. OCRContentVisible = Visibility.Collapsed;
  1472. switch (currentBar)
  1473. {
  1474. case "TabItemAnnotation":
  1475. case "TabItemTool":
  1476. case "TabItemForm":
  1477. case "TabItemFill":
  1478. ToolsBarContentVisible = Visibility.Visible;
  1479. break;
  1480. case "TabItemScan":
  1481. ToolsBarContentVisible = Visibility.Visible;
  1482. OCRContentVisible = Visibility.Visible;
  1483. break;
  1484. case "TabItemEdit":
  1485. TextEditToolContentVisible = Visibility.Visible;
  1486. break;
  1487. case "TabItemConvert":
  1488. ToolsBarContentVisible = Visibility.Visible;
  1489. break;
  1490. case "TabItemPageEdit":
  1491. case "HeaderFooterContent":
  1492. case "BatesContent":
  1493. case "WatermarkContent":
  1494. case "BackgroundContent":
  1495. case "RedactionContent":
  1496. ToolContentVisible = Visibility.Visible;
  1497. break;
  1498. default:
  1499. break;
  1500. }
  1501. PDFEditMode(currentBar);
  1502. FormMode(currentBar);
  1503. }
  1504. private void PDFEditMode(string currentBar)
  1505. {
  1506. if (currentBar == "TabItemEdit")
  1507. {
  1508. if (PDFViewer != null)
  1509. {
  1510. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1511. //SelectedPrpoertyPanel("TextEditProperty", null);
  1512. //IsPropertyOpen = true;
  1513. }
  1514. }
  1515. else
  1516. {
  1517. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1518. {
  1519. IsPropertyOpen = false;
  1520. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1521. }
  1522. }
  1523. }
  1524. private void FormMode(string currentBar)
  1525. {
  1526. if (currentBar == "TabItemForm")
  1527. {
  1528. if (PDFViewer != null)
  1529. {
  1530. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1531. }
  1532. }
  1533. else
  1534. {
  1535. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1536. {
  1537. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1538. }
  1539. }
  1540. }
  1541. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1542. {
  1543. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1544. if (e.PropertyName == "CanUndo")
  1545. {
  1546. CanUndo = PDFViewer.UndoManager.CanUndo;
  1547. }
  1548. if (e.PropertyName == "CanRedo")
  1549. {
  1550. CanRedo = PDFViewer.UndoManager.CanRedo;
  1551. }
  1552. if (e.PropertyName == "CanSave")
  1553. {
  1554. CanSave = PDFViewer.UndoManager.CanSave;
  1555. }
  1556. }
  1557. /// <summary>
  1558. /// 选项卡切换事件
  1559. /// </summary>
  1560. /// <param name="e"></param>
  1561. private void TabControlSelectonChangedEvent(object e)
  1562. {
  1563. var args = e as SelectionChangedEventArgs;
  1564. if (args != null)
  1565. {
  1566. var item = args.AddedItems[0] as TabItem;
  1567. CurrentBar = item.Name;
  1568. if (previousBar != CurrentBar)
  1569. {
  1570. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1571. {
  1572. EnterPageEdit();
  1573. }
  1574. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1575. {
  1576. EnterSelectedBar(CurrentBar);
  1577. isInPageEdit = false;
  1578. }
  1579. previousBar = CurrentBar;
  1580. }
  1581. }
  1582. }
  1583. /// <summary>
  1584. /// 进入页面编辑模式
  1585. /// </summary>
  1586. public void EnterPageEdit()
  1587. {
  1588. if (TabSelectedIndex != 1)
  1589. {
  1590. TabSelectedIndex = 1;
  1591. }
  1592. CurrentBar = "TabItemPageEdit";
  1593. EnterToolMode(barContentByTabItem[CurrentBar]);
  1594. isInPageEdit = true;
  1595. }
  1596. /// <summary>
  1597. /// 阅读模式
  1598. /// </summary>
  1599. /// <param name="viewContent"></param>
  1600. public async void On_ReadMode()
  1601. {
  1602. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1603. mainViewModel.IsBookMode = true;
  1604. IsLoading = Visibility.Visible;
  1605. await Task.Delay(1);
  1606. PDFViewer.DisableClearSelectAnnot(false);
  1607. PDFViewer.ClearSelectAnnots();
  1608. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1609. #region 旧版本
  1610. //NavigationParameters param = new NavigationParameters();
  1611. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  1612. //param.Add(ParameterNames.ViewContentViewModel, this);
  1613. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1614. ////ShowContent(CurrentBar, true);
  1615. //if (GridToolRow != 0)
  1616. //{
  1617. // GridToolRow = 0;
  1618. //}
  1619. //if (GridToolRowSpan != 4)
  1620. //{
  1621. // GridToolRowSpan = 4;
  1622. //}
  1623. ////isInPageEdit = true;
  1624. //UpdateShowContent("TabItemPageEdit");
  1625. #endregion 旧版本
  1626. OpenBOTA = false;
  1627. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  1628. //模拟一次用户点击 关闭属性面板
  1629. //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
  1630. FromClick = true;
  1631. IsPropertyOpen = false;
  1632. FromClick = false;
  1633. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1634. {
  1635. var views = region.Regions[TipContentRegionName].Views;
  1636. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  1637. if (isHasView == null)
  1638. {
  1639. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  1640. }
  1641. else
  1642. {
  1643. region.Regions[TipContentRegionName].Activate(isHasView);
  1644. }
  1645. }
  1646. IsLoading = Visibility.Collapsed;
  1647. ShowTip(true);
  1648. await Task.Delay(3000);
  1649. TipVisible = Visibility.Collapsed;
  1650. }
  1651. /// <summary>
  1652. /// 退出阅读模式
  1653. /// </summary>
  1654. public async void Off_ReadModel()
  1655. {
  1656. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1657. mainViewModel.IsBookMode = false;
  1658. IsLoading = Visibility.Visible;
  1659. await Task.Delay(1);
  1660. //PDFViewer.MouseMode = MouseModes.None;
  1661. #region 旧版本
  1662. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1663. //{
  1664. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1665. // {
  1666. // var contentRegion = region.Regions[ViwerRegionName];
  1667. // contentRegion.Remove(PDFViewer);
  1668. // }
  1669. // //还原背景色
  1670. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1671. // region.AddToRegion(ViwerRegionName, PDFViewer);
  1672. //}
  1673. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1674. //{
  1675. // EnterSelectedBar("TabItemAnnotation");
  1676. //}
  1677. //else
  1678. //{
  1679. // EnterSelectedBar(CurrentBar);
  1680. //}
  1681. #endregion 旧版本
  1682. //还原背景色
  1683. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1684. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  1685. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1686. {
  1687. var views = region.Regions[TipContentRegionName].Views;
  1688. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  1689. if (isHasView == null)
  1690. {
  1691. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1692. }
  1693. else
  1694. {
  1695. region.Regions[TipContentRegionName].Activate(isHasView);
  1696. }
  1697. }
  1698. ///退出阅读模式 显示视图面板
  1699. //IsPropertyOpen = true;
  1700. //if (region.Regions.ContainsRegionWithName(PropertyRegionName))
  1701. //{
  1702. // NavigationParameters param = new NavigationParameters();
  1703. // param.Add(ParameterNames.PDFViewer, PDFViewer);
  1704. // param.Add(ParameterNames.BottomToolContentViewModel, this);
  1705. // region.RequestNavigate(RegionNames.PropertyRegionName, "ViewModularContent", param);
  1706. //}
  1707. if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  1708. {
  1709. var views = region.Regions[BottomToolRegionName].Views;
  1710. var isHasView = views.FindFirst(q => q is BottomToolContent);
  1711. if (isHasView is BottomToolContent bottomToolContent)
  1712. {
  1713. BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  1714. toolContentViewModel.IsShowViewModular = false;
  1715. }
  1716. }
  1717. IsLoading = Visibility.Collapsed;
  1718. PDFViewer.DisableClearSelectAnnot(false);
  1719. PDFViewer.ClearSelectAnnots();
  1720. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1721. ShowTip(true);
  1722. await Task.Delay(3000);
  1723. //ReadModelTip = Visibility.Collapsed;
  1724. TipVisible = Visibility.Collapsed;
  1725. }
  1726. #region PDFViewer鼠标滚轮缩放事件
  1727. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  1728. {
  1729. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  1730. PDFViewer.Zoom(newZoom);
  1731. }
  1732. public double CheckZoomLevel(double zoom, bool IsGrowth)
  1733. {
  1734. double standardZoom = 100;
  1735. if (zoom <= 0.01)
  1736. {
  1737. return 0.01;
  1738. }
  1739. if (zoom >= 10)
  1740. {
  1741. return 10;
  1742. }
  1743. zoom *= 100;
  1744. for (int i = 0; i < zoomLevel.Length - 1; i++)
  1745. {
  1746. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  1747. {
  1748. standardZoom = zoomLevel[i + 1];
  1749. break;
  1750. }
  1751. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  1752. {
  1753. standardZoom = zoomLevel[i];
  1754. break;
  1755. }
  1756. }
  1757. return standardZoom / 100;
  1758. }
  1759. #endregion PDFViewer鼠标滚轮缩放事件
  1760. #region 方法
  1761. /// <summary>
  1762. /// 快捷键
  1763. /// </summary>
  1764. /// <param name="sender"></param>
  1765. /// <param name="e"></param>
  1766. /// <exception cref="NotImplementedException"></exception>
  1767. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1768. {
  1769. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1770. {
  1771. if (mainViewModel.IsBookMode == true)
  1772. {
  1773. Off_ReadModel();
  1774. }
  1775. //内容选择 退出
  1776. if (PDFViewer.MouseMode != MouseModes.PanTool)
  1777. {
  1778. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1779. if (annotToolContent != null && toolContentViewModel != null)
  1780. {
  1781. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1782. {
  1783. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  1784. {
  1785. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  1786. annotToolContent.BtnSelecttool.IsChecked = false;
  1787. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1788. }
  1789. }
  1790. }
  1791. }
  1792. }
  1793. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  1794. {
  1795. //内容选择 复制 快捷键
  1796. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1797. if (annotToolContent != null && toolContentViewModel != null)
  1798. {
  1799. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1800. {
  1801. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  1802. }
  1803. }
  1804. }
  1805. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  1806. {
  1807. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  1808. if (annotToolContent != null && toolContentViewModel != null)
  1809. {
  1810. if (annotToolContent.BtnSelecttool.IsChecked == true)
  1811. {
  1812. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  1813. }
  1814. }
  1815. }
  1816. }
  1817. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  1818. {
  1819. AnnotToolContent toolContent = null;
  1820. toolContentViewModel = null;
  1821. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1822. {
  1823. var views = region.Regions[ToolsBarContentRegionName].Views;
  1824. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  1825. if (model is AnnotToolContent annotToolContent)
  1826. {
  1827. toolContent = annotToolContent;
  1828. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  1829. }
  1830. }
  1831. return toolContent;
  1832. }
  1833. /// <summary>
  1834. /// 视图面板 切换分屏模式
  1835. /// </summary>
  1836. /// <param name="mode"></param>
  1837. public void EnterSplitMode(SplitMode mode)
  1838. {
  1839. ///通知UI层更改布局
  1840. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  1841. }
  1842. private void Undo()
  1843. {
  1844. PDFViewer.UndoManager.Undo();
  1845. }
  1846. private void Redo()
  1847. {
  1848. PDFViewer.UndoManager.Redo();
  1849. }
  1850. private void LoadControl()
  1851. {
  1852. NavigationParameters parameters = new NavigationParameters();
  1853. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1854. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1855. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  1856. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1857. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  1858. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  1859. //TODO 根据上一次关闭记录的菜单,选中TabItem
  1860. EnterSelectedBar("TabItemAnnotation");
  1861. //}
  1862. //));
  1863. }
  1864. /// <summary>
  1865. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  1866. /// </summary>
  1867. /// <param name="Content"></param>
  1868. /// <param name="annotPropertyPanel"></param>
  1869. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  1870. {
  1871. if (Content == "PropertyPanelContent")
  1872. {
  1873. IsPropertyOpen = false;
  1874. }
  1875. else
  1876. {
  1877. IsPropertyOpen = true;
  1878. }
  1879. NavigationParameters parameters = new NavigationParameters();
  1880. //传其他参数:文档类,空注释面板;
  1881. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1882. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  1883. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1884. region.RequestNavigate(PropertyRegionName, Content, parameters);
  1885. }
  1886. /// <summary>
  1887. /// 将PDFViwer添加到Region
  1888. /// </summary>
  1889. private bool loadFile()
  1890. {
  1891. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  1892. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  1893. CanSave = PDFViewer.UndoManager.CanSave;
  1894. CanUndo = PDFViewer.UndoManager.CanUndo;
  1895. CanRedo = PDFViewer.UndoManager.CanRedo;
  1896. if(!CheckPassword())
  1897. {
  1898. return false;
  1899. }
  1900. PDFViewer.Load();
  1901. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  1902. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1903. //设置移动注释参考线
  1904. ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"),1);
  1905. //还原上一次关闭前的视图设置
  1906. GetOpenFileInfo();
  1907. if (!string.IsNullOrEmpty(PassWord))
  1908. {
  1909. //加密文档解密后刷新底部工具栏页码总数
  1910. NavigationParameters parameters = new NavigationParameters();
  1911. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  1912. parameters.Add(ParameterNames.ViewContentViewModel, this);
  1913. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  1914. }
  1915. region.AddToRegion(ViwerRegionName, PDFViewer);
  1916. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  1917. {
  1918. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  1919. }
  1920. return true;
  1921. }
  1922. /// <summary>
  1923. /// 处理密码相关的内容
  1924. /// </summary>
  1925. private bool CheckPassword()
  1926. {
  1927. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  1928. {
  1929. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  1930. {
  1931. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  1932. }
  1933. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
  1934. {
  1935. IsFileLocked = true;
  1936. NavigationParameters param = new NavigationParameters();
  1937. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1938. param.Add(ParameterNames.ViewContentViewModel, this);
  1939. ShowLeftTip(true);
  1940. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1941. }
  1942. }
  1943. else
  1944. {
  1945. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  1946. if (result.IsDiscryptied)
  1947. {
  1948. if (result.Password != null)
  1949. {
  1950. string filePath = PDFViewer.Document.FilePath;
  1951. PDFViewer.Document.UnlockWithPassword(result.Password);
  1952. PDFViewer.Tag = result.Password;
  1953. //记录密码到内存
  1954. this.PassWord = result.Password;
  1955. }
  1956. }
  1957. if (result.IsDiscryptied == false)
  1958. {
  1959. //未成功解密文档时,释放Document对象,返回
  1960. PDFViewer.Document.Release();
  1961. //取消解密时关闭当前页签
  1962. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  1963. return false;
  1964. }
  1965. }
  1966. return true;
  1967. }
  1968. /// <summary>
  1969. /// 还原上一次浏览的视图相关设置
  1970. /// </summary>
  1971. private void GetOpenFileInfo()
  1972. {
  1973. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  1974. //偏好设置里设置了记录上次视图设置时
  1975. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  1976. {
  1977. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  1978. {
  1979. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  1980. }
  1981. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  1982. {
  1983. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  1984. }
  1985. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  1986. {
  1987. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  1988. }
  1989. if (OpenFileInfo.LastPageIndex != PDFViewer.CurrentIndex)
  1990. {
  1991. PDFViewer.GoToPage(OpenFileInfo.LastPageIndex);
  1992. }
  1993. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  1994. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  1995. if (OpenFileInfo.LastPageSpace)
  1996. {
  1997. PDFViewer.SetPageSpacing(8);
  1998. }
  1999. else
  2000. {
  2001. PDFViewer.SetPageSpacing(0);
  2002. }
  2003. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  2004. {
  2005. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  2006. }
  2007. else
  2008. {
  2009. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  2010. }
  2011. }
  2012. else
  2013. {
  2014. //新文档应用默认设置
  2015. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  2016. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  2017. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2018. }
  2019. }
  2020. /// <summary>
  2021. /// 已有路径文档的保存逻辑
  2022. /// </summary>
  2023. public bool saveFile()
  2024. {
  2025. try
  2026. {
  2027. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile)
  2028. return saveAsFile();
  2029. //文档已被修复时 提示另存为
  2030. if (PDFViewer.Document.HasRepaired)
  2031. {
  2032. AlertsMessage alertsMessage = new AlertsMessage();
  2033. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  2034. if (alertsMessage.result == ContentResult.Ok)
  2035. return saveAsFile();
  2036. else
  2037. return false;
  2038. }
  2039. //文件路径无法存在时
  2040. if (!File.Exists(PDFViewer.Document.FilePath))
  2041. {
  2042. AlertsMessage alertsMessage = new AlertsMessage();
  2043. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  2044. if (alertsMessage.result == ContentResult.Ok)
  2045. return saveAsFile();
  2046. else
  2047. return false;
  2048. }
  2049. //只读文件无法写入时,提示另存为
  2050. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  2051. if (fileInfo.IsReadOnly)
  2052. {
  2053. AlertsMessage alertsMessage = new AlertsMessage();
  2054. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  2055. if (alertsMessage.result == ContentResult.Ok)
  2056. return saveAsFile();
  2057. else
  2058. return false;
  2059. }
  2060. //Security Fixed:
  2061. //修改密码后原文档保存的步骤:
  2062. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  2063. //
  2064. if (SecurityInfo.IsPasswordChanged)
  2065. {
  2066. string currentFilePath = PDFViewer.Document.FilePath;
  2067. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  2068. string openPassword = string.Empty;
  2069. string permissionsPassword = string.Empty;
  2070. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2071. if (SecurityInfo.NeedOpenPassword)
  2072. {
  2073. openPassword = SecurityInfo.OpenPassword;
  2074. }
  2075. if (SecurityInfo.NeedPermissionsPassword)
  2076. {
  2077. permissionsPassword = SecurityInfo.PermissionsPassword;
  2078. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2079. }
  2080. try
  2081. {
  2082. string currentPath = PDFViewer.Document.FilePath;
  2083. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2084. if (PDFViewer.Document.Descrypt(tempPath))
  2085. {
  2086. PDFViewer.CloseDocument();
  2087. PDFViewer.InitDocument(tempPath);
  2088. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2089. if (PDFViewer.Document.WriteToFilePath(currentPath))
  2090. {
  2091. PDFViewer.CloseDocument();
  2092. PDFViewer.InitDocument(currentPath);
  2093. if (!string.IsNullOrEmpty(openPassword))
  2094. {
  2095. PDFViewer.Document.UnlockWithPassword(openPassword);
  2096. }
  2097. if (!string.IsNullOrEmpty(permissionsPassword) && openPassword != permissionsPassword)
  2098. {
  2099. //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  2100. IsFileLocked = true;
  2101. NavigationParameters param = new NavigationParameters();
  2102. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2103. param.Add(ParameterNames.ViewContentViewModel, this);
  2104. ShowLeftTip(true);
  2105. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2106. }
  2107. try
  2108. {
  2109. PDFViewer.Load();
  2110. }
  2111. catch
  2112. {
  2113. }
  2114. PDFViewer.UndoManager.CanSave = false;
  2115. SecurityInfo.IsPasswordChanged = false;
  2116. }
  2117. else
  2118. {
  2119. return false;
  2120. }
  2121. System.IO.File.Delete(tempPath);
  2122. }
  2123. else
  2124. {
  2125. return false;
  2126. }
  2127. return true;
  2128. }
  2129. catch
  2130. {
  2131. return false;
  2132. }
  2133. }
  2134. else if (SecurityInfo.IsPasswordRemoved)
  2135. {
  2136. try
  2137. {
  2138. string currentPath = PDFViewer.Document.FilePath;
  2139. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2140. PDFViewer.Document.Descrypt(tempPath);
  2141. PDFViewer.CloseDocument();
  2142. PDFViewer.InitDocument(tempPath);
  2143. PDFViewer.Document.WriteToFilePath(currentPath);
  2144. PDFViewer.CloseDocument();
  2145. PDFViewer.InitDocument(currentPath);
  2146. PDFViewer.Load();
  2147. System.IO.File.Delete(tempPath);
  2148. }
  2149. catch
  2150. {
  2151. return false;
  2152. }
  2153. }
  2154. bool result = PDFViewer.Document.WriteToLoadedPath();
  2155. if (result)
  2156. {
  2157. PDFViewer.UndoManager.CanSave = false;
  2158. App.Current.Dispatcher.Invoke(() =>
  2159. {
  2160. //保存时更新缩略图
  2161. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2162. try
  2163. {
  2164. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  2165. {
  2166. var size = PDFViewer.Document.GetPageSize(0);
  2167. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  2168. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  2169. if (File.Exists(folderPath))
  2170. File.Delete(folderPath);
  2171. DirectoryInfo folder = new DirectoryInfo(folderPath);
  2172. if (!folder.Exists)
  2173. folder.Create();
  2174. string imagePath = info.ThumbImgPath;
  2175. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  2176. {
  2177. string imageName = Guid.NewGuid().ToString();
  2178. imagePath = System.IO.Path.Combine(folderPath, imageName);
  2179. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  2180. {
  2181. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2182. }
  2183. }
  2184. else
  2185. {
  2186. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  2187. {
  2188. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2189. }
  2190. }
  2191. info.ThumbImgPath = imagePath;
  2192. SettingHelper.SetFileInfo(info);
  2193. }
  2194. }
  2195. catch
  2196. {
  2197. info.ThumbImgPath = null;
  2198. SettingHelper.SetFileInfo(info);
  2199. }
  2200. });
  2201. PDFViewer.ReloadDocument();
  2202. }
  2203. else
  2204. {
  2205. //文件被占用 保存失败时
  2206. AlertsMessage alertsMessage = new AlertsMessage();
  2207. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  2208. if (alertsMessage.result == ContentResult.Ok)
  2209. return saveAsFile();
  2210. else
  2211. return false;
  2212. }
  2213. return result;
  2214. }
  2215. catch { return false; }
  2216. finally
  2217. {
  2218. if (!IsFileLocked)
  2219. {
  2220. ShowLeftTip(false);
  2221. }
  2222. }
  2223. }
  2224. /// <summary>
  2225. /// 另存为或新文档保存逻辑
  2226. /// </summary>
  2227. public bool saveAsFile(Action RedactionAction = null)
  2228. {
  2229. var dlg = new Microsoft.Win32.SaveFileDialog();
  2230. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2231. dlg.FileName = PDFViewer.Document.FileName;
  2232. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2233. {
  2234. bool result = false;
  2235. if (RedactionAction != null)
  2236. {
  2237. //保存前进行标记密文处理应用或擦除
  2238. RedactionAction.Invoke();
  2239. }
  2240. if (App.OpenedFileList.Contains(dlg.FileName))
  2241. {
  2242. //提示文件已经被打开
  2243. }
  2244. else
  2245. {
  2246. string oldpath = PDFViewer.Document.FilePath;
  2247. string openPassword = string.Empty;
  2248. string permissionsPassword = string.Empty;
  2249. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2250. if (SecurityInfo.NeedOpenPassword)
  2251. {
  2252. openPassword = SecurityInfo.OpenPassword;
  2253. passwordInfo.OpenPassword = openPassword;
  2254. }
  2255. if (SecurityInfo.NeedPermissionsPassword)
  2256. {
  2257. permissionsPassword = SecurityInfo.PermissionsPassword;
  2258. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2259. passwordInfo.PermissionsPassword = permissionsPassword;
  2260. }
  2261. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2262. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2263. if (result)
  2264. {
  2265. mainViewModel.NewFile = false;
  2266. App.OpenedFileList.Remove(oldpath);
  2267. DoAfterSaveAs(dlg.FileName);
  2268. }
  2269. else
  2270. {
  2271. //提示文件被其他软件占用 无法保存
  2272. //
  2273. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2274. }
  2275. }
  2276. return result;
  2277. }
  2278. else
  2279. return false;
  2280. }
  2281. /// <summary>
  2282. /// 另存为Flatten
  2283. /// </summary>
  2284. private void saveAsFlatten()
  2285. {
  2286. var dlg = new SaveFileDialog();
  2287. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2288. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  2289. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2290. {
  2291. saveFile();
  2292. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  2293. if (kmdoc == null)
  2294. return;
  2295. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  2296. if (result)
  2297. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  2298. kmdoc.Release();
  2299. }
  2300. }
  2301. /// <summary>
  2302. /// 另存为后进行的操作
  2303. /// 重新打开新文档
  2304. /// </summary>
  2305. /// <param name="targetPath"></param>
  2306. public void DoAfterSaveAs(string targetPath)
  2307. {
  2308. PDFViewer.UndoManager.CanSave = false;
  2309. //从新路径重新加载
  2310. //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
  2311. PDFViewer.CloseDocument();
  2312. PDFViewer.InitDocument(targetPath);
  2313. //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
  2314. CheckPassword();
  2315. PDFViewer.Load();
  2316. //刷新最近文件列表
  2317. OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);
  2318. if (isnew == null)
  2319. {
  2320. if (App.OpenedFileList.Contains(targetPath) == false)
  2321. {
  2322. App.OpenedFileList.Add(targetPath);
  2323. }
  2324. }
  2325. //打开文件后,不管是新文件还是旧文件都需要更新排序
  2326. SettingHelper.SortRecentOpenFiles(targetPath);
  2327. //更新页签文件名
  2328. mainViewModel.FilePath = PDFViewer.Document.FilePath;
  2329. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2330. //刷新Bota 和底部工具栏的PDFviwer对象
  2331. LoadControl();
  2332. }
  2333. /// <summary>
  2334. /// 显示前添加内容到Region
  2335. /// </summary>
  2336. /// <param name="isPageEdit"></param>
  2337. private void ShowContent(string currentBar, bool isToolMode = false)
  2338. {
  2339. GridVisibility = Visibility.Visible;
  2340. //显示页面编辑或其他工具
  2341. if (currentBar == "TabItemPageEdit" || isToolMode)
  2342. {
  2343. if (currentBar == "TabItemPageEdit")//进入页面编辑
  2344. {
  2345. if (GridToolRow != 1)
  2346. {
  2347. GridToolRow = 1;
  2348. }
  2349. if (GridToolRowSpan != 3)
  2350. {
  2351. GridToolRowSpan = 3;
  2352. }
  2353. }
  2354. else//进入水印等其他工具模式
  2355. {
  2356. GridVisibility = Visibility.Collapsed;
  2357. if (GridToolRow != 0)
  2358. {
  2359. GridToolRow = 0;
  2360. }
  2361. if (GridToolRowSpan != 4)
  2362. {
  2363. GridToolRowSpan = 4;
  2364. }
  2365. }
  2366. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  2367. UpdateShowContent(currentBar);
  2368. }
  2369. else
  2370. {
  2371. if (GridToolRow != 1)
  2372. {
  2373. GridToolRow = 1;
  2374. }
  2375. UpdateShowContent(currentBar);
  2376. }
  2377. }
  2378. /// <summary>
  2379. /// 从二级工具栏进入需要修改界面布局的场景
  2380. /// </summary>
  2381. /// <param name="EditToolName"></param>
  2382. private void EnterEditTools(StringWithUnicode EditToolName)
  2383. {
  2384. EnterSelectedEditTool(EditToolName);
  2385. }
  2386. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  2387. {
  2388. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  2389. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  2390. {
  2391. PDFViewer.Document.ReleasePages();
  2392. PDFViewer.ReloadDocument();
  2393. }
  2394. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  2395. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  2396. {
  2397. region.AddToRegion(ViwerRegionName, PDFViewer);
  2398. }
  2399. CurrentBar = "TabItemTool";
  2400. EnterSelectedBar(CurrentBar);
  2401. }
  2402. /// <summary>
  2403. /// 二级菜单指定目标处理
  2404. /// </summary>
  2405. /// <param name="e"></param>
  2406. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  2407. {
  2408. CurrentBar = EditToolName.EditToolsContentName;
  2409. EnterToolMode(CurrentBar);
  2410. }
  2411. /// <summary>
  2412. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  2413. /// </summary>
  2414. /// <param name="targetToolMode">要导航过去的控件名称</param>
  2415. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  2416. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  2417. {
  2418. IsLoading = Visibility.Visible;
  2419. await Task.Delay(3);
  2420. NavigationParameters param = new NavigationParameters();
  2421. if (valuePairs == null)
  2422. {
  2423. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2424. param.Add(ParameterNames.ViewContentViewModel, this);
  2425. }
  2426. else//有传入其他内容的参数时
  2427. {
  2428. param = valuePairs;
  2429. }
  2430. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  2431. ShowContent(CurrentBar, true);
  2432. IsLoading = Visibility.Collapsed;
  2433. }
  2434. private void EnterSelectedBar(string currentBar)
  2435. {
  2436. NavigationParameters param = new NavigationParameters();
  2437. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2438. param.Add(ParameterNames.ViewContentViewModel, this);
  2439. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  2440. if (currentBar == "TabItemScan")
  2441. {
  2442. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  2443. }
  2444. ShowContent(currentBar);
  2445. }
  2446. /// <summary>
  2447. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  2448. /// </summary>
  2449. public void ExitToolMode()
  2450. {
  2451. ToolContentVisible = Visibility.Collapsed;
  2452. if (isInPageEdit)
  2453. {
  2454. TabSelectedIndex = 0;
  2455. isInPageEdit = false;
  2456. }
  2457. }
  2458. #endregion 方法
  2459. #region Navigate
  2460. public void OnNavigatedTo(NavigationContext navigationContext)
  2461. {
  2462. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  2463. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  2464. if (mainVM != null)
  2465. {
  2466. mainViewModel = mainVM;
  2467. mainViewModel.viewContentViewModel = this;
  2468. }
  2469. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  2470. if (pdfview != null)
  2471. {
  2472. PDFViewer = pdfview;
  2473. if (loadFile())
  2474. {
  2475. CheckHaveAllPermission();
  2476. }
  2477. }
  2478. //快捷键
  2479. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  2480. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  2481. //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
  2482. //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
  2483. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  2484. if (Settings.Default.IsNewInViewContent == true && App.IsLogin == false)
  2485. {
  2486. App.mainWindowViewModel.OpenRegister();
  2487. Settings.Default.IsNewInViewContent = false;
  2488. Settings.Default.Save();
  2489. }
  2490. //需要在pdfview赋值后绑定
  2491. GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
  2492. }
  2493. public bool IsNavigationTarget(NavigationContext navigationContext)
  2494. {
  2495. if (navigationContext != null)
  2496. {
  2497. //另存为打开导航进来时 不能新建一个实例
  2498. return true;
  2499. }
  2500. else
  2501. {
  2502. //一次性打开多个文件时,需要新建实例
  2503. return false;
  2504. }
  2505. }
  2506. public void OnNavigatedFrom(NavigationContext navigationContext)
  2507. {
  2508. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  2509. }
  2510. #endregion Navigate
  2511. }
  2512. }