ViewContentViewModel.cs 107 KB

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