ViewContentViewModel.cs 105 KB

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