ViewContentViewModel.cs 91 KB

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