ViewContentViewModel.cs 105 KB

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