ViewContentViewModel.cs 138 KB

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