ViewContentViewModel.cs 105 KB

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