ViewContentViewModel.cs 86 KB

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