ViewContentViewModel.cs 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536
  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;
  22. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Master.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Master.Model.Dialog.ConverterDialogs;
  27. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Master.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  34. using ImTools;
  35. using PDF_Master.Properties;
  36. using PDF_Master.ViewModels.BOTA;
  37. using PDF_Master.Views.BOTA;
  38. using System.Drawing;
  39. using PDF_Master.ViewModels.Tools.AnnotManager;
  40. using PDF_Master.Model.FillAndSign;
  41. using PDF_Master.Views.PropertyPanel.ViewModular;
  42. using PDF_Master.Views.PropertyPanel;
  43. using System.Windows.Threading;
  44. using Dropbox.Api.Files;
  45. using System.Windows.Media;
  46. using Color = System.Windows.Media.Color;
  47. using PDFSettings;
  48. using PDF_Master.Views;
  49. using System.Windows.Documents;
  50. using ComPDFKit.PDFPage;
  51. using ComPDFKitViewer;
  52. using SplitMode = PDF_Master.EventAggregators.SplitMode;
  53. using System.Windows.Resources;
  54. using System.Windows.Media.Imaging;
  55. using ComPDFKit.PDFWatermark;
  56. namespace PDF_Master.ViewModels
  57. {
  58. public class ViewContentViewModel : BindableBase, INavigationAware
  59. {
  60. #region 文案
  61. private string T_file;
  62. public string T_File
  63. {
  64. get { return T_file; }
  65. set
  66. {
  67. SetProperty(ref T_file, value);
  68. }
  69. }
  70. private string T_save;
  71. public string T_Save
  72. {
  73. get { return T_save; }
  74. set
  75. {
  76. SetProperty(ref T_save, value);
  77. }
  78. }
  79. private string T_undo;
  80. public string T_Undo
  81. {
  82. get { return T_undo; }
  83. set
  84. {
  85. SetProperty(ref T_undo, value);
  86. }
  87. }
  88. private string T_redo;
  89. public string T_Redo
  90. {
  91. get { return T_redo; }
  92. set
  93. {
  94. SetProperty(ref T_redo, value);
  95. }
  96. }
  97. private string T_annotation;
  98. public string T_Annotation
  99. {
  100. get { return T_annotation; }
  101. set
  102. {
  103. SetProperty(ref T_annotation, value);
  104. }
  105. }
  106. private string T_pageEdit;
  107. public string T_PageEdit
  108. {
  109. get { return T_pageEdit; }
  110. set
  111. {
  112. SetProperty(ref T_pageEdit, value);
  113. }
  114. }
  115. private string T_converter;
  116. public string T_Converter
  117. {
  118. get { return T_converter; }
  119. set
  120. {
  121. SetProperty(ref T_converter, value);
  122. }
  123. }
  124. private string T_fillSign;
  125. public string T_FillSign
  126. {
  127. get { return T_fillSign; }
  128. set
  129. {
  130. SetProperty(ref T_fillSign, value);
  131. }
  132. }
  133. private string T_tools;
  134. public string T_Tools
  135. {
  136. get { return T_tools; }
  137. set
  138. {
  139. SetProperty(ref T_tools, value);
  140. }
  141. }
  142. private string T_print;
  143. public string T_Print
  144. {
  145. get { return T_print; }
  146. set
  147. {
  148. SetProperty(ref T_print, value);
  149. }
  150. }
  151. private string T_share;
  152. public string T_Share
  153. {
  154. get { return T_share; }
  155. set
  156. {
  157. SetProperty(ref T_share, value);
  158. }
  159. }
  160. private string T_properties;
  161. public string T_Properties
  162. {
  163. get { return T_properties; }
  164. set
  165. {
  166. SetProperty(ref T_properties, value);
  167. }
  168. }
  169. private string _T_EditPDF;
  170. public string T_EditPDF
  171. {
  172. get { return _T_EditPDF; }
  173. set
  174. {
  175. SetProperty(ref _T_EditPDF, value);
  176. }
  177. }
  178. private void InitStirng()
  179. {
  180. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  181. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  182. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  183. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  184. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  185. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  186. T_EditPDF = App.MainPageLoader.GetString("ViewTopToolbar_T_EditPDF");
  187. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  188. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  189. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  190. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  191. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  192. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  193. }
  194. #endregion 文案
  195. #region 属性、变量
  196. /// <summary>
  197. /// 显示 隐藏注释
  198. /// </summary>
  199. public bool IsHiddenAnnot = false;
  200. public bool IsMultiSelected { get; set; } = false;
  201. public OpenFileInfo OpenFileInfo = null;
  202. public CPDFViewer PDFViewer { get; set; }
  203. public bool ReadModeIsShowProperty { get; set; } = false;
  204. public MainContentViewModel mainViewModel { get; set; }
  205. public BottomToolContentViewModel bottom { get; set; }
  206. public BOTAContentViewModel botaViewModel { get; set; }
  207. private CPDFWatermark watermark;
  208. public bool IsSettingOut = false;
  209. public IRegionManager region;
  210. public IDialogService dialogs;
  211. public IEventAggregator events;
  212. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  213. public string ViwerRegionName { get; set; }
  214. /// <summary>
  215. /// 分屏视图的region名称
  216. /// </summary>
  217. public string SplitViewerRegionName { get; set; }
  218. /// <summary>
  219. /// OCR视图名称
  220. /// </summary>
  221. public string OCRViewerRegionName { get; set; }
  222. public string BOTARegionName { get; set; }
  223. public string PropertyRegionName { get; set; }
  224. public string ToolContentRegionName { get; set; }
  225. public string ToolsBarContentRegionName { get; set; }
  226. /// <summary>
  227. /// 顶部提示的Content
  228. /// </summary>
  229. public string TipContentRegionName { get; set; }
  230. public string LeftTipContentRegionName { get; set; }
  231. //便签弹窗
  232. public string NotePopupRegionName { get; set; }
  233. public string ReadModeRegionName { get; set; }
  234. public string TextEditContentRegionName { get; set; }
  235. public string BackgroundContentRegionName { get; set; }
  236. public PasswordInfo PasswordInfo = new PasswordInfo();
  237. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  238. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  239. /// <summary>
  240. /// 签名列表
  241. /// </summary>
  242. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  243. /// <summary>
  244. /// 文档的密码
  245. /// </summary>
  246. public string PassWord { get; set; }
  247. public PasswordInfo passwordInfo = new PasswordInfo();
  248. private Visibility tipVisible = Visibility.Collapsed;
  249. /// <summary>
  250. /// 顶部提示栏的显示状态
  251. /// </summary>
  252. public bool IsFileLocked = false;
  253. public Visibility TipVisible
  254. {
  255. get { return tipVisible; }
  256. set
  257. {
  258. SetProperty(ref tipVisible, value);
  259. }
  260. }
  261. private Visibility leftTipVisible = Visibility.Collapsed;
  262. public Visibility LeftTipVisible
  263. {
  264. get { return leftTipVisible; }
  265. set
  266. {
  267. SetProperty(ref leftTipVisible, value);
  268. }
  269. }
  270. private Visibility notePopupVisible = Visibility.Collapsed;
  271. public Visibility NotePopupVisible
  272. {
  273. get { return notePopupVisible; }
  274. set
  275. {
  276. SetProperty(ref notePopupVisible, value);
  277. }
  278. }
  279. public bool IsNoteAdd = false;
  280. private double canvasNoteLeft;
  281. public double CanvasNoteLeft
  282. {
  283. get { return canvasNoteLeft; }
  284. set
  285. {
  286. SetProperty(ref canvasNoteLeft, value);
  287. }
  288. }
  289. private double canvasNoteBottom;
  290. public double CanvasNoteBottom
  291. {
  292. get { return canvasNoteBottom; }
  293. set
  294. {
  295. SetProperty(ref canvasNoteBottom, value);
  296. }
  297. }
  298. /// <summary>
  299. /// 底部工具栏 RegionName
  300. /// </summary>
  301. public string BottomToolRegionName { get; set; }
  302. private bool _isInPageEdit = false;
  303. /// <summary>
  304. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  305. /// </summary>
  306. public bool isInPageEdit
  307. {
  308. get { return _isInPageEdit; }
  309. set
  310. {
  311. SetProperty(ref _isInPageEdit, value);
  312. }
  313. }
  314. public Action PageEditUndo { get; set; }
  315. public Action PageEditRedo { get; set; }
  316. /// <summary>
  317. ///工具条
  318. ///0:收起
  319. ///40:显示
  320. /// </summary>
  321. private int toolRowHeight = 40;
  322. public int ToolRowHeight
  323. {
  324. get { return toolRowHeight; }
  325. set
  326. {
  327. SetProperty(ref toolRowHeight, value);
  328. }
  329. }
  330. private GridLength _ToolTooRow = new GridLength(40);
  331. public GridLength ToolTooRow
  332. {
  333. get { return _ToolTooRow; }
  334. set
  335. {
  336. SetProperty(ref _ToolTooRow, value);
  337. }
  338. }
  339. /// <summary>
  340. /// 水印,背景侧边栏宽度
  341. /// 0:收起
  342. /// 260:显示
  343. /// </summary>
  344. private int propertyColumnWidth = 0;
  345. public int PropertyColumnWidth
  346. {
  347. get { return propertyColumnWidth; }
  348. set
  349. {
  350. SetProperty(ref propertyColumnWidth, value);
  351. }
  352. }
  353. private int gridToolRow = 1;
  354. /// <summary>
  355. /// 控制ToolContent的Row
  356. /// </summary>
  357. public int GridToolRow
  358. {
  359. get { return gridToolRow; }
  360. set
  361. {
  362. SetProperty(ref gridToolRow, value);
  363. }
  364. }
  365. private int gridToolRowSpan = 3;
  366. /// <summary>
  367. /// 控制ToolContent的RowSpan
  368. /// </summary>
  369. public int GridToolRowSpan
  370. {
  371. get { return gridToolRowSpan; }
  372. set
  373. {
  374. SetProperty(ref gridToolRowSpan, value);
  375. }
  376. }
  377. private Visibility toolContentVisible = Visibility.Collapsed;
  378. /// <summary>
  379. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  380. /// 留意:显示前需要先注入内容、设置好行和跨行数
  381. /// </summary>
  382. public Visibility ToolContentVisible
  383. {
  384. get { return toolContentVisible; }
  385. set
  386. {
  387. SetProperty(ref toolContentVisible, value);
  388. }
  389. }
  390. private Visibility gridVisibility = Visibility.Visible;
  391. /// <summary>
  392. /// 是否正在加载中
  393. /// </summary>
  394. public Visibility GridVisibility
  395. {
  396. get { return gridVisibility; }
  397. set
  398. {
  399. SetProperty(ref gridVisibility, value);
  400. }
  401. }
  402. private Visibility isLoading = Visibility.Collapsed;
  403. private Visibility ocrContentVisible = Visibility.Collapsed;
  404. public Visibility OCRContentVisible
  405. {
  406. get { return ocrContentVisible; }
  407. set
  408. {
  409. SetProperty(ref ocrContentVisible, value);
  410. }
  411. }
  412. /// <summary>
  413. /// 是否正在加载中
  414. /// </summary>
  415. public Visibility IsLoading
  416. {
  417. get { return isLoading; }
  418. set
  419. {
  420. SetProperty(ref isLoading, value);
  421. }
  422. }
  423. private Visibility converterBarContentVisible = Visibility.Collapsed;
  424. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  425. ///// <summary>
  426. ///// 控制ToolsBarContent的显示
  427. ///// 留意:显示前需要先注入内容、设置好行和跨行数
  428. ///// </summary>
  429. //public Visibility ConverterBarContentVisible
  430. //{
  431. // get { return converterBarContentVisible; }
  432. // set
  433. // {
  434. // SetProperty(ref converterBarContentVisible, value);
  435. // }
  436. //}
  437. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  438. /// <summary>
  439. /// 控制ToolsBarContent的显示
  440. /// 留意:显示前需要先注入内容、设置好行和跨行数
  441. /// </summary>
  442. public Visibility ToolsBarContentVisible
  443. {
  444. get { return toolsBarContentVisible; }
  445. set
  446. {
  447. SetProperty(ref toolsBarContentVisible, value);
  448. }
  449. }
  450. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  451. /// <summary>
  452. /// 控制ToolsBarContent的显示
  453. /// 留意:显示前需要先注入内容、设置好行和跨行数
  454. /// </summary>
  455. public Visibility TextEditToolContentVisible
  456. {
  457. get { return textEditToolContentVisible; }
  458. set
  459. {
  460. SetProperty(ref textEditToolContentVisible, value);
  461. }
  462. }
  463. private bool isPorpertyOpen = false;
  464. /// <summary>
  465. /// 属性栏是否展开
  466. /// </summary>
  467. public bool IsPropertyOpen
  468. {
  469. get { return isPorpertyOpen; }
  470. set
  471. {
  472. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  473. //或者手动点击按钮时 也展开
  474. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty || FromClick)
  475. {
  476. //阅读模式 不显示属性面板
  477. //if (mainViewModel.IsBookMode)
  478. //{
  479. // this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  480. //}
  481. SetProperty(ref isPorpertyOpen, value);
  482. }
  483. }
  484. }
  485. /// <summary>
  486. /// 是否是点击属性面板按钮
  487. /// </summary>
  488. private bool FromClick = false;
  489. private Visibility isReadMode = Visibility.Visible;
  490. /// <summary>
  491. ///是否为阅读模式
  492. /// </summary>
  493. public Visibility IsReadMode
  494. {
  495. get { return isReadMode; }
  496. set
  497. {
  498. SetProperty(ref isReadMode, value);
  499. }
  500. }
  501. private bool canSave;
  502. /// <summary>
  503. /// 是否可以保存
  504. /// </summary>
  505. public bool CanSave
  506. {
  507. get { return canSave; }
  508. set
  509. {
  510. if (events != null && canSave == false)
  511. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  512. SetProperty(ref canSave, value);
  513. }
  514. }
  515. private bool canUndo;
  516. /// <summary>
  517. /// 是否可以进行Undo
  518. /// </summary>
  519. public bool CanUndo
  520. {
  521. get { return canUndo; }
  522. set
  523. {
  524. SetProperty(ref canUndo, value);
  525. }
  526. }
  527. private bool canRedo;
  528. /// <summary>
  529. /// 是否可以进行Redo
  530. /// </summary>
  531. public bool CanRedo
  532. {
  533. get { return canRedo; }
  534. set
  535. {
  536. SetProperty(ref canRedo, value);
  537. }
  538. }
  539. /// <summary>
  540. /// 定义BOTA展开后的最小宽度,小于等于该宽度时无法再缩小宽度,再往左边拖动便是收起BOTA
  541. /// </summary>
  542. public double BOTAMiniWidth = 260;
  543. private GridLength botaWidth = new GridLength(48);
  544. /// <summary>
  545. /// BOTA栏的宽度
  546. /// </summary>
  547. public GridLength BOTAWidth
  548. {
  549. get { return botaWidth; }
  550. set
  551. {
  552. SetProperty(ref botaWidth, value);
  553. if (botaWidth.Value <= 48)
  554. {
  555. OpenBOTA = false;
  556. }
  557. }
  558. }
  559. private int selectedIndex;
  560. /// <summary>
  561. /// 工具栏选中项的索引
  562. /// </summary>
  563. public int TabSelectedIndex
  564. {
  565. get { return selectedIndex; }
  566. set
  567. {
  568. SetProperty(ref selectedIndex, value);
  569. }
  570. }
  571. private bool openBOTA = false;
  572. /// <summary>
  573. /// 是否展开BOTA
  574. /// </summary>
  575. public bool OpenBOTA
  576. {
  577. get { return openBOTA; }
  578. set
  579. {
  580. SetProperty(ref openBOTA, value);
  581. if (openBOTA && BOTAWidth.Value <= 48)
  582. {
  583. BOTAWidth = new GridLength(BOTAMiniWidth);
  584. }
  585. Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
  586. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  587. }
  588. }
  589. public SecurityInfo SecurityInfo = new SecurityInfo();
  590. private Dictionary<string, string> regionNameByTabItem;
  591. private Dictionary<string, string> barContentByTabItem;
  592. private string previousBar = "";
  593. public string CurrentBar = "";
  594. public string unicode = null;
  595. /// <summary>
  596. /// 自动保存的定时器
  597. /// </summary>
  598. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  599. /// <summary>
  600. /// 用来避免重复触发导航事件的标志符
  601. /// </summary>
  602. private bool isOpenFile = false;
  603. /// <summary>
  604. /// 鼠标滚轮缩放的缩放值
  605. /// </summary>
  606. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000, 2000, 4000, 10000 };
  607. /// <summary>
  608. /// 注释-链接,提示语
  609. /// </summary>
  610. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  611. public Visibility LinkAnnotTipVisibility
  612. {
  613. get { return linkAnnotTipVisibility; }
  614. set
  615. {
  616. SetProperty(ref linkAnnotTipVisibility, value);
  617. }
  618. }
  619. private string linkAnnotTipText = "Turn to the target page, then click or box area on the page to select the target page where the link will jump.";
  620. private bool isCreateLink = false;
  621. internal bool IsRightMenuSelectedTextAddLink = false;
  622. internal bool IsSelectedTextAddLink = false;
  623. /// <summary>
  624. /// 上下左右滑动的距离
  625. /// </summary>
  626. private double scrolloffset = 50;
  627. public string LinkAnnotTipText
  628. {
  629. get { return linkAnnotTipText; }
  630. set
  631. {
  632. SetProperty(ref linkAnnotTipText, value);
  633. }
  634. }
  635. private bool botaState = false;
  636. private bool propertyOpenState = false;
  637. public bool _IsCrop = false;
  638. public bool IsCrop
  639. {
  640. get { return _IsCrop; }
  641. set
  642. {
  643. SetProperty(ref _IsCrop, value);
  644. }
  645. }
  646. #endregion 属性、变量
  647. #region 命令
  648. public DelegateCommand Load { get; set; }
  649. public DelegateCommand MouseDown { get; set; }
  650. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  651. public DelegateCommand SaveFile { get; set; }
  652. public DelegateCommand SaveAsFile { get; set; }
  653. public DelegateCommand SaveAsFlattenCommand { get; set; }
  654. public DelegateCommand UndoCommand { get; set; }
  655. public DelegateCommand RedoCommand { get; set; }
  656. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  657. public DelegateCommand AITranslationCommand { get; set; }
  658. public DelegateCommand PrintCommand { get; set; }
  659. public DelegateCommand SelectCommand { get; set; }
  660. public DelegateCommand SettingsCommand { get; set; }
  661. public DelegateCommand AboutDialogCommmand { get; set; }
  662. public DelegateCommand ShareCommand { get; set; }
  663. public DelegateCommand<object> CreateLinkCommand { get; set; }
  664. public DelegateCommand PropertyCommand { get; set; }
  665. public DelegateCommand ShowInFolderCommand { get; set; }
  666. public DelegateCommand CompressCommand { get; set; }
  667. public DelegateCommand MergeFileCommand { get; set; }
  668. public DelegateCommand EncryptCommand { get; set; }
  669. public DelegateCommand DecryptCommand { get; set; }
  670. public DelegateCommand<string> ConvertCommand { get; set; }
  671. public DelegateCommand CloseWindowCommand { get; set; }
  672. public DelegateCommand OpenFileCommand { get; set; }
  673. public DelegateCommand<string> HelpCommand { get; set; }
  674. public DelegateCommand CreateBlankFileCommand { get; set; }
  675. public DelegateCommand CreateFromFile { get; set; }
  676. public DelegateCommand ClosePropertyCommand { get; set; }
  677. public DelegateCommand<object> OpenPropertyCommand { get; set; }
  678. public DelegateCommand LostFoucsCommand { get; set; }
  679. /// <summary>
  680. /// 用于底部工具栏的部分Bug
  681. /// </summary>
  682. public DelegateCommand RealSizeCommand { get; set; }
  683. public DelegateCommand OpenFullCommand { get; set; }
  684. public DelegateCommand SinglePageCommand { get; set; }
  685. public DelegateCommand DoublePageCommand { get; set; }
  686. public DelegateCommand FirstPageCommand { get; set; }
  687. public DelegateCommand LastPageCommand { get; set; }
  688. public DelegateCommand UpCommand { get; set; }
  689. public DelegateCommand DownCommand { get; set; }
  690. public DelegateCommand RightCommand { get; set; }
  691. public DelegateCommand LeftCommand { get; set; }
  692. public DelegateCommand PrePageCommand { get; set; }
  693. public DelegateCommand NextPageCommmand { get; set; }
  694. public DelegateCommand PreViewCommand { get; set; }
  695. public DelegateCommand NextViewCommand { get; set; }
  696. public DelegateCommand ZoomInCommand { get; set; }
  697. public DelegateCommand ZoomOutCommand { get; set; }
  698. //是否显示视图面板
  699. public bool IsReadModeShow { get; internal set; } = false;
  700. #endregion 命令
  701. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  702. {
  703. InitStirng();
  704. region = regionManager;
  705. dialogs = dialogService;
  706. events = eventAggregator;
  707. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  708. Load = new DelegateCommand(LoadControl);
  709. MouseDown = new DelegateCommand(MouseDownEvent);
  710. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  711. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  712. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  713. UndoCommand = new DelegateCommand(Undo);
  714. RedoCommand = new DelegateCommand(Redo);
  715. ShareCommand = new DelegateCommand(share);
  716. PropertyCommand = new DelegateCommand(property);
  717. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  718. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  719. CompressCommand = new DelegateCommand(compress);
  720. MergeFileCommand = new DelegateCommand(mergeFile);
  721. EncryptCommand = new DelegateCommand(encrypt);
  722. DecryptCommand = new DelegateCommand(decrypt);
  723. ConvertCommand = new DelegateCommand<string>(convert);
  724. CloseWindowCommand = new DelegateCommand(closeWindow);
  725. OpenFileCommand = new DelegateCommand(openfile);
  726. HelpCommand = new DelegateCommand<string>(help);
  727. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  728. CreateFromFile = new DelegateCommand(createfromFile);
  729. OpenPropertyCommand = new DelegateCommand<object>(openProperty);
  730. AboutDialogCommmand = new DelegateCommand(about);
  731. ViwerRegionName = RegionNames.ViwerRegionName;
  732. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  733. BOTARegionName = RegionNames.BOTARegionName;
  734. PropertyRegionName = RegionNames.PropertyRegionName;
  735. BottomToolRegionName = RegionNames.BottomToolRegionName;
  736. ReadModeRegionName = RegionNames.ReadModeRegionName;
  737. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  738. AITranslationCommand = new DelegateCommand(ShowAITranslationDialog);
  739. PrintCommand = new DelegateCommand(ShowPrintDialog);
  740. SelectCommand = new DelegateCommand(SelectClick);
  741. SettingsCommand = new DelegateCommand(SettingsEvent);
  742. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  743. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  744. //底部工具栏相关的命令 绑在这一层响应更快
  745. RealSizeCommand = new DelegateCommand(realsize);
  746. OpenFullCommand = new DelegateCommand(OpenFullWindow);
  747. FirstPageCommand = new DelegateCommand(firstpage);
  748. LastPageCommand = new DelegateCommand(lastpage);
  749. PreViewCommand = new DelegateCommand(preview);
  750. NextViewCommand = new DelegateCommand(nextview);
  751. PrePageCommand = new DelegateCommand(prepage);
  752. NextPageCommmand = new DelegateCommand(nextpage);
  753. ZoomInCommand = new DelegateCommand(zoomin);
  754. ZoomOutCommand = new DelegateCommand(zoomout);
  755. UpCommand = new DelegateCommand(up);
  756. DownCommand = new DelegateCommand(down);
  757. SinglePageCommand = new DelegateCommand(singlepage);
  758. DoublePageCommand = new DelegateCommand(doublepage);
  759. LeftCommand = new DelegateCommand(left);
  760. RightCommand = new DelegateCommand(right);
  761. //未显示时无法注册上Region名称
  762. ToolContentVisible = Visibility.Visible;
  763. ToolsBarContentVisible = Visibility.Visible;
  764. OCRContentVisible = Visibility.Visible;
  765. TipVisible = Visibility.Visible;
  766. TipContentRegionName = RegionNames.TipContentRegionName;
  767. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  768. NotePopupRegionName = RegionNames.NotePopupRegionName;
  769. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  770. ToolContentRegionName = Guid.NewGuid().ToString();
  771. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  772. TextEditContentRegionName = Guid.NewGuid().ToString();
  773. ToolContentVisible = Visibility.Collapsed;
  774. ToolsBarContentVisible = Visibility.Collapsed;
  775. OCRContentVisible = Visibility.Collapsed;
  776. TipVisible = Visibility.Collapsed;
  777. regionNameByTabItem = new Dictionary<string, string>();
  778. barContentByTabItem = new Dictionary<string, string>();
  779. InitialregionNameByTabItem(ref regionNameByTabItem);
  780. InitialbarContentByTabItem(ref barContentByTabItem);
  781. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  782. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  783. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  784. //TODO:根据缓存 选择用户上次选择的菜单
  785. CurrentBar = "TabItemAnnotation";
  786. EnterSelectedBar("TabItemAnnotation");
  787. StartAutoSave();
  788. }
  789. private void about()
  790. {
  791. dialogs.ShowDialog(DialogNames.AboutDialog);
  792. }
  793. private void doublepage()
  794. {
  795. bottom?.DoublePageCommand.Execute();
  796. }
  797. private void singlepage()
  798. {
  799. bottom?.SinglePageCommand.Execute();
  800. }
  801. private void down()
  802. {
  803. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() + scrolloffset);
  804. }
  805. private void up()
  806. {
  807. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() - scrolloffset);
  808. }
  809. /// <summary>
  810. /// 右键逻辑
  811. /// </summary>
  812. private void right()
  813. {
  814. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  815. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  816. {
  817. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() + 50);
  818. }
  819. else
  820. {
  821. bottom?.NextPageCommand.Execute();
  822. }
  823. }
  824. /// <summary>
  825. /// 左键逻辑
  826. /// </summary>
  827. private void left()
  828. {
  829. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  830. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  831. {
  832. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() - 50);
  833. }
  834. else
  835. {
  836. bottom?.PrePageCommand.Execute();
  837. }
  838. }
  839. private void zoomin()
  840. {
  841. bottom?.ZoomInCommand.Execute();
  842. }
  843. private void zoomout()
  844. {
  845. bottom?.ZoomOutCommand.Execute();
  846. }
  847. private void nextpage()
  848. {
  849. bottom?.NextPageCommand.Execute();
  850. }
  851. private void prepage()
  852. {
  853. bottom?.PrePageCommand.Execute();
  854. }
  855. private void nextview()
  856. {
  857. bottom?.NextViewCommnad.Execute();
  858. }
  859. private void preview()
  860. {
  861. bottom?.PreViewCommand.Execute();
  862. }
  863. private void lastpage()
  864. {
  865. bottom?.LastPageCommand.Execute();
  866. }
  867. private void firstpage()
  868. {
  869. bottom?.FirstPageCommand.Execute();
  870. }
  871. /// <summary>
  872. /// 底部工具栏的缩放至实际大小
  873. /// </summary>
  874. private void realsize()
  875. {
  876. bottom?.RealSizeCommand.Execute();
  877. }
  878. /// <summary>
  879. /// 进入全屏模式
  880. /// </summary>
  881. private void OpenFullWindow()
  882. {
  883. DialogParameters parameters = new DialogParameters();
  884. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  885. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  886. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  887. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  888. {
  889. if (e.Result == ButtonResult.Cancel)
  890. {
  891. //TODO:弹窗提示打开全屏模式失败
  892. AlertsMessage alertsMessage = new AlertsMessage();
  893. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("OperationFailWarning"), App.ServiceLoader.GetString("Text_ok"));
  894. return;
  895. }
  896. });
  897. }
  898. /// <summary>
  899. /// 点击展开折叠属性面板
  900. /// </summary>
  901. /// <param name="obj"></param>
  902. private void openProperty(object obj)
  903. {
  904. FromClick = true;
  905. IsPropertyOpen = (bool)obj;
  906. FromClick = false;
  907. }
  908. /// <summary>
  909. /// 复制、剪切操作前校验是否有文档操作权限,没有则弹出权限解密弹窗
  910. /// </summary>
  911. /// <returns></returns>
  912. public bool CheckPermissionBeforeOption()
  913. {
  914. VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
  915. if (verifyResult.IsDiscryptied)
  916. {
  917. if (verifyResult.Password != null)
  918. {
  919. PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
  920. }
  921. ShowLeftTip(false);
  922. return true;
  923. }
  924. else
  925. {
  926. return false;
  927. }
  928. }
  929. /// <summary>
  930. /// 开始自动保存
  931. /// </summary>
  932. public void StartAutoSave()
  933. {
  934. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  935. if (autoSave)
  936. {
  937. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  938. if (autoSaveTimer == null)
  939. {
  940. autoSaveTimer = new DispatcherTimer();
  941. }
  942. autoSaveTimer.Stop();
  943. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  944. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  945. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  946. autoSaveTimer.Start();
  947. }
  948. }
  949. /// <summary>
  950. /// 释放定时器
  951. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  952. /// </summary>
  953. public void CloseAutoSave()
  954. {
  955. if (autoSaveTimer != null)
  956. {
  957. autoSaveTimer.Stop();
  958. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  959. autoSaveTimer = null;
  960. }
  961. }
  962. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  963. {
  964. //未付费的用户不进行自动保存
  965. if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
  966. {
  967. return;
  968. }
  969. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  970. if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
  971. {
  972. //自动保存仅针对已经有文件路径的文档
  973. saveFile();
  974. }
  975. }
  976. private void MouseDownEvent()
  977. {
  978. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  979. {
  980. NotePopupVisible = Visibility.Collapsed;
  981. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  982. {
  983. var views = region.Regions[NotePopupRegionName].Views;
  984. foreach (var item in views)
  985. {
  986. if (item is StickyNotePopup sticky)
  987. {
  988. var contentRegion = region.Regions[NotePopupRegionName];
  989. contentRegion.Remove(sticky);
  990. break;
  991. }
  992. }
  993. }
  994. }
  995. }
  996. private async void createfromFile()
  997. {
  998. string txt = Properties.Resources.txtex;
  999. string word = Properties.Resources.wordex;
  1000. string ppt = Properties.Resources.pptex;
  1001. string excel = Properties.Resources.excelex;
  1002. string html = Properties.Resources.htmlex;
  1003. string image = Properties.Resources.imageex;
  1004. string allfiles = txt + word + excel + ppt + image + html;
  1005. OpenFileDialog dialog = new OpenFileDialog();
  1006. dialog.Multiselect = true;
  1007. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  1008. $"Microsoft Office Word({word})|{word}|" +
  1009. $"Microsoft Office Excel({excel})|{excel}|" +
  1010. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  1011. $"Txt({txt})|{txt}|" +
  1012. $"Picture({image})|{image}|" +
  1013. $"Html({html})|{html}");
  1014. if ((bool)dialog.ShowDialog())
  1015. {
  1016. for (int i = 0; i < dialog.FileNames.Length; i++)
  1017. {
  1018. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  1019. {
  1020. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  1021. }
  1022. else
  1023. {
  1024. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1025. {
  1026. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  1027. }));
  1028. await Task.Delay(20);
  1029. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  1030. }
  1031. }
  1032. }
  1033. }
  1034. /// <summary>
  1035. ///创建空白文档
  1036. /// </summary>
  1037. private async void createBlankFile()
  1038. {
  1039. App.mainWindowViewModel.AddTab.Execute();
  1040. await Task.Delay(30);
  1041. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  1042. }
  1043. private void help(string args)
  1044. {
  1045. string url = "";
  1046. switch (args)
  1047. {
  1048. case "Guid":
  1049. //打开内嵌文档
  1050. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  1051. {
  1052. //如果已经打开时,则选中内嵌文档
  1053. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  1054. return;
  1055. }
  1056. if (File.Exists(App.GuidPDFPath))
  1057. {
  1058. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  1059. }
  1060. else
  1061. {
  1062. //因为文件被占用等情况,复制内嵌文档到新路径失败时,先打开项目内的文档
  1063. string tempfile = Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf");
  1064. if (File.Exists(tempfile))
  1065. {
  1066. App.mainWindowViewModel.AddTabItem(tempfile);
  1067. }
  1068. }
  1069. break;
  1070. case "Online":
  1071. url = @"https://www.pdfreaderpro.com/windows/help";
  1072. break;
  1073. case "More":
  1074. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  1075. break;
  1076. case "Template":
  1077. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  1078. break;
  1079. case "Blog":
  1080. //TODO:显示订阅电子报弹窗
  1081. break;
  1082. case "ComPDF":
  1083. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  1084. break;
  1085. case "FeedBack":
  1086. //调用邮箱 发送邮件
  1087. StringBuilder sr = new StringBuilder();
  1088. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  1089. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  1090. break;
  1091. default:
  1092. break;
  1093. }
  1094. if (!string.IsNullOrEmpty(url))
  1095. {
  1096. //需要跳转网页的情况
  1097. System.Diagnostics.Process.Start(url);
  1098. }
  1099. }
  1100. /// <summary>
  1101. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  1102. /// </summary>
  1103. private void openfile()
  1104. {
  1105. OpenFileDialog openFileDialog = new OpenFileDialog();
  1106. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  1107. openFileDialog.Multiselect = true;
  1108. if ((bool)openFileDialog.ShowDialog())
  1109. {
  1110. if (openFileDialog.FileNames.Count() == 1)
  1111. {
  1112. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  1113. {
  1114. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1115. }
  1116. else
  1117. {
  1118. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  1119. }
  1120. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  1121. }
  1122. else
  1123. {
  1124. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  1125. if (fileList.Count <= 0)
  1126. {
  1127. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1128. return;
  1129. }
  1130. mainViewModel.OpenFile(fileList[0]);
  1131. for (int i = 1; i < fileList.Count(); i++)
  1132. {
  1133. if (!App.OpenedFileList.Contains(fileList[i]))
  1134. {
  1135. App.mainWindowViewModel.AddTabItem(fileList[i]);
  1136. }
  1137. ToolMethod.SetFileThumbImg(fileList[i]);
  1138. }
  1139. }
  1140. }
  1141. }
  1142. /// <summary>
  1143. /// 打开文件Translation
  1144. /// </summary>
  1145. public void OpenFile(string[] newfile)
  1146. {
  1147. if (App.OpenedFileList.Contains(newfile[0]))
  1148. {
  1149. App.mainWindowViewModel.SelectItem(newfile[0]);
  1150. }
  1151. else
  1152. {
  1153. App.mainWindowViewModel.AddTabItem(newfile[0]);
  1154. }
  1155. ToolMethod.SetFileThumbImg(newfile[0]);
  1156. }
  1157. /// <summary>
  1158. /// 关闭当前窗体
  1159. /// </summary>
  1160. private void closeWindow()
  1161. {
  1162. App.Current.MainWindow.Close();
  1163. }
  1164. /// <summary>
  1165. /// 转档
  1166. /// </summary>
  1167. /// <param name="obj"></param>
  1168. private void convert(string obj)
  1169. {
  1170. if (!string.IsNullOrEmpty(obj))
  1171. {
  1172. DialogParameters value = new DialogParameters();
  1173. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1174. switch (obj)
  1175. {
  1176. case "Word":
  1177. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  1178. {
  1179. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1180. converterDialogsModel.OnOpened((DialogResult)e);
  1181. });
  1182. break;
  1183. case "Excel":
  1184. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  1185. {
  1186. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1187. converterDialogsModel.OnOpened((DialogResult)e);
  1188. });
  1189. break;
  1190. case "PPT":
  1191. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  1192. {
  1193. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1194. converterDialogsModel.OnOpened((DialogResult)e);
  1195. });
  1196. break;
  1197. case "RTF":
  1198. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  1199. {
  1200. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1201. converterDialogsModel.OnOpened((DialogResult)e);
  1202. });
  1203. break;
  1204. case "CSV":
  1205. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  1206. {
  1207. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1208. converterDialogsModel.OnOpened((DialogResult)e);
  1209. });
  1210. break;
  1211. case "HTML":
  1212. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  1213. {
  1214. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1215. converterDialogsModel.OnOpened((DialogResult)e);
  1216. });
  1217. break;
  1218. case "Text":
  1219. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  1220. {
  1221. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1222. converterDialogsModel.OnOpened((DialogResult)e);
  1223. });
  1224. break;
  1225. case "Image":
  1226. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  1227. {
  1228. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1229. converterDialogsModel.OnOpened((DialogResult)e);
  1230. });
  1231. break;
  1232. default:
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. /// <summary>
  1238. /// 解密
  1239. /// </summary>
  1240. private void decrypt()
  1241. {
  1242. ///无可用安全性设置的原因:
  1243. ///文件本身无安全性设置,且没有设置过密码
  1244. ///文件安全性已经被重置
  1245. ///
  1246. if ((!PDFViewer.Document.IsEncrypted && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
  1247. {
  1248. AlertsMessage alertsMessage = new AlertsMessage();
  1249. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("NoPasswrod_Waring"), App.ServiceLoader.GetString("Text_ok"));
  1250. }
  1251. else
  1252. {
  1253. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1254. if (result.IsDiscryptied)
  1255. {
  1256. if (result.Password != null)
  1257. {
  1258. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1259. }
  1260. ShowLeftTip(false);
  1261. DialogParameters value = new DialogParameters();
  1262. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1263. value.Add(ParameterNames.ViewContentViewModel, this);
  1264. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
  1265. {
  1266. if (e.Result == ButtonResult.OK)
  1267. {
  1268. if (SecurityInfo.IsPasswordRemoved)
  1269. {
  1270. PDFViewer.UndoManager.CanSave = true;
  1271. }
  1272. ShowLeftTip(false);
  1273. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1274. }
  1275. });
  1276. }
  1277. }
  1278. }
  1279. /// <summary>
  1280. /// 加密
  1281. /// </summary>
  1282. private void encrypt()
  1283. {
  1284. if (!this.SecurityInfo.IsPasswordChanged)
  1285. {
  1286. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1287. if (result.IsDiscryptied)
  1288. {
  1289. if (result.Password != null)
  1290. {
  1291. if (PDFViewer.Document.UnlockWithPassword(result.Password))
  1292. {
  1293. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1294. }
  1295. }
  1296. }
  1297. }
  1298. DialogParameters value = new DialogParameters();
  1299. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1300. value.Add(ParameterNames.ViewContentViewModel, this);
  1301. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1302. {
  1303. if (e.Result == ButtonResult.OK)
  1304. {
  1305. SecurityHelper.IsPasswordChanged = true;
  1306. if (this.SecurityInfo.IsPasswordChanged)
  1307. {
  1308. this.PDFViewer.UndoManager.CanSave = true;
  1309. }
  1310. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1311. }
  1312. });
  1313. }
  1314. /// <summary>
  1315. /// 合并
  1316. /// </summary>
  1317. private void mergeFile()
  1318. {
  1319. DialogParameters value = new DialogParameters();
  1320. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1321. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1322. }
  1323. /// <summary>
  1324. /// 压缩
  1325. /// </summary>
  1326. private void compress()
  1327. {
  1328. DialogParameters value = new DialogParameters();
  1329. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1330. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1331. {
  1332. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1333. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1334. });
  1335. }
  1336. /// <summary>
  1337. /// 设置Tip状态栏的显示状态
  1338. /// </summary>
  1339. /// <param name="show">是否显示</param>
  1340. public void ShowTip(bool show)
  1341. {
  1342. if (show)
  1343. {
  1344. TipVisible = Visibility.Visible;
  1345. }
  1346. else
  1347. {
  1348. TipVisible = Visibility.Collapsed;
  1349. }
  1350. }
  1351. /// <summary>
  1352. /// 设置LeftTip状态栏的显示状态
  1353. /// </summary>
  1354. /// <param name="show">是否显示</param>
  1355. public void ShowLeftTip(bool show)
  1356. {
  1357. if (show)
  1358. {
  1359. LeftTipVisible = Visibility.Visible;
  1360. }
  1361. else
  1362. {
  1363. LeftTipVisible = Visibility.Collapsed;
  1364. }
  1365. }
  1366. public void CheckHaveAllPermission()
  1367. {
  1368. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1369. {
  1370. ShowLeftTip(true);
  1371. NavigationParameters param = new NavigationParameters();
  1372. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1373. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1374. }
  1375. }
  1376. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1377. {
  1378. switch (showTipEventArgs.enumTipKind)
  1379. {
  1380. case EnumTipKind.StatusNone:
  1381. ShowLeftTip(false);
  1382. break;
  1383. case EnumTipKind.StatusSetPasswordSuccessfully:
  1384. ShowLeftTip(true);
  1385. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1386. break;
  1387. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1388. ShowLeftTip(false);
  1389. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1390. IsLoading = Visibility.Collapsed;
  1391. ShowTip(true);
  1392. await Task.Delay(3000);
  1393. //ReadModelTip = Visibility.Collapsed;
  1394. TipVisible = Visibility.Collapsed;
  1395. break;
  1396. default: break;
  1397. }
  1398. }
  1399. /// <summary>
  1400. /// 右键菜单创建链接
  1401. /// </summary>
  1402. /// <param name="obj"></param>
  1403. private void CreateLinkEvent(object obj)
  1404. {
  1405. if (obj is object[] objArry)
  1406. {
  1407. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1408. {
  1409. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1410. linkArgs.URI = string.Empty;
  1411. linkArgs.LinkType = LINK_TYPE.GOTO;
  1412. linkArgs.PageIndex = annotCommand.PageIndex;
  1413. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1414. this.IsRightMenuCreateLink = true;
  1415. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1416. lists.Add(linkArgs);
  1417. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1418. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1419. PDFViewer.SetToolParam(annotArgs);
  1420. this.IsPropertyOpen = true;
  1421. }
  1422. }
  1423. }
  1424. private void CloseProperty()
  1425. {
  1426. FromClick = true;
  1427. IsPropertyOpen = false;
  1428. FromClick = false;
  1429. }
  1430. /// <summary>
  1431. /// 在文件资源管理器中显示
  1432. /// </summary>
  1433. private void ShowInFolder()
  1434. {
  1435. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1436. }
  1437. private void property()
  1438. {
  1439. DialogParameters valuePairs = new DialogParameters();
  1440. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1441. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1442. }
  1443. private async void share()
  1444. {
  1445. try
  1446. {
  1447. //分享前自动保存
  1448. if (!await SaveBeforeOption())
  1449. {
  1450. return;
  1451. }
  1452. var path = PDFViewer.Document.FilePath;
  1453. string subject = "Share With" + " " + PDFViewer.Document.FileName;
  1454. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1455. }
  1456. catch
  1457. {
  1458. AlertsMessage alertsMessage = new AlertsMessage();
  1459. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Share_NoOutLookWarning"), App.ServiceLoader.GetString("Text_ok"));
  1460. }
  1461. }
  1462. private void SettingsEvent()
  1463. {
  1464. DialogParameters value = new DialogParameters();
  1465. value.Add(ParameterNames.ViewContentViewModel, this);
  1466. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM(); ;
  1467. dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
  1468. {
  1469. var annotate = Settings.Default.AppProperties.Annotate;
  1470. if (annotToolContent != null)
  1471. {
  1472. IsSettingOut = true;
  1473. //与注释联动修改颜色
  1474. UpdateFreeHand(annotate, annotToolContent);
  1475. UpdateTextHighlight(annotate, annotToolContent);
  1476. UpdateUnderLine(annotate, annotToolContent);
  1477. UpdateStrikethrough(annotate, annotToolContent);
  1478. UpdateLine(annotate, annotToolContent);
  1479. UpdateArrow(annotate, annotToolContent);
  1480. //IsSettingOut =false;
  1481. }
  1482. });
  1483. if (PDFViewer != null)
  1484. {
  1485. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1486. }
  1487. if (Settings.Default.AppProperties.Description.AutoSave)
  1488. {
  1489. StartAutoSave();
  1490. }
  1491. else
  1492. {
  1493. CloseAutoSave();
  1494. }
  1495. }
  1496. private AnnotToolContentViewModel GetAnnotToolContentVM()
  1497. {
  1498. AnnotToolContentViewModel annotToolContent = null;
  1499. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1500. {
  1501. var views = region.Regions[ToolsBarContentRegionName].Views;
  1502. var isHas = views.FindFirst(q => q is AnnotToolContent);
  1503. if (isHas is AnnotToolContent annotTool)
  1504. {
  1505. annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
  1506. }
  1507. }
  1508. return annotToolContent;
  1509. }
  1510. private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1511. {
  1512. Color color2 = annotate.ArrowColor;
  1513. Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
  1514. bool flag = ColorComparison(color2, color1);
  1515. if (flag)
  1516. {
  1517. annotToolContent.ArrowColor = new SolidColorBrush(color2);
  1518. if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
  1519. {
  1520. if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
  1521. {
  1522. annotArgs.LineColor = color2;
  1523. }
  1524. }
  1525. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1526. {
  1527. CreateRefreshComment(annotToolContent);
  1528. }
  1529. }
  1530. }
  1531. private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1532. {
  1533. Color color2 = annotate.LineColor;
  1534. Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
  1535. bool flag = ColorComparison(color2, color1);
  1536. if (flag)
  1537. {
  1538. annotToolContent.LineColor = new SolidColorBrush(color2);
  1539. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
  1540. {
  1541. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
  1542. {
  1543. annotArgs.LineColor = color2;
  1544. }
  1545. }
  1546. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1547. {
  1548. CreateRefreshComment(annotToolContent);
  1549. }
  1550. }
  1551. }
  1552. private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1553. {
  1554. Color color2 = annotate.StrikethroughColor;
  1555. Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
  1556. bool flag = ColorComparison(color2, color1);
  1557. if (flag)
  1558. {
  1559. annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
  1560. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1561. {
  1562. CreateRefreshComment(annotToolContent);
  1563. }
  1564. }
  1565. }
  1566. private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1567. {
  1568. Color color2 = annotate.UnderLineColor;
  1569. Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
  1570. bool flag = ColorComparison(color2, color1);
  1571. if (flag)
  1572. {
  1573. annotToolContent.UnderLineColor = new SolidColorBrush(color2);
  1574. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1575. {
  1576. CreateRefreshComment(annotToolContent);
  1577. }
  1578. }
  1579. }
  1580. private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1581. {
  1582. Color color2 = annotate.HighLightColor;
  1583. Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
  1584. bool flag = ColorComparison(color2, color1);
  1585. if (flag)
  1586. {
  1587. annotToolContent.HighLightColor = new SolidColorBrush(color2);
  1588. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1589. {
  1590. CreateRefreshComment(annotToolContent);
  1591. }
  1592. }
  1593. }
  1594. private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1595. {
  1596. Color color2 = annotate.FreeHandColor;
  1597. Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
  1598. bool flag = ColorComparison(color2, color1);
  1599. if (flag)
  1600. {
  1601. annotToolContent.FreeHandColor = new SolidColorBrush(color2);
  1602. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
  1603. {
  1604. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
  1605. {
  1606. freehandAnnotArgs.InkColor = color2;
  1607. }
  1608. }
  1609. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1610. {
  1611. CreateRefreshComment(annotToolContent);
  1612. }
  1613. }
  1614. }
  1615. private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
  1616. {
  1617. AnnotHandlerEventArgs annotArgs = null;
  1618. string tag = annotToolContent.StrAnnotToolChecked;
  1619. annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
  1620. if (annotArgs != null)
  1621. {
  1622. //设置点击页面会创建对应选中注释工具的注释
  1623. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1624. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1625. PDFViewer.SetToolParam(annotArgs);
  1626. }
  1627. }
  1628. private bool ColorComparison(Color color2, Color color1)
  1629. {
  1630. if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
  1631. && color1.A == color2.A)
  1632. {
  1633. return false;
  1634. }
  1635. else
  1636. {
  1637. return true;
  1638. }
  1639. }
  1640. private bool CanSaveExcute()
  1641. {
  1642. return CanSave;
  1643. }
  1644. private void MenuEnterReadModeEvent(object obj)
  1645. {
  1646. }
  1647. public void ShowAITranslationDialog()
  1648. {
  1649. DialogParameters printValue = new DialogParameters();
  1650. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1651. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1652. printValue.Add(ParameterNames.ViewContentViewModel, this);
  1653. printValue.Add(ParameterNames.Unicode, unicode);
  1654. dialogs.ShowDialog(DialogNames.DocumentaryTranslation, printValue, e => { });
  1655. }
  1656. public void ShowPrintDialog()
  1657. {
  1658. DialogParameters printValue = new DialogParameters();
  1659. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1660. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1661. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1662. printValue.Add(ParameterNames.Unicode, unicode);
  1663. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1664. }
  1665. public void SelectClick()
  1666. {
  1667. if (OpenBOTA == false)
  1668. {
  1669. OpenBOTA = true;
  1670. }
  1671. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1672. if (isBook == false)
  1673. {
  1674. bOTAContent.TabItemSearch.IsSelected = true;
  1675. }
  1676. }
  1677. public bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1678. {
  1679. bool isTabItem = false;
  1680. bOTAContentViewModel = null;
  1681. bOTAContent = null;
  1682. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1683. {
  1684. var views = region.Regions[this.BOTARegionName].Views;
  1685. var model = views.FirstOrDefault(q => q is BOTAContent);
  1686. if (model is BOTAContent bOTAContent1)
  1687. {
  1688. bOTAContent = bOTAContent1;
  1689. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1690. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1691. {
  1692. isTabItem = true;
  1693. }
  1694. }
  1695. }
  1696. return isTabItem;
  1697. }
  1698. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1699. {
  1700. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1701. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1702. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1703. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1704. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  1705. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1706. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1707. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1708. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1709. }
  1710. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1711. {
  1712. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1713. dictionary.Add("TabItemTool", "ToolsBarContent");
  1714. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1715. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1716. dictionary.Add("TabItemScan", "ScanContent");
  1717. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1718. dictionary.Add("TabItemForm", "FormsToolContent");
  1719. dictionary.Add("TabItemFill", "FillAndSignContent");
  1720. }
  1721. private void UpdateShowContent(string currentBar)
  1722. {
  1723. ToolContentVisible = Visibility.Collapsed;
  1724. ToolsBarContentVisible = Visibility.Collapsed;
  1725. ToolsBarContentVisible = Visibility.Collapsed;
  1726. TextEditToolContentVisible = Visibility.Collapsed;
  1727. OCRContentVisible = Visibility.Collapsed;
  1728. switch (currentBar)
  1729. {
  1730. case "TabItemAnnotation":
  1731. case "TabItemTool":
  1732. case "TabItemForm":
  1733. case "TabItemFill":
  1734. ToolsBarContentVisible = Visibility.Visible;
  1735. break;
  1736. case "TabItemScan":
  1737. ToolsBarContentVisible = Visibility.Visible;
  1738. OCRContentVisible = Visibility.Visible;
  1739. break;
  1740. case "TabItemEdit":
  1741. TextEditToolContentVisible = Visibility.Visible;
  1742. break;
  1743. case "TabItemConvert":
  1744. ToolsBarContentVisible = Visibility.Visible;
  1745. break;
  1746. case "TabItemPageEdit":
  1747. case "HeaderFooterContent":
  1748. case "BatesContent":
  1749. case "WatermarkContent":
  1750. case "BackgroundContent":
  1751. case "RedactionContent":
  1752. ToolContentVisible = Visibility.Visible;
  1753. break;
  1754. default:
  1755. break;
  1756. }
  1757. PDFEditMode(currentBar);
  1758. FormMode(currentBar);
  1759. }
  1760. private void PDFEditMode(string currentBar)
  1761. {
  1762. if (currentBar == "TabItemEdit")
  1763. {
  1764. if (PDFViewer != null)
  1765. {
  1766. SolidColorBrush brush = new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#18A0FB"));
  1767. brush.Opacity = 0.2;
  1768. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1769. CommonDrawData.PDFEditCoverBrush = brush;
  1770. CommonDrawData.PDFEditCoverPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
  1771. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  1772. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  1773. //SelectedPrpoertyPanel("TextEditProperty", null);
  1774. //IsPropertyOpen = true;
  1775. }
  1776. }
  1777. else
  1778. {
  1779. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1780. {
  1781. IsPropertyOpen = false;
  1782. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1783. }
  1784. }
  1785. }
  1786. private void FormMode(string currentBar)
  1787. {
  1788. if (currentBar == "TabItemForm")
  1789. {
  1790. if (PDFViewer != null)
  1791. {
  1792. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1793. }
  1794. }
  1795. else
  1796. {
  1797. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1798. {
  1799. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1800. }
  1801. }
  1802. }
  1803. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1804. {
  1805. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1806. if (e.PropertyName == "CanUndo")
  1807. {
  1808. CanUndo = PDFViewer.UndoManager.CanUndo;
  1809. }
  1810. if (e.PropertyName == "CanRedo")
  1811. {
  1812. CanRedo = PDFViewer.UndoManager.CanRedo;
  1813. }
  1814. if (e.PropertyName == "CanSave")
  1815. {
  1816. CanSave = PDFViewer.UndoManager.CanSave;
  1817. }
  1818. }
  1819. /// <summary>
  1820. /// 选项卡切换事件
  1821. /// </summary>
  1822. /// <param name="e"></param>
  1823. private void TabControlSelectonChangedEvent(object e)
  1824. {
  1825. var args = e as SelectionChangedEventArgs;
  1826. if (args != null && args.AddedItems.Count > 0)
  1827. {
  1828. var item = args.AddedItems[0] as TabItem;
  1829. CurrentBar = item.Name;
  1830. if (previousBar != CurrentBar)
  1831. {
  1832. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1833. {
  1834. EnterPageEdit();
  1835. }
  1836. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1837. {
  1838. EnterSelectedBar(CurrentBar);
  1839. isInPageEdit = false;
  1840. }
  1841. previousBar = CurrentBar;
  1842. }
  1843. }
  1844. }
  1845. /// <summary>
  1846. /// 进入页面编辑模式
  1847. /// </summary>
  1848. //工具栏添加功能应注意自处
  1849. public void EnterPageEdit()
  1850. {
  1851. if (TabSelectedIndex != 2)
  1852. {
  1853. TabSelectedIndex = 2;
  1854. }
  1855. CurrentBar = "TabItemPageEdit";
  1856. EnterToolMode(barContentByTabItem[CurrentBar]);
  1857. isInPageEdit = true;
  1858. }
  1859. /// <summary>
  1860. /// 阅读模式
  1861. /// </summary>
  1862. /// <param name="viewContent"></param>
  1863. public async void On_ReadMode()
  1864. {
  1865. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1866. mainViewModel.IsBookMode = true;
  1867. IsLoading = Visibility.Visible;
  1868. await Task.Delay(1);
  1869. PDFViewer.DisableClearSelectAnnot(false);
  1870. PDFViewer.ClearSelectAnnots();
  1871. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1872. var annotArgs = new SelectToolArgs();
  1873. PDFViewer.SetToolParam(annotArgs);
  1874. #region 旧版本
  1875. //NavigationParameters param = new NavigationParameters();
  1876. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  1877. //param.Add(ParameterNames.ViewContentViewModel, this);
  1878. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1879. ////ShowContent(CurrentBar, true);
  1880. //if (GridToolRow != 0)
  1881. //{
  1882. // GridToolRow = 0;
  1883. //}
  1884. //if (GridToolRowSpan != 4)
  1885. //{
  1886. // GridToolRowSpan = 4;
  1887. //}
  1888. ////isInPageEdit = true;
  1889. //UpdateShowContent("TabItemPageEdit");
  1890. #endregion 旧版本
  1891. //5.15
  1892. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  1893. botaState = OpenBOTA;
  1894. propertyOpenState = IsPropertyOpen;
  1895. //5.6注释
  1896. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  1897. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  1898. //OpenBOTA = false;
  1899. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  1900. //模拟一次用户点击 关闭属性面板
  1901. //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
  1902. FromClick = true;
  1903. IsPropertyOpen = false;
  1904. FromClick = false;
  1905. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM();
  1906. if (annotToolContent != null)
  1907. {
  1908. annotToolContent.StrAnnotToolChecked = "";
  1909. }
  1910. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1911. {
  1912. var views = region.Regions[TipContentRegionName].Views;
  1913. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  1914. if (isHasView == null)
  1915. {
  1916. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  1917. }
  1918. else
  1919. {
  1920. region.Regions[TipContentRegionName].Activate(isHasView);
  1921. }
  1922. }
  1923. IsLoading = Visibility.Collapsed;
  1924. ShowTip(true);
  1925. await Task.Delay(3000);
  1926. TipVisible = Visibility.Collapsed;
  1927. }
  1928. /// <summary>
  1929. /// 退出阅读模式
  1930. /// </summary>
  1931. public async void Off_ReadModel()
  1932. {
  1933. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1934. mainViewModel.IsBookMode = false;
  1935. IsLoading = Visibility.Visible;
  1936. await Task.Delay(1);
  1937. //PDFViewer.MouseMode = MouseModes.None;
  1938. #region 旧版本
  1939. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1940. //{
  1941. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1942. // {
  1943. // var contentRegion = region.Regions[ViwerRegionName];
  1944. // contentRegion.Remove(PDFViewer);
  1945. // }
  1946. // //还原背景色
  1947. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1948. // region.AddToRegion(ViwerRegionName, PDFViewer);
  1949. //}
  1950. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1951. //{
  1952. // EnterSelectedBar("TabItemAnnotation");
  1953. //}
  1954. //else
  1955. //{
  1956. // EnterSelectedBar(CurrentBar);
  1957. //}
  1958. #endregion 旧版本
  1959. //还原背景色
  1960. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1961. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  1962. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1963. {
  1964. var views = region.Regions[TipContentRegionName].Views;
  1965. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  1966. if (isHasView == null)
  1967. {
  1968. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1969. }
  1970. else
  1971. {
  1972. region.Regions[TipContentRegionName].Activate(isHasView);
  1973. }
  1974. }
  1975. ///退出阅读模式 显示视图面板
  1976. BottomToolContent bottomTool = null;
  1977. BottomToolContentViewModel bottomToolVM = GetBottomToolContentVM(ref bottomTool);
  1978. if (bottomToolVM != null)
  1979. {
  1980. bottomToolVM.IsShowViewModular = propertyOpenState;
  1981. IsPropertyOpen = propertyOpenState;
  1982. if (bottomToolVM.IsShowViewModular && bottomTool != null)
  1983. {
  1984. bottomToolVM.ShowViewModularCommand.Execute(true);
  1985. }
  1986. }
  1987. //if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  1988. //{
  1989. // var views = region.Regions[BottomToolRegionName].Views;
  1990. // var isHasView = views.FindFirst(q => q is BottomToolContent);
  1991. // if (isHasView is BottomToolContent bottomToolContent)
  1992. // {
  1993. // BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  1994. // toolContentViewModel.IsShowViewModular = propertyOpenState;
  1995. // IsPropertyOpen = propertyOpenState;
  1996. // }
  1997. //}
  1998. IsLoading = Visibility.Collapsed;
  1999. //5.6注释
  2000. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  2001. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  2002. //5.15
  2003. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  2004. OpenBOTA = botaState;
  2005. PDFViewer.DisableClearSelectAnnot(false);
  2006. PDFViewer.ClearSelectAnnots();
  2007. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2008. var annotArgs = new SelectToolArgs();
  2009. PDFViewer.SetToolParam(annotArgs);
  2010. ShowTip(true);
  2011. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  2012. await Task.Delay(3000);
  2013. //ReadModelTip = Visibility.Collapsed;
  2014. TipVisible = Visibility.Collapsed;
  2015. }
  2016. public BottomToolContentViewModel GetBottomToolContentVM(ref BottomToolContent bottomTool)
  2017. {
  2018. BottomToolContentViewModel viewModel = null;
  2019. if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  2020. {
  2021. var views = region.Regions[BottomToolRegionName].Views;
  2022. var isHasView = views.FindFirst(q => q is BottomToolContent);
  2023. if (isHasView is BottomToolContent bottomToolContent)
  2024. {
  2025. bottomTool = bottomToolContent;
  2026. viewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  2027. }
  2028. }
  2029. return viewModel;
  2030. }
  2031. #region PDFViewer鼠标滚轮缩放事件
  2032. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  2033. {
  2034. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  2035. PDFViewer.Zoom(newZoom);
  2036. }
  2037. public double CheckZoomLevel(double zoom, bool IsGrowth)
  2038. {
  2039. double standardZoom = 100;
  2040. //最小缩放倍数 0.01倍
  2041. double minrate = 0.01;
  2042. //最大缩放倍数 100倍
  2043. double maxrate = 100;
  2044. if (zoom <= minrate)
  2045. {
  2046. return minrate;
  2047. }
  2048. //最大缩放倍数 100倍
  2049. if (zoom >= maxrate)
  2050. {
  2051. return maxrate;
  2052. }
  2053. zoom *= 100;
  2054. for (int i = 0; i < zoomLevel.Length - 1; i++)
  2055. {
  2056. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  2057. {
  2058. standardZoom = zoomLevel[i + 1];
  2059. break;
  2060. }
  2061. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  2062. {
  2063. standardZoom = zoomLevel[i];
  2064. break;
  2065. }
  2066. }
  2067. return standardZoom / 100;
  2068. }
  2069. #endregion PDFViewer鼠标滚轮缩放事件
  2070. #region 方法
  2071. /// <summary>
  2072. /// 快捷键
  2073. /// </summary>
  2074. /// <param name="sender"></param>
  2075. /// <param name="e"></param>
  2076. /// <exception cref="NotImplementedException"></exception>
  2077. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  2078. {
  2079. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  2080. {
  2081. //判断是不是不是注释工具下
  2082. bool isunannotTool = true;
  2083. //内容选择 退出
  2084. if (PDFViewer.MouseMode != MouseModes.PanTool)
  2085. {
  2086. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2087. if (annotToolContent != null && toolContentViewModel != null)
  2088. {
  2089. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2090. {
  2091. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  2092. {
  2093. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  2094. annotToolContent.BtnSelecttool.IsChecked = false;
  2095. PDFViewer.SetMouseMode(MouseModes.PanTool);
  2096. isunannotTool = false;
  2097. }
  2098. }
  2099. else
  2100. {
  2101. //如果注释是在拖拉创建中 或者 选中 了图片 不退出阅读模式
  2102. if (toolContentViewModel != null)
  2103. {
  2104. if (toolContentViewModel.IsCreateAnnot)
  2105. {
  2106. isunannotTool = false;
  2107. toolContentViewModel.IsCreateAnnot = false;
  2108. }
  2109. if (toolContentViewModel.IsSelectImage)
  2110. {
  2111. isunannotTool = false;
  2112. toolContentViewModel.IsSelectImage = false;
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. if (mainViewModel.IsBookMode == true && isunannotTool)
  2119. {
  2120. Off_ReadModel();
  2121. }
  2122. }
  2123. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  2124. {
  2125. //内容选择 复制 快捷键
  2126. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2127. if (annotToolContent != null && toolContentViewModel != null)
  2128. {
  2129. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2130. {
  2131. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  2132. }
  2133. }
  2134. }
  2135. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  2136. {
  2137. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2138. if (annotToolContent != null && toolContentViewModel != null)
  2139. {
  2140. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2141. {
  2142. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  2143. }
  2144. }
  2145. }
  2146. }
  2147. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  2148. {
  2149. AnnotToolContent toolContent = null;
  2150. toolContentViewModel = null;
  2151. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  2152. {
  2153. var views = region.Regions[ToolsBarContentRegionName].Views;
  2154. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  2155. if (model is AnnotToolContent annotToolContent)
  2156. {
  2157. toolContent = annotToolContent;
  2158. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  2159. }
  2160. }
  2161. return toolContent;
  2162. }
  2163. /// <summary>
  2164. /// 视图面板 切换分屏模式
  2165. /// </summary>
  2166. /// <param name="mode"></param>
  2167. public void EnterSplitMode(SplitMode mode)
  2168. {
  2169. ///通知UI层更改布局
  2170. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  2171. }
  2172. private void Undo()
  2173. {
  2174. PDFViewer.UndoManager.Undo();
  2175. PDFViewer.DisableClearSelectAnnot(false);
  2176. PDFViewer.ClearSelectAnnots();
  2177. }
  2178. private void Redo()
  2179. {
  2180. PDFViewer.UndoManager.Redo();
  2181. }
  2182. private void LoadControl()
  2183. {
  2184. NavigationParameters parameters = new NavigationParameters();
  2185. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2186. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2187. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  2188. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2189. region.RequestNavigate(ReadModeRegionName, "PageContent", parameters);
  2190. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  2191. //TODO 根据上一次关闭记录的菜单,选中顶部TabItem
  2192. EnterSelectedBar("TabItemAnnotation");
  2193. //}
  2194. //));
  2195. }
  2196. /// <summary>
  2197. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  2198. /// </summary>
  2199. /// <param name="Content"></param>
  2200. /// <param name="annotPropertyPanel"></param>
  2201. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  2202. {
  2203. if (Content == "PropertyPanelContent")
  2204. {
  2205. IsPropertyOpen = false;
  2206. }
  2207. else
  2208. {
  2209. IsPropertyOpen = true;
  2210. }
  2211. NavigationParameters parameters = new NavigationParameters();
  2212. //传其他参数:文档类,空注释面板;
  2213. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2214. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  2215. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2216. region.RequestNavigate(PropertyRegionName, Content, parameters);
  2217. }
  2218. /// <summary>
  2219. /// 将PDFViwer添加到Region
  2220. /// </summary>
  2221. private bool loadFile()
  2222. {
  2223. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  2224. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  2225. CanSave = PDFViewer.UndoManager.CanSave;
  2226. CanUndo = PDFViewer.UndoManager.CanUndo;
  2227. CanRedo = PDFViewer.UndoManager.CanRedo;
  2228. if (!CheckPassword())
  2229. {
  2230. return false;
  2231. }
  2232. PDFViewer.Load();
  2233. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2234. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  2235. //设置移动注释参考线
  2236. ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"), 1);
  2237. ComPDFKitViewer.CommonDrawData.DrawAnnotGuidesLine = true;
  2238. //还原上一次关闭前的视图设置
  2239. GetOpenFileInfo();
  2240. if (!string.IsNullOrEmpty(PassWord))
  2241. {
  2242. //加密文档解密后刷新底部工具栏页码总数
  2243. NavigationParameters parameters = new NavigationParameters();
  2244. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2245. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2246. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2247. //解密后,刷新侧边栏逻辑
  2248. botaViewModel.OpenBOTA();
  2249. }
  2250. PDFViewer.SnapsToDevicePixels = true;
  2251. PDFViewer.UseLayoutRounding = true;
  2252. RenderOptions.SetBitmapScalingMode(PDFViewer, BitmapScalingMode.Fant);
  2253. region.AddToRegion(ViwerRegionName, PDFViewer);
  2254. if (App.mainWindowViewModel != null)
  2255. {
  2256. //更新CurrentPDFViewer对象
  2257. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2258. }
  2259. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  2260. {
  2261. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  2262. }
  2263. return true;
  2264. }
  2265. /// <summary>
  2266. /// 处理密码相关的内容
  2267. /// </summary>
  2268. private bool CheckPassword()
  2269. {
  2270. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  2271. {
  2272. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  2273. {
  2274. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  2275. }
  2276. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
  2277. {
  2278. IsFileLocked = true;
  2279. NavigationParameters param = new NavigationParameters();
  2280. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2281. param.Add(ParameterNames.ViewContentViewModel, this);
  2282. ShowLeftTip(true);
  2283. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2284. }
  2285. }
  2286. else
  2287. {
  2288. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  2289. if (result.IsDiscryptied)
  2290. {
  2291. if (result.Password != null)
  2292. {
  2293. string filePath = PDFViewer.Document.FilePath;
  2294. PDFViewer.Document.UnlockWithPassword(result.Password);
  2295. PDFViewer.Tag = result.Password;
  2296. //记录密码到内存
  2297. this.PassWord = result.Password;
  2298. }
  2299. }
  2300. if (result.IsDiscryptied == false)
  2301. {
  2302. //未成功解密文档时,释放Document对象,返回
  2303. PDFViewer.Document.Release();
  2304. //取消解密时关闭当前页签
  2305. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  2306. return false;
  2307. }
  2308. }
  2309. return true;
  2310. }
  2311. /// <summary>
  2312. /// 还原上一次浏览的视图相关设置
  2313. /// </summary>
  2314. private void GetOpenFileInfo()
  2315. {
  2316. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2317. //偏好设置里设置了记录上次视图设置时
  2318. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  2319. {
  2320. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  2321. {
  2322. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  2323. }
  2324. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  2325. {
  2326. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  2327. }
  2328. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  2329. {
  2330. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  2331. }
  2332. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  2333. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  2334. if (OpenFileInfo.LastPageSpace)
  2335. {
  2336. PDFViewer.SetPageSpacing(8);
  2337. }
  2338. else
  2339. {
  2340. PDFViewer.SetPageSpacing(0);
  2341. }
  2342. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  2343. {
  2344. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  2345. }
  2346. else
  2347. {
  2348. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  2349. }
  2350. if (OpenFileInfo.LastPageIndex == 0 && PDFViewer.GetVerticalOffset() != 0)
  2351. {
  2352. PDFViewer.ScrollToVerticalOffset(0);
  2353. }
  2354. }
  2355. else
  2356. {
  2357. //新文档应用默认设置
  2358. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  2359. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  2360. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2361. }
  2362. }
  2363. /// <summary>
  2364. /// 已有路径文档的保存逻辑
  2365. /// </summary>
  2366. public bool saveFile(bool autosave = false)
  2367. {
  2368. try
  2369. {
  2370. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2371. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)&&App.IsUsedVIP==true)
  2372. {
  2373. DialogParameters value = new DialogParameters();
  2374. value.Add(ParameterNames.ViewContentViewModel, this);
  2375. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2376. {
  2377. });
  2378. return false;
  2379. }
  2380. if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
  2381. return saveAsFile();
  2382. //文档已被修复时 提示另存为
  2383. if (PDFViewer.Document.HasRepaired)
  2384. {
  2385. AlertsMessage alertsMessage = new AlertsMessage();
  2386. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileRepairedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2387. if (alertsMessage.result == ContentResult.Ok)
  2388. return saveAsFile();
  2389. else
  2390. return false;
  2391. }
  2392. //文件路径无法存在时
  2393. if (!File.Exists(PDFViewer.Document.FilePath))
  2394. {
  2395. AlertsMessage alertsMessage = new AlertsMessage();
  2396. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileNotExistWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2397. if (alertsMessage.result == ContentResult.Ok)
  2398. return saveAsFile();
  2399. else
  2400. return false;
  2401. }
  2402. //只读文件无法写入时,提示另存为
  2403. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  2404. if (fileInfo.IsReadOnly)
  2405. {
  2406. AlertsMessage alertsMessage = new AlertsMessage();
  2407. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileReadonlyWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2408. if (alertsMessage.result == ContentResult.Ok)
  2409. return saveAsFile();
  2410. else
  2411. return false;
  2412. }
  2413. //记录保存前的当前页
  2414. int pageindex = PDFViewer.CurrentIndex;
  2415. //Security Fixed:
  2416. //修改密码后原文档保存的步骤:
  2417. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  2418. //
  2419. if (SecurityInfo.IsPasswordChanged)
  2420. {
  2421. string currentFilePath = PDFViewer.Document.FilePath;
  2422. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  2423. string openPassword = string.Empty;
  2424. string permissionsPassword = string.Empty;
  2425. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2426. if (SecurityInfo.NeedOpenPassword)
  2427. {
  2428. openPassword = SecurityInfo.OpenPassword;
  2429. }
  2430. if (SecurityInfo.NeedPermissionsPassword)
  2431. {
  2432. permissionsPassword = SecurityInfo.PermissionsPassword;
  2433. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2434. }
  2435. try
  2436. {
  2437. string currentPath = PDFViewer.Document.FilePath;
  2438. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2439. if (PDFViewer.Document.Descrypt(tempPath))
  2440. {
  2441. PDFViewer.CloseDocument();
  2442. PDFViewer.InitDocument(tempPath);
  2443. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2444. if (PDFViewer.Document.WriteToFilePath(currentPath))
  2445. {
  2446. PDFViewer.CloseDocument();
  2447. PDFViewer.InitDocument(currentPath);
  2448. if (!string.IsNullOrEmpty(openPassword))
  2449. {
  2450. PDFViewer.Document.UnlockWithPassword(openPassword);
  2451. }
  2452. if (!string.IsNullOrEmpty(permissionsPassword) && openPassword != permissionsPassword)
  2453. {
  2454. //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  2455. IsFileLocked = true;
  2456. NavigationParameters param = new NavigationParameters();
  2457. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2458. param.Add(ParameterNames.ViewContentViewModel, this);
  2459. ShowLeftTip(true);
  2460. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2461. }
  2462. try
  2463. {
  2464. PDFViewer.Load();
  2465. //跳转到保存前的页面
  2466. PDFViewer.GoToPage(pageindex);
  2467. }
  2468. catch
  2469. {
  2470. }
  2471. if (!autosave)
  2472. {
  2473. PDFViewer.UndoManager.CanSave = false;
  2474. }
  2475. SecurityInfo.IsPasswordChanged = false;
  2476. }
  2477. else
  2478. {
  2479. return false;
  2480. }
  2481. System.IO.File.Delete(tempPath);
  2482. }
  2483. else
  2484. {
  2485. return false;
  2486. }
  2487. return true;
  2488. }
  2489. catch
  2490. {
  2491. return false;
  2492. }
  2493. }
  2494. else if (SecurityInfo.IsPasswordRemoved)
  2495. {
  2496. try
  2497. {
  2498. string currentPath = PDFViewer.Document.FilePath;
  2499. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2500. PDFViewer.Document.Descrypt(tempPath);
  2501. PDFViewer.CloseDocument();
  2502. PDFViewer.InitDocument(tempPath);
  2503. PDFViewer.Document.WriteToFilePath(currentPath);
  2504. PDFViewer.CloseDocument();
  2505. PDFViewer.InitDocument(currentPath);
  2506. PDFViewer.Load();
  2507. //跳转到保存前的页面
  2508. PDFViewer.GoToPage(pageindex);
  2509. System.IO.File.Delete(tempPath);
  2510. }
  2511. catch
  2512. {
  2513. return false;
  2514. }
  2515. }
  2516. //自动裁剪保存
  2517. List<int> cropPageList = new List<int>();
  2518. for (int i = 0; i < PDFViewer.Document.PageCount; i++)
  2519. {
  2520. cropPageList.Clear();
  2521. cropPageList.Add(i);
  2522. CPDFPage cPDFPage = PDFViewer.Document.PageAtIndex(i);
  2523. if (PDFViewer.IsCropMode(i) == true)
  2524. {
  2525. Rect rect = cPDFPage.GetCropBounds();
  2526. PDFViewer?.CropPage(CPDFDisplayBox.CropBox, rect, cropPageList);
  2527. }
  2528. }
  2529. bool result = PDFViewer.Document.WriteToLoadedPath();
  2530. if (result)
  2531. {
  2532. if (!autosave)
  2533. {
  2534. PDFViewer.UndoManager.CanSave = false;
  2535. }
  2536. App.Current.Dispatcher.Invoke(() =>
  2537. {
  2538. //保存时更新缩略图
  2539. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2540. try
  2541. {
  2542. if (info != null && !string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  2543. {
  2544. var size = PDFViewer.Document.GetPageSize(0);
  2545. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  2546. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  2547. if (File.Exists(folderPath))
  2548. File.Delete(folderPath);
  2549. DirectoryInfo folder = new DirectoryInfo(folderPath);
  2550. if (!folder.Exists)
  2551. folder.Create();
  2552. string imagePath = info.ThumbImgPath;
  2553. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  2554. {
  2555. string imageName = Guid.NewGuid().ToString();
  2556. imagePath = System.IO.Path.Combine(folderPath, imageName);
  2557. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  2558. {
  2559. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2560. }
  2561. }
  2562. else
  2563. {
  2564. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  2565. {
  2566. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2567. }
  2568. }
  2569. info.ThumbImgPath = imagePath;
  2570. SettingHelper.SetFileInfo(info);
  2571. }
  2572. }
  2573. catch
  2574. {
  2575. info.ThumbImgPath = null;
  2576. SettingHelper.SetFileInfo(info);
  2577. }
  2578. });
  2579. //编辑不要刷新,否则保存时会崩溃
  2580. if (PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.None)
  2581. {
  2582. PDFViewer.ReloadDocument();
  2583. }
  2584. //PDFViewer.ReloadDocument();
  2585. }
  2586. else
  2587. {
  2588. //弹窗前 激活主窗体
  2589. //App.Current.MainWindow.Activate();
  2590. AlertsMessage alertsMessage = new AlertsMessage();
  2591. //文件被占用 保存失败时
  2592. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2593. //显示当前窗体,防止窗口置底
  2594. App.Current.MainWindow.Activate();
  2595. if (alertsMessage.result == ContentResult.Ok)
  2596. return saveAsFile();
  2597. else
  2598. return false;
  2599. }
  2600. return result;
  2601. }
  2602. catch { return false; }
  2603. finally
  2604. {
  2605. if (!IsFileLocked)
  2606. {
  2607. ShowLeftTip(false);
  2608. }
  2609. }
  2610. }
  2611. /// <summary>
  2612. /// 另存为或新文档保存逻辑
  2613. /// </summary>
  2614. public bool saveAsFile(Action RedactionAction = null, String IsFormSave=null)
  2615. {
  2616. if(IsFormSave=="FormSave")
  2617. {
  2618. var dlg = new Microsoft.Win32.SaveFileDialog();
  2619. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2620. dlg.FileName = PDFViewer.Document.FileName;
  2621. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2622. {
  2623. bool result = false;
  2624. if (RedactionAction != null)
  2625. {
  2626. //保存前进行标记密文处理应用或擦除
  2627. RedactionAction.Invoke();
  2628. }
  2629. if (App.OpenedFileList.Contains(dlg.FileName))
  2630. {
  2631. //提示文件已经被打开
  2632. }
  2633. else
  2634. {
  2635. string oldpath = PDFViewer.Document.FilePath;
  2636. string openPassword = string.Empty;
  2637. string permissionsPassword = string.Empty;
  2638. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2639. if (SecurityInfo.NeedOpenPassword)
  2640. {
  2641. openPassword = SecurityInfo.OpenPassword;
  2642. passwordInfo.OpenPassword = openPassword;
  2643. }
  2644. if (SecurityInfo.NeedPermissionsPassword)
  2645. {
  2646. permissionsPassword = SecurityInfo.PermissionsPassword;
  2647. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2648. passwordInfo.PermissionsPassword = permissionsPassword;
  2649. }
  2650. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2651. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2652. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2653. if (resourceInfo != null)
  2654. {
  2655. using (Stream stream = resourceInfo.Stream)
  2656. {
  2657. BitmapFrame frame = null;
  2658. int width = 0;
  2659. int height = 0;
  2660. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2661. if (decoder != null && decoder.Frames.Count > 0)
  2662. {
  2663. frame = decoder.Frames[0];
  2664. }
  2665. if (frame != null)
  2666. {
  2667. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2668. width = frame.PixelWidth;
  2669. height = frame.PixelHeight;
  2670. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2671. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2672. watermark.SetImage(ImageArray, width, height);
  2673. watermark.SetScale(1);
  2674. watermark.SetRotation(0);
  2675. watermark.SetOpacity(255);
  2676. watermark.SetFront(true);
  2677. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2678. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2679. watermark.SetFullScreen(false);
  2680. watermark.SetVertOffset(0);
  2681. watermark.SetHorizOffset(0);
  2682. watermark.SetHorizontalSpacing(0);
  2683. watermark.SetVerticalSpacing(0);
  2684. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2685. watermark.SetPages(setpages);
  2686. watermark.UpdateWatermark();
  2687. PDFViewer.Document.ReleasePages();
  2688. PDFViewer.ReloadDocument();
  2689. }
  2690. }
  2691. }
  2692. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2693. if (result)
  2694. {
  2695. mainViewModel.NewFile = false;
  2696. App.OpenedFileList.Remove(oldpath);
  2697. DoAfterSaveAs(dlg.FileName);
  2698. }
  2699. else
  2700. {
  2701. //提示文件被其他软件占用 无法保存
  2702. //
  2703. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2704. }
  2705. }
  2706. return result;
  2707. }
  2708. else
  2709. return false;
  2710. }
  2711. else
  2712. {
  2713. bool flg = false;
  2714. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2715. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && App.IsUsedVIP == true)
  2716. {
  2717. DialogParameters value = new DialogParameters();
  2718. value.Add(ParameterNames.ViewContentViewModel, this);
  2719. value.Add(ParameterNames.Open, "saveAs");
  2720. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2721. {
  2722. if (dialogResult.Result == ButtonResult.Cancel)
  2723. {
  2724. flg = true;
  2725. }
  2726. });
  2727. if (flg == false)
  2728. {
  2729. return false;
  2730. }
  2731. }
  2732. var dlg = new Microsoft.Win32.SaveFileDialog();
  2733. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2734. dlg.FileName = PDFViewer.Document.FileName;
  2735. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2736. {
  2737. bool result = false;
  2738. if (RedactionAction != null)
  2739. {
  2740. //保存前进行标记密文处理应用或擦除
  2741. RedactionAction.Invoke();
  2742. }
  2743. if (App.OpenedFileList.Contains(dlg.FileName))
  2744. {
  2745. //提示文件已经被打开
  2746. }
  2747. else
  2748. {
  2749. string oldpath = PDFViewer.Document.FilePath;
  2750. string openPassword = string.Empty;
  2751. string permissionsPassword = string.Empty;
  2752. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2753. if (SecurityInfo.NeedOpenPassword)
  2754. {
  2755. openPassword = SecurityInfo.OpenPassword;
  2756. passwordInfo.OpenPassword = openPassword;
  2757. }
  2758. if (SecurityInfo.NeedPermissionsPassword)
  2759. {
  2760. permissionsPassword = SecurityInfo.PermissionsPassword;
  2761. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2762. passwordInfo.PermissionsPassword = permissionsPassword;
  2763. }
  2764. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2765. if(flg==true)
  2766. {
  2767. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2768. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2769. if (resourceInfo != null)
  2770. {
  2771. using (Stream stream = resourceInfo.Stream)
  2772. {
  2773. BitmapFrame frame = null;
  2774. int width = 0;
  2775. int height = 0;
  2776. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2777. if (decoder != null && decoder.Frames.Count > 0)
  2778. {
  2779. frame = decoder.Frames[0];
  2780. }
  2781. if (frame != null)
  2782. {
  2783. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2784. width = frame.PixelWidth;
  2785. height = frame.PixelHeight;
  2786. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2787. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2788. watermark.SetImage(ImageArray, width, height);
  2789. watermark.SetScale(1);
  2790. watermark.SetRotation(0);
  2791. watermark.SetOpacity(255);
  2792. watermark.SetFront(true);
  2793. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2794. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2795. watermark.SetFullScreen(false);
  2796. watermark.SetVertOffset(0);
  2797. watermark.SetHorizOffset(0);
  2798. watermark.SetHorizontalSpacing(0);
  2799. watermark.SetVerticalSpacing(0);
  2800. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2801. watermark.SetPages(setpages);
  2802. watermark.UpdateWatermark();
  2803. PDFViewer.Document.ReleasePages();
  2804. PDFViewer.ReloadDocument();
  2805. }
  2806. }
  2807. }
  2808. }
  2809. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2810. if (result)
  2811. {
  2812. mainViewModel.NewFile = false;
  2813. App.OpenedFileList.Remove(oldpath);
  2814. DoAfterSaveAs(dlg.FileName);
  2815. }
  2816. else
  2817. {
  2818. //提示文件被其他软件占用 无法保存
  2819. //
  2820. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2821. }
  2822. }
  2823. return result;
  2824. }
  2825. else
  2826. return false;
  2827. }
  2828. }
  2829. /// <summary>
  2830. /// 转档、压缩、合并前自动保存
  2831. /// </summary>
  2832. public async Task<bool> SaveBeforeOption()
  2833. {
  2834. bool result = true;
  2835. //因配合权益弹窗弹出,暂时移除可保存条件判断
  2836. //if (PDFViewer.UndoManager.CanSave)
  2837. {
  2838. string title = "Saving File";
  2839. App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
  2840. //让保存的效果更明显
  2841. await Task.Delay(200);
  2842. //合并前自动保存一次
  2843. result = saveFile(true);
  2844. App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
  2845. }
  2846. //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
  2847. return result;
  2848. }
  2849. /// <summary>
  2850. /// 另存为Flatten
  2851. /// </summary>
  2852. private void saveAsFlatten()
  2853. {
  2854. var dlg = new SaveFileDialog();
  2855. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2856. dlg.FileName = PDFViewer.Document.FileName + "_Flattened.pdf";
  2857. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2858. {
  2859. saveFile();
  2860. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FilePath);
  2861. if (kmdoc == null)
  2862. {
  2863. return;
  2864. }
  2865. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  2866. if (result)
  2867. {
  2868. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  2869. }
  2870. kmdoc.Release();
  2871. }
  2872. }
  2873. /// <summary>
  2874. /// 另存为后进行的操作
  2875. /// 重新打开新文档
  2876. /// </summary>
  2877. /// <param name="targetPath"></param>
  2878. public void DoAfterSaveAs(string targetPath)
  2879. {
  2880. PDFViewer.UndoManager.CanSave = false;
  2881. //从新路径重新加载
  2882. //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
  2883. PDFViewer.CloseDocument();
  2884. PDFViewer.InitDocument(targetPath);
  2885. //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
  2886. CheckPassword();
  2887. PDFViewer.Load();
  2888. //刷新最近文件列表
  2889. OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);
  2890. if (isnew == null)
  2891. {
  2892. if (App.OpenedFileList.Contains(targetPath) == false)
  2893. {
  2894. App.OpenedFileList.Add(targetPath);
  2895. }
  2896. }
  2897. //打开文件后,不管是新文件还是旧文件都需要更新排序
  2898. SettingHelper.SortRecentOpenFiles(targetPath);
  2899. //更新页签文件名
  2900. mainViewModel.FilePath = PDFViewer.Document.FilePath;
  2901. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2902. //刷新Bota 和底部工具栏的PDFviwer对象
  2903. LoadControl();
  2904. }
  2905. /// <summary>
  2906. /// 显示前添加内容到Region
  2907. /// </summary>
  2908. /// <param name="isPageEdit"></param>
  2909. private void ShowContent(string currentBar, bool isToolMode = false)
  2910. {
  2911. GridVisibility = Visibility.Visible;
  2912. //显示页面编辑或其他工具
  2913. if (currentBar == "TabItemPageEdit" || isToolMode)
  2914. {
  2915. if (currentBar == "TabItemPageEdit")//进入页面编辑
  2916. {
  2917. if (GridToolRow != 1)
  2918. {
  2919. GridToolRow = 1;
  2920. }
  2921. if (GridToolRowSpan != 3)
  2922. {
  2923. GridToolRowSpan = 3;
  2924. }
  2925. }
  2926. else//进入水印等其他工具模式
  2927. {
  2928. GridVisibility = Visibility.Collapsed;
  2929. if (GridToolRow != 0)
  2930. {
  2931. GridToolRow = 0;
  2932. }
  2933. if (GridToolRowSpan != 4)
  2934. {
  2935. GridToolRowSpan = 4;
  2936. }
  2937. }
  2938. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  2939. UpdateShowContent(currentBar);
  2940. }
  2941. else
  2942. {
  2943. if (GridToolRow != 1)
  2944. {
  2945. GridToolRow = 1;
  2946. }
  2947. UpdateShowContent(currentBar);
  2948. }
  2949. }
  2950. /// <summary>
  2951. /// 从二级工具栏进入需要修改界面布局的场景
  2952. /// </summary>
  2953. /// <param name="EditToolName"></param>
  2954. private void EnterEditTools(StringWithUnicode EditToolName)
  2955. {
  2956. EnterSelectedEditTool(EditToolName);
  2957. }
  2958. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  2959. {
  2960. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  2961. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  2962. {
  2963. PDFViewer.Document.ReleasePages();
  2964. PDFViewer.ReloadDocument();
  2965. }
  2966. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  2967. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  2968. {
  2969. region.AddToRegion(ViwerRegionName, PDFViewer);
  2970. }
  2971. CurrentBar = "TabItemTool";
  2972. EnterSelectedBar(CurrentBar);
  2973. }
  2974. /// <summary>
  2975. /// 二级菜单指定目标处理
  2976. /// </summary>
  2977. /// <param name="e"></param>
  2978. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  2979. {
  2980. CurrentBar = EditToolName.EditToolsContentName;
  2981. EnterToolMode(CurrentBar);
  2982. }
  2983. /// <summary>
  2984. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  2985. /// </summary>
  2986. /// <param name="targetToolMode">要导航过去的控件名称</param>
  2987. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  2988. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  2989. {
  2990. IsLoading = Visibility.Visible;
  2991. await Task.Delay(3);
  2992. NavigationParameters param = new NavigationParameters();
  2993. if (valuePairs == null)
  2994. {
  2995. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2996. param.Add(ParameterNames.ViewContentViewModel, this);
  2997. }
  2998. else//有传入其他内容的参数时
  2999. {
  3000. param = valuePairs;
  3001. }
  3002. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  3003. ShowContent(CurrentBar, true);
  3004. IsLoading = Visibility.Collapsed;
  3005. }
  3006. private void EnterSelectedBar(string currentBar)
  3007. {
  3008. if (currentBar == "TabItemEdit")
  3009. {
  3010. if (!ServiceHelper.IAPBeforeFunction())
  3011. {
  3012. TabSelectedIndex = 0;
  3013. isInPageEdit = false;
  3014. return;
  3015. }
  3016. }
  3017. NavigationParameters param = new NavigationParameters();
  3018. param.Add(ParameterNames.PDFViewer, PDFViewer);
  3019. param.Add(ParameterNames.ViewContentViewModel, this);
  3020. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  3021. if (currentBar == "TabItemScan")
  3022. {
  3023. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  3024. }
  3025. ShowContent(currentBar);
  3026. }
  3027. /// <summary>
  3028. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  3029. /// </summary>
  3030. public void ExitToolMode()
  3031. {
  3032. ToolContentVisible = Visibility.Collapsed;
  3033. if (isInPageEdit)
  3034. {
  3035. TabSelectedIndex = 0;
  3036. isInPageEdit = false;
  3037. }
  3038. }
  3039. #endregion 方法
  3040. #region Navigate
  3041. public void OnNavigatedTo(NavigationContext navigationContext)
  3042. {
  3043. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  3044. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  3045. if (mainVM != null)
  3046. {
  3047. mainViewModel = mainVM;
  3048. mainViewModel.viewContentViewModel = this;
  3049. }
  3050. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  3051. if (pdfview != null)
  3052. {
  3053. PDFViewer = pdfview;
  3054. if (loadFile())
  3055. {
  3056. CheckHaveAllPermission();
  3057. }
  3058. }
  3059. //快捷键
  3060. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3061. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  3062. //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
  3063. //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
  3064. Settings.Default.UserDate.CheckRegisterStatus();
  3065. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  3066. if (Settings.Default.UserDate.TodayRegister == false && App.IsLogin == false)
  3067. {
  3068. Settings.Default.UserDate.TodayRegister = true;
  3069. DateTime currentTime = DateTime.Now;
  3070. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  3071. Settings.Default.Save();
  3072. App.mainWindowViewModel.OpenRegister();
  3073. }
  3074. //需要在pdfview赋值后绑定
  3075. GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
  3076. }
  3077. public bool IsNavigationTarget(NavigationContext navigationContext)
  3078. {
  3079. if (navigationContext != null)
  3080. {
  3081. //另存为打开导航进来时 不能新建一个实例
  3082. return true;
  3083. }
  3084. else
  3085. {
  3086. //一次性打开多个文件时,需要新建实例
  3087. return false;
  3088. }
  3089. }
  3090. public void OnNavigatedFrom(NavigationContext navigationContext)
  3091. {
  3092. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3093. }
  3094. internal void FindPageEditContent(out Views.PageEdit.PageEditContent pageEditContent)
  3095. {
  3096. pageEditContent = null;
  3097. if (region.Regions.ContainsRegionWithName(ToolContentRegionName))
  3098. {
  3099. var views = region.Regions[ToolContentRegionName].Views;
  3100. var model = views.FirstOrDefault(q => q is Views.PageEdit.PageEditContent);
  3101. if (model is Views.PageEdit.PageEditContent page)
  3102. {
  3103. pageEditContent = page;
  3104. }
  3105. }
  3106. }
  3107. #endregion Navigate
  3108. }
  3109. }