ViewContentViewModel.cs 80 KB

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