ViewContentViewModel.cs 102 KB

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